|
1
|
|
|
from django.test import Client, TestCase |
|
2
|
|
|
from django.urls import resolve, reverse |
|
3
|
|
|
|
|
4
|
|
|
from common.tests import GeneralMixinTestCase, OwnerMixinTestCase |
|
5
|
|
|
|
|
6
|
|
|
from ..views import SubmissionValidationSummaryView |
|
7
|
|
|
|
|
8
|
|
|
|
|
9
|
|
|
class SubmissionValidationSummaryViewTest(GeneralMixinTestCase, |
|
10
|
|
|
OwnerMixinTestCase, TestCase): |
|
11
|
|
|
"""Test Submission DetailView""" |
|
12
|
|
|
fixtures = [ |
|
13
|
|
|
"image_app/user", |
|
14
|
|
|
"image_app/dictcountry", |
|
15
|
|
|
"image_app/dictrole", |
|
16
|
|
|
"image_app/organization", |
|
17
|
|
|
"image_app/submission", |
|
18
|
|
|
"validation/validationsummary" |
|
19
|
|
|
] |
|
20
|
|
|
|
|
21
|
|
|
def setUp(self): |
|
22
|
|
|
# login a test user (defined in fixture) |
|
23
|
|
|
self.client = Client() |
|
24
|
|
|
self.client.login(username='test', password='test') |
|
25
|
|
|
|
|
26
|
|
|
self.url_animals = reverse('submissions:validation_summary', kwargs={ |
|
27
|
|
|
'pk': 1, 'type': 'animals'}) |
|
28
|
|
|
self.url_samples = reverse('submissions:validation_summary', kwargs={ |
|
29
|
|
|
'pk': 1, 'type': 'samples'}) |
|
30
|
|
|
self.url = self.url_animals |
|
31
|
|
|
self.response = self.client.get(self.url_animals) |
|
32
|
|
|
|
|
33
|
|
|
def test_url_resolves_view_for_animals(self): |
|
34
|
|
|
view = resolve('/submissions/1/validation_summary/animals/') |
|
35
|
|
|
self.assertIsInstance(view.func.view_class(), |
|
36
|
|
|
SubmissionValidationSummaryView) |
|
37
|
|
|
|
|
38
|
|
|
def test_url_resolves_view_for_samples(self): |
|
39
|
|
|
view = resolve('/submissions/1/validation_summary/samples/') |
|
40
|
|
|
self.assertIsInstance(view.func.view_class(), |
|
41
|
|
|
SubmissionValidationSummaryView) |
|
42
|
|
|
|
|
43
|
|
|
def test_new_not_found_status_code_for_animals(self): |
|
44
|
|
|
url = reverse('submissions:validation_summary', kwargs={ |
|
45
|
|
|
'pk': 99, 'type': 'animals'}) |
|
46
|
|
|
response = self.client.get(url) |
|
47
|
|
|
self.assertEqual(response.status_code, 404) |
|
48
|
|
|
|
|
49
|
|
|
def test_new_not_found_status_code_for_samples(self): |
|
50
|
|
|
url = reverse('submissions:validation_summary', kwargs={ |
|
51
|
|
|
'pk': 99, 'type': 'samples'}) |
|
52
|
|
|
response = self.client.get(url) |
|
53
|
|
|
self.assertEqual(response.status_code, 404) |
|
54
|
|
|
|
|
55
|
|
|
def test_ownership_for_animals(self): |
|
56
|
|
|
"""Test ownership for a submissions""" |
|
57
|
|
|
|
|
58
|
|
|
client = Client() |
|
59
|
|
|
client.login(username='test2', password='test2') |
|
60
|
|
|
|
|
61
|
|
|
response = client.get(self.url_animals) |
|
62
|
|
|
self.assertEqual(response.status_code, 404) |
|
63
|
|
|
|
|
64
|
|
|
def test_ownership_for_samples(self): |
|
65
|
|
|
"""Test ownership for a submissions""" |
|
66
|
|
|
|
|
67
|
|
|
client = Client() |
|
68
|
|
|
client.login(username='test2', password='test2') |
|
69
|
|
|
|
|
70
|
|
|
response = client.get(self.url_samples) |
|
71
|
|
|
self.assertEqual(response.status_code, 404) |
|
72
|
|
|
|
|
73
|
|
|
def test_contains_mesages_for_animals(self): |
|
74
|
|
|
"""test validation summary badges and messages""" |
|
75
|
|
|
response = self.client.get(self.url_animals) |
|
76
|
|
|
self.assertContains(response, "Pass: 0") |
|
77
|
|
|
self.assertContains(response, "Warnings: 1") |
|
78
|
|
|
self.assertContains(response, "Errors: 0") |
|
79
|
|
|
self.assertContains(response, "JSON Errors: 0") |
|
80
|
|
|
self.assertContains(response, "Wrong JSON structure") |
|
81
|
|
|
|
|
82
|
|
|
def test_contains_mesages_for_samples(self): |
|
83
|
|
|
"""test validation summary badges and messages""" |
|
84
|
|
|
response = self.client.get(self.url_samples) |
|
85
|
|
|
self.assertContains(response, "Pass: 0") |
|
86
|
|
|
self.assertContains(response, "Warnings: 0") |
|
87
|
|
|
self.assertContains(response, "Errors: 0") |
|
88
|
|
|
self.assertContains(response, "JSON Errors: 0") |
|
89
|
|
|
self.assertContains(response, "Wrong JSON structure") |
|
90
|
|
|
|