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