9e8a2a33d7fe67e22f7f5ade9efd84210dc16acc
[htsworkflow.git] / htsworkflow / frontend / samples / tests.py
1 import datetime
2 import unittest
3 from htsworkflow.frontend.samples.models import \
4         Affiliation, \
5         ExperimentType, \
6         Species, \
7         Library
8
9 # The django test runner flushes the database between test suites not cases,
10 # so to be more compatible with running via nose we flush the database tables
11 # of interest before creating our sample data.
12 def create_db(obj):
13     Species.objects.all().delete()
14     obj.species_human = Species(
15         scientific_name = 'Homo Sapeins',
16         common_name = 'human',
17     )
18     obj.species_human.save()
19     obj.species_worm = Species(
20         scientific_name = 'C. Elegans',
21         common_name = 'worm',
22     )
23     obj.species_worm.save()
24     obj.species_phix = Species(
25         scientific_name = 'PhiX',
26         common_name = 'PhiX'
27     )
28     obj.species_phix.save()
29
30     ExperimentType.objects.all().delete()
31     obj.experiment_de_novo = ExperimentType(
32         name = 'De Novo',
33     )
34     obj.experiment_de_novo.save()
35     obj.experiment_chip_seq = ExperimentType(
36         name = 'ChIP-Seq'
37     )
38     obj.experiment_chip_seq.save()
39     obj.experiment_rna_seq = ExperimentType(
40         name = 'RNA-Seq'
41     )
42     obj.experiment_rna_seq.save()
43
44     Affiliation.objects.all().delete()
45     obj.affiliation_alice = Affiliation(
46         name = 'Alice',
47         contact = 'Lab Boss',
48         email = 'alice@some.where.else.'
49     )
50     obj.affiliation_alice.save()
51     obj.affiliation_bob = Affiliation(
52         name = 'Bob',
53         contact = 'Other Lab Boss',
54         email = 'bob@some.where.else',
55     )
56     obj.affiliation_bob.save()
57
58     Library.objects.all().delete()
59     obj.library_10001 = Library(
60         library_id = 10001,
61         library_name = 'C2C12 named poorly',
62         library_species = obj.species_human,
63         experiment_type = obj.experiment_rna_seq,
64         creation_date = datetime.datetime.now(),
65         made_for = 'scientist unit 2007',
66         made_by = 'microfludics system 7321',
67         stopping_point = '2A',
68         undiluted_concentration = '5.01',
69     )
70     obj.library_10001.save()
71     obj.library_10002 = Library(
72         library_id = 10002,
73         library_name = 'Worm named poorly',
74         library_species = obj.species_human,
75         experiment_type = obj.experiment_rna_seq,
76         creation_date = datetime.datetime.now(),
77         made_for = 'scientist unit 2007',
78         made_by = 'microfludics system 7321',
79         stopping_point = '2A',
80         undiluted_concentration = '5.01',
81     )
82     obj.library_10002.save()
83  
84 class LibraryTestCase(unittest.TestCase):
85     def setUp(self):
86         create_db(self)
87                
88     def testOrganism(self):
89         self.assertEquals(self.library_10001.organism(), 'human')
90
91     def testAffiliations(self):
92         self.library_10001.affiliations.add(self.affiliation_alice)
93         self.library_10002.affiliations.add(
94                 self.affiliation_alice, 
95                 self.affiliation_bob
96         )
97         self.failUnless(len(self.library_10001.affiliations.all()), 1)
98         self.failUnless(self.library_10001.affiliation(), 'Alice')
99
100         self.failUnless(len(self.library_10002.affiliations.all()), 2)
101         self.failUnless(self.library_10001.affiliation(), 'Alice, Bob')
102