Passed
Pull Request — master (#72)
by Paolo
16:34
created

uid.tests.test_models   C

Complexity

Total Complexity 54

Size/Duplication

Total Lines 760
Duplicated Lines 4.21 %

Importance

Changes 0
Metric Value
wmc 54
eloc 406
dl 32
loc 760
rs 6.4799
c 0
b 0
f 0

51 Methods

Rating   Name   Duplication   Size   Complexity  
A DictSexTestCase.test_str() 0 9 1
A SampleTestCase.test_to_biosample2() 0 23 1
A DictSpecieTestCase.setUp() 0 4 1
A SubmissionTestCase.test_error() 0 10 1
A SampleTestCase.test_to_biosample() 16 16 1
A DictSpecieTestCase.test_str() 0 9 1
A SampleTestCase.test_waiting() 0 10 1
A SampleTestCase.test_error() 0 10 1
A DictCountryTestCase.setUp() 0 4 1
A SampleTestCase.test_uid_report() 0 25 1
A DictSpecieTestCase.test_get_specie_by_synonym() 0 17 2
A SampleTestCase.test_loaded() 0 10 1
A PersonTestCase.setUp() 0 3 1
A AnimalTestCase.test_to_biosample() 16 16 1
A SubmissionTestCase.test_loaded() 0 10 1
A SampleTestCase.test_to_biosample_no_foreign() 0 27 3
A DictSpecieTestCase.test_missing_taxon() 0 6 1
A SubmissionTestCase.test_submitted() 0 10 1
A SubmissionTestCase.setUp() 0 2 1
A PersonTestCase.test_str() 0 6 1
A AnimalTestCase.test_ready() 0 10 1
A AnimalTestCase.test_loaded() 0 10 1
A AnimalTestCase.test_relationship() 0 42 1
A AnimalTestCase.test_need_revision() 0 10 1
A AnimalTestCase.test_waiting() 0 10 1
A DictSpecieTestCase.test_get_specie_check_synonyms() 0 19 1
A DictBreedTestCase.test_get_no_mapped_breed() 0 9 1
A DictCountryTestCase.test_str() 0 9 1
A DictSpecieTestCase.test_get_specie_by_synonym_nospaces() 0 14 1
A SubmissionTestCase.test_waiting() 0 10 1
A AnimalTestCase.test_completed() 0 10 1
A DictBreedTestCase.test_default_mapped_breed() 0 12 1
A SampleTestCase.test_need_revision() 0 10 1
A SampleTestCase.setUp() 0 9 1
A SubmissionTestCase.test_ready() 0 10 1
A SubmissionTestCase.test_str() 0 5 1
A AnimalTestCase.setUp() 0 4 1
A AnimalTestCase.test_to_biosample2() 0 12 1
A SampleTestCase.test_ready() 0 10 1
A SampleTestCase.test_submitted() 0 10 1
A DictSexTestCase.test_format_attribute_default() 0 15 1
A SubmissionTestCase.test_completed() 0 10 1
A DictSexTestCase.setUp() 0 4 1
A SubmissionTestCase.test_need_revision() 0 10 1
A SampleTestCase.test_completed() 0 10 1
A SampleTestCase.test_related_object() 0 7 1
A SampleTestCase.test_uid_has_data() 0 4 1
A AnimalTestCase.test_submitted() 0 10 1
A AnimalTestCase.test_error() 0 10 1
A DictBreedTestCase.test_str() 0 13 1
A DictSexTestCase.test_format_attribute() 0 14 1

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complexity

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like uid.tests.test_models often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

1
#!/usr/bin/env python3
2
# -*- coding: utf-8 -*-
3
"""
4
Created on Tue Apr  3 12:16:55 2018
5
6
@author: Paolo Cozzi <[email protected]>
7
"""
8
9
import os
10
import json
11
12
from django.test import TestCase
13
from django.utils import timezone
14
15
from common.constants import OBO_URL
16
from common.helpers import get_deleted_objects
17
from common.tests import PersonMixinTestCase
18
from common.constants import (
19
    WAITING, LOADED, ERROR, READY, NEED_REVISION, SUBMITTED, COMPLETED)
20
21
from uid.models import (
22
    Animal, Submission, DictBreed, DictCountry,
23
    DictSex, DictSpecie, Sample, uid_report, Person, User, db_has_data)
24
25
26
class DictSexTestCase(TestCase):
27
    """Testing DictSex class"""
28
29
    fixtures = [
30
        "uid/dictsex",
31
        "uid/ontology"
32
    ]
33
34
    def setUp(self):
35
        # my attributes
36
        self.label = 'male'
37
        self.term = 'PATO_0000384'
38
39
    def test_str(self):
40
        """Testing str representation"""
41
42
        male = DictSex.objects.get(label=self.label)
43
        self.assertEqual(
44
                str(male),
45
                "{label} ({term})".format(
46
                        label=self.label,
47
                        term=self.term))
48
49
    def test_format_attribute(self):
50
        """Testing format attribute"""
51
52
        reference = [{
53
            "value": "male",
54
            "terms": [{
55
                "url": "%s/PATO_0000384" % (OBO_URL)
56
             }]
57
        }]
58
59
        male = DictSex.objects.get(label=self.label)
60
        test = male.format_attribute()
61
62
        self.assertEqual(reference, test)
63
64
    def test_format_attribute_default(self):
65
        """Testing format attribute with no library_uri"""
66
67
        reference = [{
68
            "value": "male",
69
            "terms": [{
70
                "url": "%s/PATO_0000384" % (OBO_URL)
71
             }]
72
        }]
73
74
        male = DictSex.objects.get(label=self.label)
75
        male.library_name = None
76
        test = male.format_attribute()
77
78
        self.assertEqual(reference, test)
79
80
81
class DictSpecieTestCase(TestCase):
82
    """Testing DictSpecie class"""
83
84
    fixtures = [
85
        'uid/dictcountry',
86
        'uid/dictspecie',
87
        'uid/ontology',
88
        'uid/speciesynonym'
89
    ]
90
91
    def setUp(self):
92
        # my attributes
93
        self.label = 'Sus scrofa'
94
        self.term = 'NCBITaxon_9823'
95
96
    def test_str(self):
97
        """Testing str representation"""
98
99
        sus = DictSpecie.objects.get(label=self.label)
100
        self.assertEqual(
101
                str(sus),
102
                "{label} ({term})".format(
103
                        label=self.label,
104
                        term=self.term))
105
106
    def test_missing_taxon(self):
107
        """test no term returns no taxon"""
108
109
        sus = DictSpecie.objects.get(label=self.label)
110
        sus.term = None
111
        self.assertIsNone(sus.taxon_id)
112
113
    def test_get_specie_by_synonym(self):
114
        """Getting specie using synonym"""
115
116
        sus = DictSpecie.get_by_synonym('Pig', 'United Kingdom')
117
118
        self.assertEqual(sus.label, self.label)
119
        self.assertEqual(sus.term, self.term)
120
121
        # assert a specie in a different language (synonym not defined)
122
        sus = DictSpecie.get_by_synonym('Pig', 'Italy')
123
124
        self.assertEqual(sus.label, self.label)
125
        self.assertEqual(sus.term, self.term)
126
127
        # using a word not registered returns no data
128
        with self.assertRaises(DictSpecie.DoesNotExist):
129
            DictSpecie.get_by_synonym('Foo', 'United Kingdom')
130
131
    def test_get_specie_by_synonym_nospaces(self):
132
        """Getting specie using synonym, no matters spaces"""
133
134
        # assert with spaces
135
        sus = DictSpecie.get_by_synonym('Pig (domestic)', 'United Kingdom')
136
137
        self.assertEqual(sus.label, self.label)
138
        self.assertEqual(sus.term, self.term)
139
140
        # assert without spaces
141
        sus = DictSpecie.get_by_synonym('Pig(domestic)', 'United Kingdom')
142
143
        self.assertEqual(sus.label, self.label)
144
        self.assertEqual(sus.term, self.term)
145
146
    def test_get_specie_check_synonyms(self):
147
        """Get the same specie from latin or dictionary table"""
148
149
        # get a country object
150
        language = DictCountry.objects.get(label="Italy")
151
152
        sus = DictSpecie.get_specie_check_synonyms(
153
            species_label=self.label,
154
            language=language)
155
156
        self.assertEqual(sus.label, self.label)
157
        self.assertEqual(sus.term, self.term)
158
159
        sus = DictSpecie.get_specie_check_synonyms(
160
            species_label="Pig",
161
            language=language)
162
163
        self.assertEqual(sus.label, self.label)
164
        self.assertEqual(sus.term, self.term)
165
166
167
class DictCountryTestCase(TestCase):
168
    """Testing DictCountry class"""
169
170
    fixtures = [
171
        "uid/dictcountry",
172
        "uid/ontology"
173
    ]
174
175
    def setUp(self):
176
        # my attributes
177
        self.label = 'United Kingdom'
178
        self.term = 'NCIT_C17233'
179
180
    def test_str(self):
181
        """Testing str representation"""
182
183
        uk = DictCountry.objects.get(label=self.label)
184
        self.assertEqual(
185
                str(uk),
186
                "{label} ({term})".format(
187
                        label=self.label,
188
                        term=self.term))
189
190
191
class DictBreedTestCase(TestCase):
192
    """Testing DictBreed class"""
193
194
    fixtures = [
195
        "uid/dictbreed",
196
        "uid/dictcountry",
197
        "uid/dictspecie",
198
        "uid/ontology"
199
    ]
200
201
    def test_str(self):
202
        """Testing str representation (as mapped_breed, if present)"""
203
204
        breed = DictBreed.objects.get(pk=1)
205
        self.assertEqual(
206
            str(breed),
207
            "Bunte Bentheimer (Bentheim Black Pied, Sus scrofa)")
208
209
        # unset mapped_breed
210
        breed.mapped_breed = None
211
        breed.mapped_breed_term = None
212
        self.assertEqual(
213
            str(breed), "Bunte Bentheimer (pig breed, Sus scrofa)")
214
215
    def test_default_mapped_breed(self):
216
        """Test mapped breed returns specie.label if no mapping occours"""
217
218
        breed = DictBreed.objects.get(pk=1)
219
        self.assertEqual(breed.mapped_breed, "Bentheim Black Pied")
220
        self.assertEqual(breed.mapped_breed_term, "LBO_0000347")
221
222
        # unset mapped_breed
223
        breed.mapped_breed = None
224
        breed.mapped_breed_term = None
225
        self.assertEqual(breed.mapped_breed, "pig breed")
226
        self.assertEqual(breed.mapped_breed_term, "LBO_0000003")
227
228
    def test_get_no_mapped_breed(self):
229
        """Test with a specie not defined in get_general_breed_by_species"""
230
231
        specie = DictSpecie(label='Anser anser', term="NCBITaxon_8843")
232
        breed = DictBreed(specie=specie, supplied_breed='Anser anser')
233
234
        self.assertIsNone(breed.mapped_breed)
235
        self.assertIsNone(breed.mapped_breed_term)
236
        self.assertIsNone(breed.format_attribute())
237
238
239
class SubmissionTestCase(TestCase):
240
    """Testing Submission class"""
241
242
    fixtures = [
243
        'uid/dictcountry',
244
        'uid/dictrole',
245
        'uid/ontology',
246
        'uid/organization',
247
        'uid/submission',
248
        'uid/user'
249
    ]
250
251
    def setUp(self):
252
        self.submission = Submission.objects.get(pk=1)
253
254
    def test_str(self):
255
        test = str(self.submission)
256
        reference = "Cryoweb (United Kingdom, test)"
257
258
        self.assertEqual(reference, test)
259
260
    def test_waiting(self):
261
        """Test waiting status"""
262
263
        # force submission status
264
        self.submission.status = WAITING
265
266
        # test my helper methods
267
        self.assertFalse(self.submission.can_edit())
268
        self.assertFalse(self.submission.can_validate())
269
        self.assertFalse(self.submission.can_submit())
270
271
    def test_loaded(self):
272
        """Test loaded status"""
273
274
        # force submission status
275
        self.submission.status = LOADED
276
277
        # test my helper methods
278
        self.assertTrue(self.submission.can_edit())
279
        self.assertTrue(self.submission.can_validate())
280
        self.assertFalse(self.submission.can_submit())
281
282
    def test_submitted(self):
283
        """Test submitted status"""
284
285
        # force submission status
286
        self.submission.status = SUBMITTED
287
288
        # test my helper methods
289
        self.assertFalse(self.submission.can_edit())
290
        self.assertFalse(self.submission.can_validate())
291
        self.assertFalse(self.submission.can_submit())
292
293
    def test_error(self):
294
        """Test error status"""
295
296
        # force submission status
297
        self.submission.status = ERROR
298
299
        # test my helper methods
300
        self.assertTrue(self.submission.can_edit())
301
        self.assertFalse(self.submission.can_validate())
302
        self.assertFalse(self.submission.can_submit())
303
304
    def test_need_revision(self):
305
        """Test need_revision status"""
306
307
        # force submission status
308
        self.submission.status = NEED_REVISION
309
310
        # test my helper methods
311
        self.assertTrue(self.submission.can_edit())
312
        self.assertTrue(self.submission.can_validate())
313
        self.assertFalse(self.submission.can_submit())
314
315
    def test_ready(self):
316
        """Test ready status"""
317
318
        # force submission status
319
        self.submission.status = READY
320
321
        # test my helper methods
322
        self.assertTrue(self.submission.can_edit())
323
        self.assertTrue(self.submission.can_validate())
324
        self.assertTrue(self.submission.can_submit())
325
326
    def test_completed(self):
327
        """Test completed status"""
328
329
        # force submission status
330
        self.submission.status = COMPLETED
331
332
        # test my helper methods
333
        self.assertTrue(self.submission.can_edit())
334
        self.assertFalse(self.submission.can_validate())
335
        self.assertFalse(self.submission.can_submit())
336
337
338
class AnimalTestCase(PersonMixinTestCase, TestCase):
339
    """Testing Animal Class"""
340
341
    # an attribute for PersonMixinTestCase
342
    person = Person
343
344
    fixtures = [
345
        'uid/animal',
346
        'uid/dictbreed',
347
        'uid/dictcountry',
348
        'uid/dictrole',
349
        'uid/dictsex',
350
        'uid/dictspecie',
351
        'uid/ontology',
352
        'uid/organization',
353
        'uid/publication',
354
        'uid/submission',
355
        'uid/user'
356
    ]
357
358
    def setUp(self):
359
        # create animal
360
        self.animal = Animal.objects.get(pk=1)
361
        self.submission = self.animal.submission
362
363 View Code Duplication
    def test_to_biosample(self):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
364
        """Testing JSON conversion for biosample submission"""
365
366
        base_dir = os.path.dirname(os.path.abspath(__file__))
367
        file_path = os.path.join(base_dir, "biosample_animal.json")
368
        handle = open(file_path)
369
        reference = json.load(handle)
370
371
        # fix release date to today
372
        now = timezone.now()
373
        reference['releaseDate'] = str(now.date())
374
375
        test = self.animal.to_biosample()
376
377
        self.maxDiff = None
378
        self.assertEqual(reference, test)
379
380
    def test_to_biosample2(self):
381
        """testing json conversion with a biosample_id"""
382
383
        # assign a different biosample id
384
        reference = "SAMEA4450079"
385
        self.animal.biosample_id = reference
386
        self.animal.save()
387
388
        test = self.animal.to_biosample()
389
390
        # asserting biosample_.id in response
391
        self.assertEqual(test["accession"], reference)
392
393
    def test_relationship(self):
394
        """Testing an animal who has mother and father"""
395
396
        animal = Animal.objects.get(pk=3)
397
398
        test = animal.to_biosample()
399
400
        reference = [
401
            {'alias': 'IMAGEA000000001',
402
             'relationshipNature': 'derived from'},
403
            {'alias': 'IMAGEA000000002',
404
             'relationshipNature': 'derived from'}
405
        ]
406
407
        # asserting relationship
408
        self.assertEqual(test['sampleRelationships'], reference)
409
410
        # cleaning up relationship (by erasing fk - as crbanim data could be)
411
        # erase father relationship
412
        animal.father = None
413
        animal.save()
414
415
        test = animal.to_biosample()
416
417
        reference = [
418
            {'alias': 'IMAGEA000000002',
419
             'relationshipNature': 'derived from'},
420
        ]
421
422
        # asserting relationship
423
        self.assertEqual(test['sampleRelationships'], reference)
424
425
        # cleaning up last relationship
426
        animal.mother = None
427
        animal.save()
428
429
        test = animal.to_biosample()
430
431
        reference = []
432
433
        # asserting relationship
434
        self.assertEqual(test['sampleRelationships'], reference)
435
436
    # TODO: test None rendering
437
438
    def test_waiting(self):
439
        """Test waiting status"""
440
441
        # force submission status
442
        self.submission.status = WAITING
443
        self.submission.save()
444
445
        # test my helper methods
446
        self.assertFalse(self.animal.can_delete())
447
        self.assertFalse(self.animal.can_edit())
448
449
    def test_loaded(self):
450
        """Test loaded status"""
451
452
        # force submission status
453
        self.submission.status = LOADED
454
        self.submission.save()
455
456
        # test my helper methods
457
        self.assertTrue(self.animal.can_delete())
458
        self.assertTrue(self.animal.can_edit())
459
460
    def test_submitted(self):
461
        """Test submitted status"""
462
463
        # force submission status
464
        self.submission.status = SUBMITTED
465
        self.submission.save()
466
467
        # test my helper methods
468
        self.assertFalse(self.animal.can_delete())
469
        self.assertFalse(self.animal.can_edit())
470
471
    def test_error(self):
472
        """Test error status"""
473
474
        # force submission status
475
        self.submission.status = ERROR
476
        self.submission.save()
477
478
        # test my helper methods
479
        self.assertTrue(self.animal.can_delete())
480
        self.assertTrue(self.animal.can_edit())
481
482
    def test_need_revision(self):
483
        """Test need_revision status"""
484
485
        # force submission status
486
        self.submission.status = NEED_REVISION
487
        self.submission.save()
488
489
        # test my helper methods
490
        self.assertTrue(self.animal.can_delete())
491
        self.assertTrue(self.animal.can_edit())
492
493
    def test_ready(self):
494
        """Test ready status"""
495
496
        # force submission status
497
        self.submission.status = READY
498
        self.submission.save()
499
500
        # test my helper methods
501
        self.assertTrue(self.animal.can_delete())
502
        self.assertTrue(self.animal.can_edit())
503
504
    def test_completed(self):
505
        """Test completed status"""
506
507
        # force submission status
508
        self.submission.status = COMPLETED
509
        self.submission.save()
510
511
        # test my helper methods
512
        self.assertTrue(self.animal.can_delete())
513
        self.assertTrue(self.animal.can_edit())
514
515
516
class SampleTestCase(PersonMixinTestCase, TestCase):
517
    """testing sample class"""
518
519
    # an attribute for PersonMixinTestCase
520
    person = Person
521
522
    fixtures = [
523
        'uid/animal',
524
        'uid/dictbreed',
525
        'uid/dictcountry',
526
        'uid/dictrole',
527
        'uid/dictsex',
528
        'uid/dictspecie',
529
        'uid/dictstage',
530
        'uid/dictuberon',
531
        'uid/ontology',
532
        'uid/organization',
533
        'uid/publication',
534
        'uid/sample',
535
        'uid/submission',
536
        'uid/user'
537
    ]
538
539
    def setUp(self):
540
        # create animal
541
        self.animal = Animal.objects.get(pk=1)
542
543
        # now get a sample object
544
        self.sample = Sample.objects.get(pk=1)
545
546
        # set submission
547
        self.submission = self.sample.submission
548
549 View Code Duplication
    def test_to_biosample(self):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
550
        """Testing JSON conversion for biosample submission"""
551
552
        base_dir = os.path.dirname(os.path.abspath(__file__))
553
        file_path = os.path.join(base_dir, "biosample_sample.json")
554
        handle = open(file_path)
555
        reference = json.load(handle)
556
557
        # fix release date to today
558
        now = timezone.now()
559
        reference['releaseDate'] = str(now.date())
560
561
        test = self.sample.to_biosample()
562
563
        self.maxDiff = None
564
        self.assertEqual(reference, test)
565
566
    def test_to_biosample2(self):
567
        """testing json conversion with a biosample_id"""
568
569
        # assign a different biosample id
570
        animal_reference = "SAMEA4450079"
571
        self.animal.biosample_id = animal_reference
572
        self.animal.save()
573
574
        sample_reference = "SAMEA4450075"
575
        self.sample.biosample_id = sample_reference
576
        self.sample.save()
577
578
        test = self.sample.to_biosample()
579
580
        # asserting biosample_.id in response
581
        self.assertEqual(test["accession"], sample_reference)
582
583
        # asserting animal biosample_id in relatioship
584
        reference = [{
585
            "accession": animal_reference,
586
            "relationshipNature": "derived from",
587
        }]
588
        self.assertEqual(test['sampleRelationships'], reference)
589
590
    def test_to_biosample_no_foreign(self):
591
        """Testing JSON conversion for biosample submission without
592
        foreign keys"""
593
594
        base_dir = os.path.dirname(os.path.abspath(__file__))
595
        file_path = os.path.join(base_dir, "biosample_sample.json")
596
        handle = open(file_path)
597
        reference = json.load(handle)
598
599
        # fix release date to today
600
        now = timezone.now()
601
        reference['releaseDate'] = str(now.date())
602
603
        # remove foreign keys from reference
604
        for key in ["Organism part", "Developmental stage"]:
605
            if key in reference["attributes"]:
606
                del(reference["attributes"][key])
607
608
        # remove foreing keys from sample object
609
        self.sample.organism_part = None
610
        self.sample.developmental_stage = None
611
        self.sample.save()
612
613
        test = self.sample.to_biosample()
614
615
        self.maxDiff = None
616
        self.assertEqual(reference, test)
617
618
    # TODO: test biosample with None rendering
619
620
    def test_related_object(self):
621
        """Testing relationship using get_deleted_objects"""
622
623
        deletable_objects, model_count, protected = get_deleted_objects(
624
            [self.animal])
625
626
        self.assertEqual(model_count, {'animals': 2, 'samples': 1})
627
628
    def test_uid_report(self):
629
        """testing uid report after a Sample and Animal insert"""
630
631
        reference = {
632
                'n_of_animals': 3,
633
                'n_of_samples': 1,
634
                'breeds_total': 1,
635
                'breeds_without_ontology': 0,
636
                'countries_total': 3,
637
                'countries_without_ontology': 0,
638
                'species_total': 1,
639
                'species_without_ontology': 0,
640
                'developmental_stages_total': 1,
641
                'developmental_stages_without_ontology': 0,
642
                'organism_parts_total': 1,
643
                'organism_parts_without_ontology': 0,
644
                'physiological_stages_total': 1,
645
                'physiological_stages_without_ontology': 0,
646
                }
647
648
        user = User.objects.get(pk=1)
649
650
        test = uid_report(user)
651
652
        self.assertEqual(reference, test)
653
654
    def test_uid_has_data(self):
655
        """testing db_has_data for uid"""
656
657
        self.assertTrue(db_has_data())
658
659
    def test_waiting(self):
660
        """Test waiting status"""
661
662
        # force submission status
663
        self.submission.status = WAITING
664
        self.submission.save()
665
666
        # test my helper methods
667
        self.assertFalse(self.sample.can_delete())
668
        self.assertFalse(self.sample.can_edit())
669
670
    def test_loaded(self):
671
        """Test loaded status"""
672
673
        # force submission status
674
        self.submission.status = LOADED
675
        self.submission.save()
676
677
        # test my helper methods
678
        self.assertTrue(self.sample.can_delete())
679
        self.assertTrue(self.sample.can_edit())
680
681
    def test_submitted(self):
682
        """Test submitted status"""
683
684
        # force submission status
685
        self.submission.status = SUBMITTED
686
        self.submission.save()
687
688
        # test my helper methods
689
        self.assertFalse(self.sample.can_delete())
690
        self.assertFalse(self.sample.can_edit())
691
692
    def test_error(self):
693
        """Test error status"""
694
695
        # force submission status
696
        self.submission.status = ERROR
697
        self.submission.save()
698
699
        # test my helper methods
700
        self.assertTrue(self.sample.can_delete())
701
        self.assertTrue(self.sample.can_edit())
702
703
    def test_need_revision(self):
704
        """Test need_revision status"""
705
706
        # force submission status
707
        self.submission.status = NEED_REVISION
708
        self.submission.save()
709
710
        # test my helper methods
711
        self.assertTrue(self.sample.can_delete())
712
        self.assertTrue(self.sample.can_edit())
713
714
    def test_ready(self):
715
        """Test ready status"""
716
717
        # force submission status
718
        self.submission.status = READY
719
        self.submission.save()
720
721
        # test my helper methods
722
        self.assertTrue(self.sample.can_delete())
723
        self.assertTrue(self.sample.can_edit())
724
725
    def test_completed(self):
726
        """Test completed status"""
727
728
        # force submission status
729
        self.submission.status = COMPLETED
730
        self.submission.save()
731
732
        # test my helper methods
733
        self.assertTrue(self.sample.can_delete())
734
        self.assertTrue(self.sample.can_edit())
735
736
737
class PersonTestCase(PersonMixinTestCase, TestCase):
738
    """Testing Person Class"""
739
740
    # an attribute for PersonMixinTestCase
741
    person = Person
742
743
    fixtures = [
744
        'uid/dictcountry',
745
        'uid/dictrole',
746
        'uid/organization',
747
        'uid/user'
748
    ]
749
750
    def setUp(self):
751
        # get a person
752
        self.person = Person.objects.get(user__id=1)
753
754
    def test_str(self):
755
        """test a repr method"""
756
757
        test = str(self.person)
758
        self.assertEqual(
759
            test, "Foo Bar (Test organization (United Kingdom))")
760