Passed
Pull Request — master (#41)
by Paolo
06:50
created

submissions.tests.common.SubmissionDeleteMixin.setUp()   A

Complexity

Conditions 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 10
rs 10
c 0
b 0
f 0
cc 1
nop 1
1
#!/usr/bin/env python3
2
# -*- coding: utf-8 -*-
3
"""
4
Created on Thu Mar 28 16:25:39 2019
5
6
@author: Paolo Cozzi <[email protected]>
7
"""
8
9
import os
10
11
from django.test import Client
12
13
import common.tests
14
from image_app.models import Submission
15
16
from common.constants import (
17
    WAITING, LOADED, ERROR, READY, NEED_REVISION, SUBMITTED, COMPLETED,
18
    CRYOWEB_TYPE, CRB_ANIM_TYPE, TEMPLATE_TYPE)
19
20
21
class SubmissionFormMixin():
22
23
    data_sources_files = {
24
        CRYOWEB_TYPE: "cryoweb_test_data_only.sql",
25
        CRB_ANIM_TYPE: "crbanim_test_data.csv",
26
        "latin_type": "crbanim_test_data_latin-1.csv",
27
        TEMPLATE_TYPE: "Image_sample_template_with_example_20190405.xlsx",
28
        "not_valid_crbanim": "Mapping_rules_CRB-Anim_InjectTool_v1.csv"
29
    }
30
31
    data_sources_types = {
32
        CRYOWEB_TYPE: CRYOWEB_TYPE,
33
        CRB_ANIM_TYPE: CRB_ANIM_TYPE,
34
        "latin_type": CRB_ANIM_TYPE,
35
        TEMPLATE_TYPE: TEMPLATE_TYPE,
36
        "not_valid_crbanim": CRB_ANIM_TYPE
37
    }
38
39
    def get_data(self, ds_file=CRYOWEB_TYPE):
40
        """Get data dictionary"""
41
42
        # get ds_type reling on ds_file
43
        ds_type = self.data_sources_types[ds_file]
44
45
        # get data source path relying on type
46
        ds_path = os.path.join(
47
            common.tests.__path__[0],
48
            self.data_sources_files[ds_file]
49
        )
50
51
        return ds_type, ds_path
52
53
54 View Code Duplication
class SubmissionStatusMixin():
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
55
    """Test response with different submission statuses"""
56
57
    def test_waiting(self):
58
        """Test waiting statuses return to submission detail"""
59
60
        # update statuses
61
        self.submission.status = WAITING
62
        self.submission.save()
63
64
        # test redirect
65
        response = self.client.get(self.url)
66
        self.assertRedirects(response, self.redirect_url)
67
68
    def test_loaded(self):
69
        """Test loaded status"""
70
71
        # force submission status
72
        self.submission.status = LOADED
73
        self.submission.save()
74
75
        # test no redirect
76
        response = self.client.get(self.url)
77
        self.assertEqual(response.status_code, 200)
78
79
    def test_submitted(self):
80
        """Test submitted status"""
81
82
        # force submission status
83
        self.submission.status = SUBMITTED
84
        self.submission.save()
85
86
        # test redirect
87
        response = self.client.get(self.url)
88
        self.assertRedirects(response, self.redirect_url)
89
90
    def test_error(self):
91
        """Test error status"""
92
93
        # force submission status
94
        self.submission.status = ERROR
95
        self.submission.save()
96
97
        # test no redirect
98
        response = self.client.get(self.url)
99
        self.assertEqual(response.status_code, 200)
100
101
    def test_need_revision(self):
102
        """Test need_revision status"""
103
104
        # force submission status
105
        self.submission.status = NEED_REVISION
106
        self.submission.save()
107
108
        # test no redirect
109
        response = self.client.get(self.url)
110
        self.assertEqual(response.status_code, 200)
111
112
    def test_ready(self):
113
        """Test ready status"""
114
115
        # force submission status
116
        self.submission.status = READY
117
        self.submission.save()
118
119
        # test no redirect
120
        response = self.client.get(self.url)
121
        self.assertEqual(response.status_code, 200)
122
123
    def test_completed(self):
124
        """Test completed status"""
125
126
        # force submission status
127
        self.submission.status = COMPLETED
128
        self.submission.save()
129
130
        # test no redirect
131
        response = self.client.get(self.url)
132
        self.assertEqual(response.status_code, 200)
133
134
135
class SubmissionDataMixin():
136
    fixtures = [
137
        'image_app/animal',
138
        'image_app/dictbreed',
139
        'image_app/dictcountry',
140
        'image_app/dictrole',
141
        'image_app/dictsex',
142
        'image_app/dictspecie',
143
        'image_app/dictstage',
144
        'image_app/dictuberon',
145
        'image_app/name',
146
        'image_app/organization',
147
        'image_app/publication',
148
        'image_app/sample',
149
        'image_app/submission',
150
        'image_app/user',
151
        'validation/validationsummary',
152
    ]
153
154
    def setUp(self):
155
        # login a test user (defined in fixture)
156
        self.client = Client()
157
        self.client.login(username='test', password='test')
158
159
        # get a submission object
160
        self.submission = Submission.objects.get(pk=1)
161