|
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
|
|
|
|
|
14
|
|
|
|
|
15
|
|
|
class DataSourceMixinTestCase(CommonDataSourceMixinTest): |
|
16
|
|
|
# defining attribute classes |
|
17
|
|
|
submission_model = Submission |
|
18
|
|
|
|
|
19
|
|
|
def upload_datasource(self, message): |
|
20
|
|
|
"""test upload data from DatsSource""" |
|
21
|
|
|
|
|
22
|
|
|
super(DataSourceMixinTestCase, self).upload_datasource(message) |
|
23
|
|
|
|
|
24
|
|
|
# assert data into database |
|
25
|
|
|
self.assertTrue(db_has_data()) |
|
26
|
|
|
self.assertTrue(Animal.objects.exists()) |
|
27
|
|
|
self.assertTrue(Sample.objects.exists()) |
|
28
|
|
|
|
|
29
|
|
|
def check_errors(self, my_check, message): |
|
30
|
|
|
"""Common stuff for cehcking error in file loading""" |
|
31
|
|
|
|
|
32
|
|
|
super(DataSourceMixinTestCase, self).check_errors(my_check, message) |
|
33
|
|
|
|
|
34
|
|
|
# assert data into database |
|
35
|
|
|
self.assertFalse(db_has_data()) |
|
36
|
|
|
self.assertFalse(Animal.objects.exists()) |
|
37
|
|
|
self.assertFalse(Sample.objects.exists()) |
|
38
|
|
|
|
|
39
|
|
|
|
|
40
|
|
|
class FileReaderMixinTestCase: |
|
41
|
|
|
"""A class to deal with common text between CRBAnimReader and |
|
42
|
|
|
ExcelTemplateReader""" |
|
43
|
|
|
|
|
44
|
|
|
def test_check_species(self): |
|
45
|
|
|
"""Test check species method""" |
|
46
|
|
|
|
|
47
|
|
|
# get a country |
|
48
|
|
|
country = DictCountry.objects.get(label="United Kingdom") |
|
49
|
|
|
|
|
50
|
|
|
check, not_found = self.reader.check_species(country) |
|
51
|
|
|
|
|
52
|
|
|
self.assertTrue(check) |
|
53
|
|
|
self.assertEqual(len(not_found), 0) |
|
54
|
|
|
|
|
55
|
|
|
# changing species set |
|
56
|
|
|
DictSpecie.objects.filter(label='Capra hircus').delete() |
|
57
|
|
|
|
|
58
|
|
|
check, not_found = self.reader.check_species(country) |
|
59
|
|
|
|
|
60
|
|
|
# the read species are not included in fixtures |
|
61
|
|
|
self.assertFalse(check) |
|
62
|
|
|
self.assertGreater(len(not_found), 0) |
|
63
|
|
|
|
|
64
|
|
|
def test_check_sex(self): |
|
65
|
|
|
"""Test check sex method""" |
|
66
|
|
|
|
|
67
|
|
|
check, not_found = self.reader.check_sex() |
|
68
|
|
|
|
|
69
|
|
|
self.assertTrue(check) |
|
70
|
|
|
self.assertEqual(len(not_found), 0) |
|
71
|
|
|
|
|
72
|
|
|
# changing sex set |
|
73
|
|
|
DictSex.objects.filter(label='female').delete() |
|
74
|
|
|
|
|
75
|
|
|
check, not_found = self.reader.check_sex() |
|
76
|
|
|
|
|
77
|
|
|
# the read species are not included in fixtures |
|
78
|
|
|
self.assertFalse(check) |
|
79
|
|
|
self.assertGreater(len(not_found), 0) |
|
80
|
|
|
|