summaryrefslogtreecommitdiffstats
path: root/test/rules/test_meta_video_links.py
blob: 3772ea270f52c8bfb9c5c2fe688ac097af02520a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
"""Tests for meta-video-links rule."""
from ansiblelint.rules import RulesCollection
from ansiblelint.rules.meta_video_links import MetaVideoLinksRule
from ansiblelint.testing import RunFromText

META_VIDEO_LINKS = """
galaxy_info:
  video_links:
  - url: https://www.youtube.com/watch?v=aWmRepTSFKs&feature=youtu.be
    title: Proper format
  - url: https://drive.google.com/file/d/1spYR51l8SqQqvAhSdZE7/view
    title: Check for VIDEO_REGEXP validity and break
  - https://www.youtube.com/watch?v=aWmRepTSFKs&feature=youtu.be
  - my_bad_key: https://www.youtube.com/watch?v=aWmRepTSFKs&feature=youtu.be
    title: This has a bad key
  - url: www.acme.com/vid
    title: Bad format of url
"""

META_NO_GALAXY_INFO = """
galaxy_information:
  video_links:
  - url: https://www.youtube.com/watch?v=aWmRepTSFKs&feature=youtu.be
"""


def test_video_links() -> None:
    """Test meta_video_links."""
    collection = RulesCollection()
    collection.register(MetaVideoLinksRule())
    runner = RunFromText(collection)

    results = runner.run_role_meta_main(META_VIDEO_LINKS)
    assert "Expected item in 'video_links' to be a dictionary" in str(results)
    assert "'video_links' to contain only keys 'url' and 'title'" in str(results)
    assert "URL format 'www.acme.com/vid' is not recognized" in str(results)


def test_meta_video_links_no_galaxy_info() -> None:
    """Test meta_video_links."""
    collection = RulesCollection()
    collection.register(MetaVideoLinksRule())
    runner = RunFromText(collection)

    results = runner.run_role_meta_main(META_NO_GALAXY_INFO)
    assert len(results) == 0