4 from django.test import TestCase
5 from django.contrib.auth.models import User
6 from django.core import urlresolvers
8 from htsworkflow.frontend.inventory.models import Item, Vendor
9 from htsworkflow.util.rdfhelp import get_model, load_string_into_model, get_serializer, inventoryOntology, libraryOntology, fromTypedNode
11 def localhostNode(url):
12 return RDF.Node(RDF.Uri('http://localhost%s' % (url,)))
14 class InventoryTestCase(TestCase):
15 fixtures = ['test_user', 'test_harddisks']
17 def test_fixture(self):
18 # make sure that some of our test data is was loaded
19 # since there was no error message when I typoed the test fixture
20 hd1 = Item.objects.get(pk=1)
21 self.failUnlessEqual(hd1.uuid, '8a90b6ce522311de99b00015172ce556')
23 user = User.objects.get(pk=5)
24 self.failUnlessEqual(user.username, 'test')
27 url = '/inventory/8a90b6ce522311de99b00015172ce556/'
28 self.client.login(username='test', password='BJOKL5kAj6aFZ6A5')
29 response = self.client.get(url)
30 self.failUnlessEqual(response.status_code, 200)
33 load_string_into_model(model, 'rdfa', response.content, url)
35 itemNode = RDF.Node(RDF.Uri(url))
36 item_type = fromTypedNode(model.get_target(itemNode, inventoryOntology['item_type']))
37 self.failUnlessEqual(item_type, u'Hard Drive')
39 def test_itemindex(self):
40 url = '/inventory/it/Hard Drive/'
41 indexNode = localhostNode(url)
42 diskNode = localhostNode('/inventory/8a90b6ce522311de99b00015172ce556/')
43 self.client.login(username='test', password='BJOKL5kAj6aFZ6A5')
45 flowcells = self.get_flowcells_from_content(url, indexNode, diskNode)
46 self.failUnlessEqual(len(flowcells), 2)
47 self.failUnless('http://localhost/flowcell/11ONEAAXX/' in flowcells)
48 self.failUnless('http://localhost/flowcell/22TWOAAXX/' in flowcells)
50 def test_add_disk(self):
51 url = '/inventory/it/Hard Drive/'
52 #url_disk = '/inventory/8a90b6ce522311de99b00015172ce556/'
53 url_disk = '/inventory/b0792d425aa411de99b00015172ce556/'
54 indexNode = localhostNode(url)
55 diskNode = localhostNode(url_disk)
56 self.client.login(username='test', password='BJOKL5kAj6aFZ6A5')
58 flowcells = self.get_flowcells_from_content(url, indexNode, diskNode)
59 self.failUnlessEqual(len(flowcells), 0)
61 # step two link the flowcell
62 flowcell = '22TWOAAXX'
63 serial = 'WCAU49042470'
64 link_url = urlresolvers.reverse(
65 'htsworkflow.frontend.inventory.views.link_flowcell_and_device',
66 args=(flowcell, serial))
67 link_response = self.client.get(link_url)
68 self.failUnlessEqual(link_response.status_code, 200)
70 flowcells = self.get_flowcells_from_content(url, indexNode, diskNode)
71 self.failUnlessEqual(len(flowcells), 1)
72 self.failUnlessEqual('http://localhost/flowcell/%s/' % (flowcell),
75 def test_add_disk_failed_flowcell(self):
76 url = '/inventory/it/Hard Drive/'
77 #url_disk = '/inventory/8a90b6ce522311de99b00015172ce556/'
78 url_disk = '/inventory/b0792d425aa411de99b00015172ce556/'
79 indexNode = localhostNode(url)
80 diskNode = localhostNode(url_disk)
81 self.client.login(username='test', password='BJOKL5kAj6aFZ6A5')
83 flowcells = self.get_flowcells_from_content(url, indexNode, diskNode)
84 self.failUnlessEqual(len(flowcells), 0)
86 # step two link the flowcell
87 flowcell = '33THRAAXX'
88 serial = 'WCAU49042470'
89 link_url = urlresolvers.reverse(
90 'htsworkflow.frontend.inventory.views.link_flowcell_and_device',
91 args=(flowcell, serial))
92 link_response = self.client.get(link_url)
93 self.failUnlessEqual(link_response.status_code, 200)
95 flowcells = self.get_flowcells_from_content(url, indexNode, diskNode)
96 self.failUnlessEqual(len(flowcells), 1)
97 self.failUnlessEqual('http://localhost/flowcell/%s/' % (flowcell),
101 def get_flowcells_from_content(self, url, rootNode, diskNode):
104 response = self.client.get(url)
105 self.failUnlessEqual(response.status_code, 200)
107 load_string_into_model(model, 'rdfa', response.content, rootNode.uri)
108 targets = model.get_targets(diskNode, libraryOntology['flowcell_id'])
109 flowcells = [ str(x.uri) for x in targets]
113 return unittest.makeSuite(InventoryTestCase, 'test')
115 if __name__ == "__main__":
116 unittest.main(defaultTest="suite")