/
test_models.py
188 lines (138 loc) · 5.88 KB
/
test_models.py
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
"""Tests for ``clinvar_export.models``."""
from test_plus.test import TestCase
from variants.models import Case
from variants.tests.factories import CaseFactory
from clinvar_export.models import (
AssertionMethod,
Family,
Individual,
Organisation,
Submission,
SubmissionSet,
Submitter,
SubmittingOrg,
refresh_individual_sex_affected,
)
from clinvar_export.tests.factories import (
AssertionMethodFactory,
FamilyFactory,
IndividualFactory,
OrganisationFactory,
SubmissionFactory,
SubmissionSetFactory,
SubmitterFactory,
SubmittingOrgFactory,
)
class TestFamily(TestCase):
"""Basic tests for the ``Family`` model and manager."""
def testCreate(self):
self.assertEquals(Family.objects.count(), 0)
FamilyFactory()
self.assertEquals(Family.objects.count(), 1)
def testGetOrCreateInProjectByCaseName(self):
case = CaseFactory()
self.assertEquals(Family.objects.count(), 0)
family = Family.objects.get_or_create_in_project(project=case.project, case_name=case.name)
self.assertEquals(Family.objects.count(), 1)
self.assertEquals(family.case.id, case.id)
def testGetOrCreateInProjectByCaseNameFails(self):
case = CaseFactory()
self.assertEquals(Family.objects.count(), 0)
with self.assertRaises(Case.DoesNotExist):
Family.objects.get_or_create_in_project(project=case.project, case_name=case.name + "_")
self.assertEquals(Family.objects.count(), 0)
def testGetOrCreateInProjectByCase(self):
case = CaseFactory()
self.assertEquals(Family.objects.count(), 0)
family = Family.objects.get_or_create_in_project(project=case.project, case=case)
self.assertEquals(Family.objects.count(), 1)
self.assertEquals(family.case.id, case.id)
class TestIndividual(TestCase):
"""Basic tests for the ``Individual`` model and manager."""
def testCreate(self):
self.assertEquals(Family.objects.count(), 0)
self.assertEquals(Individual.objects.count(), 0)
IndividualFactory()
self.assertEquals(Family.objects.count(), 1)
self.assertEquals(Individual.objects.count(), 1)
def testGetOrCreateInProjectByCaseName(self):
case = CaseFactory()
self.assertEquals(Family.objects.count(), 0)
indiv = Individual.objects.get_or_create_in_project(
project=case.project, name=case.pedigree[0]["patient"], case_name=case.name
)
self.assertEquals(Family.objects.count(), 1)
self.assertEquals(indiv.family.case.id, case.id)
def testGetOrCreateInProjectByCaseNameFails(self):
case = CaseFactory()
self.assertEquals(Family.objects.count(), 0)
with self.assertRaises(Case.DoesNotExist):
Individual.objects.get_or_create_in_project(
project=case.project, name=case.pedigree[0]["patient"], case_name=case.name + "_"
)
self.assertEquals(Family.objects.count(), 0)
def testGetOrCreateInProjectByCase(self):
case = CaseFactory()
self.assertEquals(Family.objects.count(), 0)
indiv = Individual.objects.get_or_create_in_project(
project=case.project, name=case.pedigree[0]["patient"], case=case
)
self.assertEquals(Family.objects.count(), 1)
self.assertEquals(indiv.family.case.id, case.id)
def testGetOrCreateInProjectByFamily(self):
family = FamilyFactory()
self.assertEquals(Family.objects.count(), 1)
indiv = Individual.objects.get_or_create_in_project(
project=family.project, name=family.case.pedigree[0]["patient"], family=family
)
self.assertEquals(Family.objects.count(), 1)
self.assertEquals(indiv.family.id, family.id)
class TestAssertionMethod(TestCase):
"""Basic tests for ``AssertionMethod``"""
def testCreate(self):
self.assertEquals(AssertionMethod.objects.count(), 1)
AssertionMethodFactory()
self.assertEquals(AssertionMethod.objects.count(), 2)
class TestSubmitter(TestCase):
"""Basic tests for ``Submitter``"""
def testCreate(self):
self.assertEquals(Submitter.objects.count(), 1)
SubmitterFactory()
self.assertEquals(Submitter.objects.count(), 2)
class TestOrganisation(TestCase):
"""Basic tests for ``Organisation``"""
def testCreate(self):
self.assertEquals(Organisation.objects.count(), 2)
OrganisationFactory()
self.assertEquals(Organisation.objects.count(), 3)
class TestSubmissionSet(TestCase):
"""Basic tests for ``SubmissionSet``."""
def testCreate(self):
self.assertEquals(SubmissionSet.objects.count(), 0)
SubmissionSetFactory()
self.assertEquals(SubmissionSet.objects.count(), 1)
class TestSubmittingOrg(TestCase):
"""Basic tests for ``SubmittingOrg``."""
def testCreate(self):
self.assertEquals(SubmittingOrg.objects.count(), 0)
SubmittingOrgFactory()
self.assertEquals(SubmittingOrg.objects.count(), 1)
class TestSubmission(TestCase):
"""Basic tests for ``Submission``."""
def testCreate(self):
self.assertEquals(Submission.objects.count(), 0)
SubmissionFactory()
self.assertEquals(Submission.objects.count(), 1)
class TestUpdateIndividualSexAffectedTask(TestCase):
"""Test the task that updates the sex/affected of ``Individual`` records from upstream case."""
def testRun(self):
individual = IndividualFactory(sex="male", affected="yes")
individual.sex = "unknown"
individual.affected = "unknown"
individual.save()
self.assertEquals(individual.sex, "unknown")
self.assertEquals(individual.sex, "unknown")
refresh_individual_sex_affected()
individual.refresh_from_db()
self.assertEquals(individual.sex, "male")
self.assertEquals(individual.affected, "yes")