-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtests.py
More file actions
81 lines (68 loc) · 2.77 KB
/
tests.py
File metadata and controls
81 lines (68 loc) · 2.77 KB
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
from django.test import TestCase
from django.urls import reverse
from django.contrib.messages import get_messages
from core import models as core_models, files
from utils.testing import helpers
class GalleyViewTests(TestCase):
@classmethod
def setUpTestData(cls):
# Create press, journals and an editor
helpers.create_press()
cls.journal_one, cls.journal_two = helpers.create_journals()
cls.editor = helpers.create_user(
'emh@voyager.com',
['editor'],
cls.journal_one,
)
# Create test files
cls.file_with_unsupported_mime = core_models.File.objects.create(
mime_type='unsupported/type',
original_filename='unsupported_file.txt',
uuid_filename='unsupported_file_uuid.txt'
)
cls.file_with_supported_mime = core_models.File.objects.create(
mime_type=files.MIMETYPES_WITH_FIGURES[0],
original_filename='supported_file.txt',
uuid_filename='supported_file_uuid.txt'
)
# Create test articles
cls.article = helpers.create_article(
cls.journal_one,
)
# Create galleys
cls.galley_with_unsupported_file = core_models.Galley.objects.create(
article=cls.article,
file=cls.file_with_unsupported_mime
)
cls.galley_without_file = core_models.Galley.objects.create(
article=cls.article,
file=None
)
cls.galley_with_supported_file = core_models.Galley.objects.create(
article=cls.article,
file=cls.file_with_supported_mime
)
def setUp(self):
self.client.force_login(self.editor)
def test_galley_file_not_editable(self):
response = self.client.get(reverse('edit_galley_file', kwargs={
'article_id': self.article.id,
'galley_id': self.galley_with_unsupported_file.id
}))
messages = list(get_messages(response.wsgi_request))
self.assertEqual(len(messages), 1)
self.assertRedirects(response, reverse('editor_galley_list'))
def test_galley_has_no_file(self):
response = self.client.get(reverse('edit_galley_file', kwargs={
'article_id': self.article.id,
'galley_id': self.galley_without_file.id
}))
messages = list(get_messages(response.wsgi_request))
self.assertEqual(len(messages), 1)
self.assertRedirects(response, reverse('editor_galley_list'))
def test_galley_with_editable_file(self):
response = self.client.get(reverse('edit_galley_file', kwargs={
'article_id': self.article.id,
'galley_id': self.galley_with_supported_file.id
}))
self.assertEqual(response.status_code, 200)