1667f8ec4e5baeedc6df32a59443dfba621d883b
[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 PROJECT_NAMES = [
12     "controller",
13     "dlux",
14     "dluxapps",
15     "infrautils",
16     "mdsal",
17     "netconf",
18     "neutron",
19     "odlparent",
20     "openflowplugin",
21     "ovsdb",
22     "sfc",
23     "yangtools",
24 ]
25 DISTRO_PATH = "/tmp/distribution-karaf"
26 BRANCH = "master"
27 LIMIT = 10
28 QLIMIT = 50
29
30
31 class TestChanges(unittest.TestCase):
32     def setUp(self):
33         print("Starting test: %s" % self.id())
34
35     @staticmethod
36     def run_cmd(
37         branch, distro_patch, limit, qlimit, project_names, remote_url, loglevel=0
38     ):
39         changes = Changes(
40             branch, distro_patch, limit, qlimit, project_names, remote_url, loglevel
41         )
42         projects = changes.run_cmd()
43         changes.pretty_print_projects(projects)
44
45     def test_run_cmd_multiple(self):
46         project_names = PROJECT_NAMES
47         branch = BRANCH
48         self.run_cmd(
49             branch, DISTRO_PATH, LIMIT, QLIMIT, project_names, REMOTE_URL, logging.INFO
50         )
51
52     def test_pretty_print(self):
53         project_names = PROJECT_NAMES
54         changes = Changes(BRANCH, DISTRO_PATH, LIMIT, QLIMIT, project_names, REMOTE_URL)
55         projects = {}
56         for project in project_names:
57             projects[project] = {"commit": 1, "includes": [{"a": 1}]}
58         changes.pretty_print_projects(projects)
59         for project in project_names:
60             projects[project] = {
61                 "commit": 1,
62                 "includes": [
63                     {
64                         "grantedOn": 1,
65                         "lastUpdated": 11,
66                         "number": "12345",
67                         "subject": "This is a test for " + project,
68                     },
69                     {
70                         "grantedOn": 2,
71                         "lastUpdated": 22,
72                         "number": "56789",
73                         "subject": "This is a test for " + project,
74                     },
75                 ],
76             }
77         changes.pretty_print_projects(projects)
78
79     def test_epoch_to_utc(self):
80         project_names = PROJECT_NAMES
81         changes = Changes(BRANCH, DISTRO_PATH, LIMIT, QLIMIT, project_names, REMOTE_URL)
82         print("utc: %s" % changes.epoch_to_utc(1483974872))
83
84     def test_distcompare(self):
85         distcompare.main()
86
87
88 if __name__ == "__main__":
89     unittest.main()