This repository has been archived by the owner on Dec 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
test_issue.py
138 lines (125 loc) · 5.68 KB
/
test_issue.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# -*- coding: utf-8 -*-
from urllib import quote_plus
from django.test import TestCase
from django.core.urlresolvers import reverse
from nose.tools import *
from ispdb.config import models
from ispdb.tests.common import adding_domain_form
from ispdb.tests.common import success_code, fail_code
def adding_issue_form():
form = adding_domain_form()
form['show_form'] = 'False'
form['title'] = 'Test'
form['description'] = 'Test'
return form
class IssueTest(TestCase):
fixtures = ['login_testdata', 'issue_testdata']
def add_issue(self, updated_config=False, config_id=1):
self.client.login(username='test', password='test')
issue = models.Issue.objects.filter(title='Test')
assert_false(issue)
form = adding_issue_form()
form["domain-INITIAL_FORMS"] = "1"
form["domain-0-id"] = "1"
form["domain-0-name"] = "test1.com"
form["display_name"] = "testing2"
form["docurl-INITIAL_FORMS"] = "1"
form["docurl-0-id"] = "1"
form["docurl-0-url"] = "http://test1.com/"
form["desc_0-INITIAL_FORMS"] = "1"
form["desc_0-0-id"] = "1"
form["desc_0-0-description"] = "test1"
form["enableurl-INITIAL_FORMS"] = "1"
form["enableurl-0-id"] = "1"
form["enableurl-0-url"] = "http://test1.com/"
form["inst_0-INITIAL_FORMS"] = "1"
form["inst_0-0-id"] = "1"
form["inst_0-0-description"] = "test1"
if updated_config:
form['show_form'] = 'True'
res = self.client.post(reverse("ispdb_report", args=[config_id]), form)
assert_equal(res.status_code, success_code)
issue = models.Issue.objects.get(title='Test')
assert isinstance(issue, models.Issue)
assert_equal(issue.updated_config != None, updated_config)
self.client.logout()
def test_add_issue_no_login(self):
res = self.client.post(reverse("ispdb_report",args=[2]),
adding_issue_form(),
follow=True)
# Make sure it redirects to login page
goodRedirect = "/login/?next=%s" % (quote_plus("/report/2"))
self.assertRedirects(res, goodRedirect)
def test_add_issue(self):
self.add_issue()
def test_add_issue_with_updated_config(self):
self.add_issue(updated_config=True)
def test_close_issue_normal_user(self):
self.add_issue()
self.client.login(username='test', password='test')
res = self.client.post(reverse("ispdb_show_issue",args=[1]),
{"action":"close"},
follow=True)
issue = models.Issue.objects.get(title='Test')
assert_equal(issue.status, "open")
# Make sure it redirects to login page
goodRedirect = "/login/"
self.assertRedirects(res, goodRedirect)
def test_close_issue_superuser(self):
self.add_issue()
self.client.login(username='test_admin', password='test')
res = self.client.post(reverse("ispdb_show_issue",args=[1]),
{"action":"close"},
follow=True)
issue = models.Issue.objects.get(title='Test')
assert_equal(issue.status, "closed")
def test_merge_issue_normal_user(self):
self.add_issue(updated_config=True)
self.client.login(username='test', password='test')
res = self.client.post(reverse("ispdb_show_issue",args=[1]),
{"action":"merge"},
follow=True)
issue = models.Issue.objects.get(title='Test')
assert_equal(issue.status, "open")
# Make sure it redirects to login page
goodRedirect = "/login/"
self.assertRedirects(res, goodRedirect)
def test_merge_locked_config(self):
self.add_issue(updated_config=True)
issue = models.Issue.objects.get(title='Test')
issue.config.locked = True
issue.config.save()
self.client.login(username='test_admin', password='test')
res = self.client.post(reverse("ispdb_show_issue",args=[1]),
{"action":"merge"},
follow=True)
issue = models.Issue.objects.get(title='Test')
assert_equal(issue.status, "open")
assert_true(issue.config.display_name != "testing2")
assert_true("This configuration is locked. Only admins can unlock it."
in res.content)
def test_merge_issue_superuser(self):
self.add_issue(updated_config=True)
self.client.login(username='test_admin', password='test')
res = self.client.post(reverse("ispdb_show_issue",args=[1]),
{"action":"merge"},
follow=True)
issue = models.Issue.objects.get(title='Test')
assert_equal(issue.status, "closed")
assert_equal(issue.config.display_name, "testing2")
assert_equal(1, len(issue.config.domains.all()))
assert_equal("test1.com", issue.config.domains.all()[0].name)
# doc url
assert_equal(len(issue.config.docurl_set.all()), 1)
docurl = issue.config.docurl_set.all()[0]
assert_equal(docurl.url, 'http://test1.com/')
assert_equal(len(docurl.descriptions.all()), 1)
desc = docurl.descriptions.all()[0]
assert_equal(desc.description, 'test1')
# enable URL
assert_equal(len(issue.config.enableurl_set.all()), 1)
enableurl = issue.config.enableurl_set.all()[0]
assert_equal(enableurl.url, 'http://test1.com/')
assert_equal(len(enableurl.instructions.all()), 1)
inst = enableurl.instructions.all()[0]
assert_equal(inst.description, 'test1')