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