1
|
|
|
# pylint: disable=too-many-ancestors,wrong-import-position |
2
|
|
|
|
3
|
|
|
import unittest |
4
|
|
|
|
5
|
|
|
from django.conf import settings |
6
|
|
|
|
7
|
|
|
if 'tcms.bugs.apps.AppConfig' not in settings.INSTALLED_APPS: |
8
|
|
|
raise unittest.SkipTest('tcms.bugs is disabled') |
9
|
|
|
|
10
|
|
|
from django.urls import reverse # noqa: E402 |
11
|
|
|
from django.utils.translation import gettext_lazy as _ # noqa: E402 |
12
|
|
|
|
13
|
|
|
from tcms.core.templatetags.extra_filters import markdown2html # noqa: E402 |
14
|
|
|
from tcms.bugs.models import Bug # noqa: E402 |
15
|
|
|
from tcms.bugs.tests.factory import BugFactory # noqa: E402 |
16
|
|
|
from tcms.tests import ( # noqa: E402 |
17
|
|
|
BaseCaseRun, |
18
|
|
|
LoggedInTestCase, |
19
|
|
|
user_should_have_perm |
20
|
|
|
) |
21
|
|
|
from tcms.tests.factories import ( # noqa: E402 |
22
|
|
|
BuildFactory, |
23
|
|
|
ComponentFactory, |
24
|
|
|
ProductFactory, |
25
|
|
|
UserFactory, |
26
|
|
|
VersionFactory |
27
|
|
|
) |
28
|
|
|
from tcms.utils.permissions import initiate_user_with_default_setups # noqa: E402 |
29
|
|
|
|
30
|
|
|
|
31
|
|
|
class TestBugStatusChange(BaseCaseRun): |
32
|
|
|
"""Test the possible bug status changes. |
33
|
|
|
|
34
|
|
|
Cases: |
35
|
|
|
* Closing an open bug. |
36
|
|
|
* Reopening a closed bug. |
37
|
|
|
""" |
38
|
|
|
|
39
|
|
|
@classmethod |
40
|
|
|
def setUpTestData(cls): |
41
|
|
|
super().setUpTestData() |
42
|
|
|
|
43
|
|
|
initiate_user_with_default_setups(cls.tester) |
44
|
|
|
cls.comment_bug_url = reverse('bugs-comment') |
45
|
|
|
user_should_have_perm(cls.tester, 'bugs.change_bug') |
46
|
|
|
|
47
|
|
|
def test_close_an_open_bug(self): |
48
|
|
|
bug = BugFactory(status=True) |
49
|
|
|
|
50
|
|
|
edit_bug_data = { |
51
|
|
|
'bug': bug.pk, |
52
|
|
|
'text': 'Close the bug.', |
53
|
|
|
'action': 'close' |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
redirect_url = reverse('bugs-get', args=[bug.pk]) |
57
|
|
|
response = self.client.post(self.comment_bug_url, edit_bug_data, follow=True) |
58
|
|
|
|
59
|
|
|
self.assertContains(response, markdown2html(_('*bug closed*'))) |
60
|
|
|
self.assertContains(response, 'Close the bug.') |
61
|
|
|
self.assertRedirects(response, redirect_url) |
62
|
|
|
bug.refresh_from_db() |
63
|
|
|
self.assertFalse(bug.status) |
64
|
|
|
|
65
|
|
|
# test case for https://github.com/kiwitcms/Kiwi/issues/1152 |
66
|
|
|
def test_reopen_a_closed_bug(self): |
67
|
|
|
bug = BugFactory(status=False) |
68
|
|
|
|
69
|
|
|
edit_bug_data = { |
70
|
|
|
'bug': bug.pk, |
71
|
|
|
'text': 'Reopen the bug.', |
72
|
|
|
'action': 'reopen' |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
redirect_url = reverse('bugs-get', args=[bug.pk]) |
76
|
|
|
response = self.client.post(self.comment_bug_url, edit_bug_data, follow=True) |
77
|
|
|
|
78
|
|
|
self.assertContains(response, markdown2html(_('*bug reopened*'))) |
79
|
|
|
self.assertContains(response, 'Reopen the bug.') |
80
|
|
|
self.assertRedirects(response, redirect_url) |
81
|
|
|
bug.refresh_from_db() |
82
|
|
|
self.assertTrue(bug.status) |
83
|
|
|
|
84
|
|
|
|
85
|
|
|
class TestNewBug(LoggedInTestCase): |
86
|
|
|
|
87
|
|
|
@classmethod |
88
|
|
|
def setUpTestData(cls): |
89
|
|
|
super().setUpTestData() |
90
|
|
|
user_should_have_perm(cls.tester, 'bugs.add_bug') |
91
|
|
|
|
92
|
|
|
cls.url = reverse('bugs-new') |
93
|
|
|
|
94
|
|
|
cls.summary = 'A shiny new bug!' |
95
|
|
|
cls.product = ProductFactory() |
96
|
|
|
cls.version = VersionFactory(product=cls.product) |
97
|
|
|
cls.build = BuildFactory(product=cls.product) |
98
|
|
|
cls.post_data = { |
99
|
|
|
'summary': cls.summary, |
100
|
|
|
'reporter': cls.tester.pk, |
101
|
|
|
'product': cls.product.pk, |
102
|
|
|
'version': cls.version.pk, |
103
|
|
|
'build': cls.version.pk, |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
def test_get_view(self): |
107
|
|
|
response = self.client.get(self.url) |
108
|
|
|
|
109
|
|
|
self.assertEqual(response.status_code, 200) |
110
|
|
|
self.assertEqual(response.context['page_title'], _('New bug')) |
111
|
|
|
self.assertEqual(response.context['form_post_url'], reverse('bugs-new')) |
112
|
|
|
self.assertTemplateUsed(response, 'bugs/mutable.html') |
113
|
|
|
|
114
|
|
|
form = response.context['form'] |
115
|
|
|
self.assertEqual(form.initial['reporter'].pk, self.tester.pk) |
116
|
|
|
self.assertEqual(form.fields['version'].queryset.count(), 0) |
117
|
|
|
self.assertEqual(form.fields['build'].queryset.count(), 0) |
118
|
|
|
|
119
|
|
|
def test_create_new_bug(self): |
120
|
|
|
initial_bug_count = Bug.objects.count() |
121
|
|
|
|
122
|
|
|
response = self.client.post(self.url, self.post_data) |
123
|
|
|
|
124
|
|
|
bug_created = Bug.objects.last() |
125
|
|
|
self.assertRedirects( |
126
|
|
|
response, |
127
|
|
|
reverse('bugs-get', args=(bug_created.pk,)), |
128
|
|
|
status_code=302, |
129
|
|
|
target_status_code=200 |
130
|
|
|
) |
131
|
|
|
self.assertEqual(Bug.objects.count(), initial_bug_count + 1) |
132
|
|
|
self.assertEqual(bug_created.summary, self.summary) |
133
|
|
|
|
134
|
|
|
def test_new_bug_assignee_inferred_from_components(self): |
135
|
|
|
comp = ComponentFactory(initial_owner=UserFactory(), product=self.product) |
136
|
|
|
|
137
|
|
|
self.client.post(self.url, self.post_data, follow=True) |
138
|
|
|
|
139
|
|
|
bug_created = Bug.objects.last() |
140
|
|
|
self.assertEqual(bug_created.summary, self.summary) |
141
|
|
|
self.assertEqual(bug_created.assignee, comp.initial_owner) |
142
|
|
|
|