|
1
|
|
|
#!/usr/bin/env python3 |
|
2
|
|
|
# -*- coding: utf-8 -*- |
|
3
|
|
|
""" |
|
4
|
|
|
Created on Fri Jul 5 15:57:10 2019 |
|
5
|
|
|
|
|
6
|
|
|
@author: Paolo Cozzi <[email protected]> |
|
7
|
|
|
""" |
|
8
|
|
|
|
|
9
|
|
|
from common.tests import DataSourceMixinTestCase as CommonDataSourceMixinTest |
|
10
|
|
|
|
|
11
|
|
|
from ..models import ( |
|
12
|
|
|
db_has_data, Animal, Sample, Submission, DictCountry, DictSpecie, DictSex, |
|
13
|
|
|
Person) |
|
14
|
|
|
|
|
15
|
|
|
|
|
16
|
|
|
class DataSourceMixinTestCase(CommonDataSourceMixinTest): |
|
17
|
|
|
# defining attribute classes |
|
18
|
|
|
submission_model = Submission |
|
19
|
|
|
|
|
20
|
|
|
def upload_datasource(self, message): |
|
21
|
|
|
"""test upload data from DatsSource""" |
|
22
|
|
|
|
|
23
|
|
|
super(DataSourceMixinTestCase, self).upload_datasource(message) |
|
24
|
|
|
|
|
25
|
|
|
# assert data into database |
|
26
|
|
|
self.assertTrue(db_has_data()) |
|
27
|
|
|
self.assertTrue(Animal.objects.exists()) |
|
28
|
|
|
self.assertTrue(Sample.objects.exists()) |
|
29
|
|
|
|
|
30
|
|
|
def check_errors(self, my_check, message): |
|
31
|
|
|
"""Common stuff for cehcking error in file loading""" |
|
32
|
|
|
|
|
33
|
|
|
super(DataSourceMixinTestCase, self).check_errors(my_check, message) |
|
34
|
|
|
|
|
35
|
|
|
# assert data into database |
|
36
|
|
|
self.assertFalse(db_has_data()) |
|
37
|
|
|
self.assertFalse(Animal.objects.exists()) |
|
38
|
|
|
self.assertFalse(Sample.objects.exists()) |
|
39
|
|
|
|
|
40
|
|
|
|
|
41
|
|
|
class FileReaderMixinTestCase: |
|
42
|
|
|
"""A class to deal with common text between CRBAnimReader and |
|
43
|
|
|
ExcelTemplateReader""" |
|
44
|
|
|
|
|
45
|
|
|
def test_check_species(self): |
|
46
|
|
|
"""Test check species method""" |
|
47
|
|
|
|
|
48
|
|
|
# get a country |
|
49
|
|
|
country = DictCountry.objects.get(label="United Kingdom") |
|
50
|
|
|
|
|
51
|
|
|
check, not_found = self.reader.check_species(country) |
|
52
|
|
|
|
|
53
|
|
|
self.assertTrue(check) |
|
54
|
|
|
self.assertEqual(len(not_found), 0) |
|
55
|
|
|
|
|
56
|
|
|
# changing species set |
|
57
|
|
|
DictSpecie.objects.filter(label='Capra hircus').delete() |
|
58
|
|
|
|
|
59
|
|
|
check, not_found = self.reader.check_species(country) |
|
60
|
|
|
|
|
61
|
|
|
# the read species are not included in fixtures |
|
62
|
|
|
self.assertFalse(check) |
|
63
|
|
|
self.assertGreater(len(not_found), 0) |
|
64
|
|
|
|
|
65
|
|
|
def test_check_sex(self): |
|
66
|
|
|
"""Test check sex method""" |
|
67
|
|
|
|
|
68
|
|
|
check, not_found = self.reader.check_sex() |
|
69
|
|
|
|
|
70
|
|
|
self.assertTrue(check) |
|
71
|
|
|
self.assertEqual(len(not_found), 0) |
|
72
|
|
|
|
|
73
|
|
|
# changing sex set |
|
74
|
|
|
DictSex.objects.filter(label='female').delete() |
|
75
|
|
|
|
|
76
|
|
|
check, not_found = self.reader.check_sex() |
|
77
|
|
|
|
|
78
|
|
|
# the read species are not included in fixtures |
|
79
|
|
|
self.assertFalse(check) |
|
80
|
|
|
self.assertGreater(len(not_found), 0) |
|
81
|
|
|
|
|
82
|
|
|
def test_check_countries(self): |
|
83
|
|
|
"Testing country method""" |
|
84
|
|
|
|
|
85
|
|
|
# assert countries are present |
|
86
|
|
|
check, not_found = self.reader.check_countries() |
|
87
|
|
|
|
|
88
|
|
|
self.assertTrue(check) |
|
89
|
|
|
self.assertEqual(len(not_found), 0) |
|
90
|
|
|
|
|
91
|
|
|
# remove a country from UID |
|
92
|
|
|
DictCountry.objects.filter(label="Italy").delete() |
|
93
|
|
|
|
|
94
|
|
|
check, not_found = self.reader.check_countries() |
|
95
|
|
|
|
|
96
|
|
|
self.assertFalse(check) |
|
97
|
|
|
self.assertGreater(len(not_found), 0) |
|
98
|
|
|
|
|
99
|
|
|
|
|
100
|
|
|
# a mixin to correctly instantiate a person object in order to get |
|
101
|
|
|
# a biosample json for test data |
|
102
|
|
|
class PersonMixinTestCase(object): |
|
103
|
|
|
@classmethod |
|
104
|
|
|
def setUpClass(cls): |
|
105
|
|
|
# calling my base class setup |
|
106
|
|
|
super().setUpClass() |
|
107
|
|
|
|
|
108
|
|
|
# now fix person table |
|
109
|
|
|
person = Person.objects.get(user__username="test") |
|
110
|
|
|
person.affiliation_id = 1 |
|
111
|
|
|
person.role_id = 1 |
|
112
|
|
|
person.initials = "T" |
|
113
|
|
|
person.save() |
|
114
|
|
|
|