Auto-generated patch by python-black
[integration/test.git] / tools / distchanges / tests / test_changes.py
1 #!/usr/bin/env python
2
3 # TODO: Add more tests here using all the tests/resources/* and automate those tests in a verify job
4
5 import logging
6 import unittest
7 import distcompare
8 from changes import Changes
9
10 REMOTE_URL = "ssh://git.opendaylight.org:29418"
11 NETVIRT_PROJECTS = [
12     "controller",
13     "dlux",
14     "dluxapps",
15     "genius",
16     "infrautils",
17     "mdsal",
18     "netconf",
19     "netvirt",
20     "neutron",
21     "odlparent",
22     "openflowplugin",
23     "ovsdb",
24     "sfc",
25     "yangtools",
26 ]
27 PROJECT_NAMES = NETVIRT_PROJECTS
28 DISTRO_PATH = "/tmp/distribution-karaf"
29 BRANCH = "master"
30 LIMIT = 10
31 QLIMIT = 50
32
33
34 class TestChanges(unittest.TestCase):
35     def setUp(self):
36         print("Starting test: %s" % self.id())
37
38     @staticmethod
39     def run_cmd(
40         branch, distro_patch, limit, qlimit, project_names, remote_url, loglevel=0
41     ):
42         changes = Changes(
43             branch, distro_patch, limit, qlimit, project_names, remote_url, loglevel
44         )
45         projects = changes.run_cmd()
46         changes.pretty_print_projects(projects)
47
48     def test_run_cmd_single(self):
49         project_names = ["netvirt"]
50         branch = BRANCH
51         self.run_cmd(
52             branch, DISTRO_PATH, LIMIT, QLIMIT, project_names, REMOTE_URL, logging.INFO
53         )
54
55     def test_run_cmd_multiple(self):
56         project_names = PROJECT_NAMES
57         branch = BRANCH
58         self.run_cmd(
59             branch, DISTRO_PATH, LIMIT, QLIMIT, project_names, REMOTE_URL, logging.INFO
60         )
61
62     def test_pretty_print(self):
63         project_names = PROJECT_NAMES
64         changes = Changes(BRANCH, DISTRO_PATH, LIMIT, QLIMIT, project_names, REMOTE_URL)
65         projects = {}
66         for project in project_names:
67             projects[project] = {"commit": 1, "includes": [{"a": 1}]}
68         changes.pretty_print_projects(projects)
69         for project in project_names:
70             projects[project] = {
71                 "commit": 1,
72                 "includes": [
73                     {
74                         "grantedOn": 1,
75                         "lastUpdated": 11,
76                         "number": "12345",
77                         "subject": "This is a test for " + project,
78                     },
79                     {
80                         "grantedOn": 2,
81                         "lastUpdated": 22,
82                         "number": "56789",
83                         "subject": "This is a test for " + project,
84                     },
85                 ],
86             }
87         changes.pretty_print_projects(projects)
88
89     def test_epoch_to_utc(self):
90         project_names = PROJECT_NAMES
91         changes = Changes(BRANCH, DISTRO_PATH, LIMIT, QLIMIT, project_names, REMOTE_URL)
92         print("utc: %s" % changes.epoch_to_utc(1483974872))
93
94     def test_distcompare(self):
95         distcompare.main()
96
97
98 if __name__ == "__main__":
99     unittest.main()