1
|
|
|
# Copyright (c) 2019 Alexander Todorov <[email protected]> |
2
|
|
|
|
3
|
|
|
# Licensed under the GPL 2.0: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
4
|
|
|
|
5
|
|
|
import pkg_resources |
6
|
|
|
|
7
|
|
|
from django.conf import settings |
8
|
|
|
from django.test import TestCase |
9
|
|
|
from django.urls import reverse |
10
|
|
|
from django.urls.resolvers import URLResolver |
11
|
|
|
from django.utils.translation import ugettext_lazy as _ |
12
|
|
|
|
13
|
|
|
from tcms.urls import urlpatterns |
14
|
|
|
from tcms.telemetry.tests.plugin import menu as plugin_menu |
15
|
|
|
|
16
|
|
|
|
17
|
|
|
class PluginDiscoveryTestCase(TestCase): |
18
|
|
|
def test_installed_apps_is_updated(self): |
19
|
|
|
""" |
20
|
|
|
Given there are some plugins installed |
21
|
|
|
Then validate the plugin module is added to INSTALLED_APPS |
22
|
|
|
""" |
23
|
|
|
for plugin in pkg_resources.iter_entry_points('kiwitcms.telemetry.plugins'): |
24
|
|
|
self.assertIn(plugin.module_name, settings.INSTALLED_APPS) |
25
|
|
|
|
26
|
|
|
|
27
|
|
|
class UrlDiscoveryTestCase(TestCase): |
28
|
|
|
def test_urlpatterns_is_updated(self): |
29
|
|
|
""" |
30
|
|
|
Given there are some plugins installed |
31
|
|
|
Then validate urlpatterns: |
32
|
|
|
|
33
|
|
|
- ^<plugin-name>/ includes(<plugin-module-urls>) |
34
|
|
|
""" |
35
|
|
|
for plugin in pkg_resources.iter_entry_points('kiwitcms.telemetry.plugins'): |
36
|
|
|
for url_resolver in urlpatterns: |
37
|
|
|
if isinstance(url_resolver, URLResolver): |
38
|
|
|
if str(url_resolver.pattern) == '^%s/' % plugin.name and \ |
39
|
|
|
url_resolver.urlconf_module.__name__ == plugin.module_name+'.urls': |
40
|
|
|
return |
41
|
|
|
|
42
|
|
|
self.fail('No plugins found or urlpatterns not valid') |
43
|
|
|
|
44
|
|
|
|
45
|
|
|
class MenuDiscoveryTestCase(TestCase): |
46
|
|
|
def test_menu_is_updated(self): |
47
|
|
|
""" |
48
|
|
|
Given there are some plugins installed |
49
|
|
|
Then navigation menu under TELEMETRY will be extended |
50
|
|
|
""" |
51
|
|
|
for name, target in settings.MENU_ITEMS: |
52
|
|
|
if name == _('TELEMETRY'): |
53
|
|
|
for menu_item in plugin_menu.MENU_ITEMS: |
54
|
|
|
self.assertIn(menu_item, target) |
55
|
|
|
|
56
|
|
|
return |
57
|
|
|
|
58
|
|
|
self.fail('TELEMETRY not found in settings.MENU_ITEMS') |
59
|
|
|
|
60
|
|
|
def test_menu_rendering(self): |
61
|
|
|
""" |
62
|
|
|
Given there are some plugins installed |
63
|
|
|
Then navigation menu under TELEMETRY will be rendered |
64
|
|
|
with several levels of sub menus. |
65
|
|
|
""" |
66
|
|
|
response = self.client.get(reverse('iframe-navigation')) |
67
|
|
|
self.assertContains(response, 'Fake Plugin under TELEMETRY') |
68
|
|
|
self.assertContains( |
69
|
|
|
response, |
70
|
|
|
"<a class='dropdown-toggle' href='#' data-toggle='dropdown'>Fake Plugin sub-menu</a>", |
71
|
|
|
html=True) |
72
|
|
|
self.assertContains(response, |
73
|
|
|
'<a href="/a_fake_plugin/example/" target="_parent">Example</a>', |
74
|
|
|
html=True) |
75
|
|
|
self.assertContains( |
76
|
|
|
response, |
77
|
|
|
"<a class='dropdown-toggle' href='#' data-toggle='dropdown'>3rd level menu</a>", |
78
|
|
|
html=True) |
79
|
|
|
self.assertContains(response, 'Go to Dashboard') |
80
|
|
|
self.assertContains(response, 'Go to kiwitcms.org') |
81
|
|
|
|