1
|
|
|
# -*- coding: utf-8 -*- |
2
|
|
|
# pylint: disable=invalid-name, no-member |
3
|
|
|
|
4
|
|
|
from django.conf import settings |
5
|
|
|
from django.test import TestCase |
6
|
|
|
from django.template.loader import render_to_string |
7
|
|
|
from django.utils.translation import gettext_lazy as _ |
8
|
|
|
from mock import patch |
9
|
|
|
|
10
|
|
|
from tcms.core.history import history_email_for |
11
|
|
|
from tcms.testcases.helpers.email import get_case_notification_recipients |
12
|
|
|
from tcms.tests import BasePlanCase |
13
|
|
|
from tcms.tests.factories import (ComponentFactory, TagFactory, |
14
|
|
|
TestCaseComponentFactory, TestCaseTagFactory) |
15
|
|
|
from tcms.tests.factories import TestCaseFactory |
16
|
|
|
|
17
|
|
|
|
18
|
|
|
class SupportsCyrillic(TestCase): |
19
|
|
|
def test_create_testcase_with_cyrillic_works_issue_1770(self): |
20
|
|
|
# https://github.com/kiwitcms/Kiwi/issues/1770 |
21
|
|
|
case = TestCaseFactory(summary="Това е тест на кирилица") |
22
|
|
|
case.save() |
23
|
|
|
|
24
|
|
|
case.refresh_from_db() |
25
|
|
|
self.assertTrue(case.summary.endswith("кирилица")) |
26
|
|
|
|
27
|
|
|
|
28
|
|
|
class TestCaseRemoveComponent(BasePlanCase): |
29
|
|
|
"""Test TestCase.remove_component""" |
30
|
|
|
|
31
|
|
|
@classmethod |
32
|
|
|
def setUpTestData(cls): |
33
|
|
|
super(TestCaseRemoveComponent, cls).setUpTestData() |
34
|
|
|
|
35
|
|
|
cls.component_1 = ComponentFactory(name='Application', |
36
|
|
|
product=cls.product, |
37
|
|
|
initial_owner=cls.tester, |
38
|
|
|
initial_qa_contact=cls.tester) |
39
|
|
|
cls.component_2 = ComponentFactory(name='Database', |
40
|
|
|
product=cls.product, |
41
|
|
|
initial_owner=cls.tester, |
42
|
|
|
initial_qa_contact=cls.tester) |
43
|
|
|
|
44
|
|
|
cls.cc_rel_1 = TestCaseComponentFactory(case=cls.case, |
45
|
|
|
component=cls.component_1) |
46
|
|
|
cls.cc_rel_2 = TestCaseComponentFactory(case=cls.case, |
47
|
|
|
component=cls.component_2) |
48
|
|
|
|
49
|
|
|
def test_remove_a_component(self): |
50
|
|
|
self.case.remove_component(self.component_1) |
51
|
|
|
|
52
|
|
|
found = self.case.component.filter(pk=self.component_1.pk).exists() |
53
|
|
|
self.assertFalse( |
54
|
|
|
found, |
55
|
|
|
'Component {0} exists. But, it should be removed.'.format( |
56
|
|
|
self.component_1.pk)) |
57
|
|
|
found = self.case.component.filter(pk=self.component_2.pk).exists() |
58
|
|
|
self.assertTrue( |
59
|
|
|
found, |
60
|
|
|
'Component {0} does not exist. It should not be removed.'.format( |
61
|
|
|
self.component_2.pk)) |
62
|
|
|
|
63
|
|
|
|
64
|
|
|
class TestCaseRemoveTag(BasePlanCase): |
65
|
|
|
"""Test TestCase.remove_tag""" |
66
|
|
|
|
67
|
|
|
@classmethod |
68
|
|
|
def setUpTestData(cls): |
69
|
|
|
super(TestCaseRemoveTag, cls).setUpTestData() |
70
|
|
|
|
71
|
|
|
cls.tag_rhel = TagFactory(name='rhel') |
72
|
|
|
cls.tag_fedora = TagFactory(name='fedora') |
73
|
|
|
TestCaseTagFactory(case=cls.case, tag=cls.tag_rhel) |
74
|
|
|
TestCaseTagFactory(case=cls.case, tag=cls.tag_fedora) |
75
|
|
|
|
76
|
|
|
def test_remove_tag(self): |
77
|
|
|
self.case.remove_tag(self.tag_rhel) |
78
|
|
|
|
79
|
|
|
tag_pks = list(self.case.tag.all().values_list('pk', flat=True)) |
80
|
|
|
self.assertEqual([self.tag_fedora.pk], tag_pks) |
81
|
|
|
|
82
|
|
|
|
83
|
|
|
class TestSendMailOnCaseIsUpdated(BasePlanCase): |
84
|
|
|
"""Test send mail on case post_save signal is triggered""" |
85
|
|
|
@classmethod |
86
|
|
|
def setUpTestData(cls): |
87
|
|
|
super().setUpTestData() |
88
|
|
|
|
89
|
|
|
cls.case.emailing.notify_on_case_update = True |
90
|
|
|
cls.case.emailing.auto_to_case_author = True |
91
|
|
|
cls.case.emailing.save() |
92
|
|
|
|
93
|
|
|
@patch('tcms.core.utils.mailto.send_mail') |
94
|
|
|
def test_send_mail_to_case_author(self, send_mail): |
95
|
|
|
self.case.summary = 'New summary for running test' |
96
|
|
|
self.case.save() |
97
|
|
|
|
98
|
|
|
expected_subject, expected_body = history_email_for(self.case, self.case.summary) |
99
|
|
|
recipients = get_case_notification_recipients(self.case) |
100
|
|
|
|
101
|
|
|
# Verify notification mail |
102
|
|
|
send_mail.assert_called_once_with(settings.EMAIL_SUBJECT_PREFIX + expected_subject, |
103
|
|
|
expected_body, |
104
|
|
|
settings.DEFAULT_FROM_EMAIL, |
105
|
|
|
recipients, |
106
|
|
|
fail_silently=False) |
107
|
|
|
|
108
|
|
|
|
109
|
|
|
class TestSendMailOnCaseIsDeleted(BasePlanCase): |
110
|
|
|
"""Test send mail on case post_delete signal is triggered""" |
111
|
|
|
@classmethod |
112
|
|
|
def setUpTestData(cls): |
113
|
|
|
super().setUpTestData() |
114
|
|
|
|
115
|
|
|
cls.case.emailing.notify_on_case_delete = True |
116
|
|
|
cls.case.emailing.auto_to_case_author = True |
117
|
|
|
cls.case.emailing.save() |
118
|
|
|
|
119
|
|
|
@patch('tcms.core.utils.mailto.send_mail') |
120
|
|
|
def test_send_mail_to_case_author(self, send_mail): |
121
|
|
|
expected_subject = _('DELETED: TestCase #%(pk)d - %(summary)s') % { |
122
|
|
|
'pk': self.case.pk, |
123
|
|
|
'summary': self.case.summary |
124
|
|
|
} |
125
|
|
|
expected_body = render_to_string('email/post_case_delete/email.txt', {'case': self.case}) |
126
|
|
|
recipients = get_case_notification_recipients(self.case) |
127
|
|
|
|
128
|
|
|
self.case.delete() |
129
|
|
|
|
130
|
|
|
# Verify notification mail |
131
|
|
|
send_mail.assert_called_once_with(settings.EMAIL_SUBJECT_PREFIX + expected_subject, |
132
|
|
|
expected_body, |
133
|
|
|
settings.DEFAULT_FROM_EMAIL, |
134
|
|
|
recipients, |
135
|
|
|
fail_silently=False) |
136
|
|
|
|