class TemplateTagsTestCase(TestCase): def setUp(self): self.m1 = Machine(url='http://dspace.wrlc.org', name='DSpace Server') self.m1.save() self.m2 = Machine(url='dspace.wrlc.org', name='Backup DSpace Server') self.m2.save() self.collection = Collection(id='testcoll', name='TestCollection') self.collection.save() self.project = Project(id='testproj', name='TestProject', collection=self.collection) self.project.save() self.item = Item(id='testItem', title='TestItem', collection=self.collection, project=self.project) self.item.save() self.bag1 = Bag(bagname='testBag1', item=self.item, machine=self.m1, bag_type='1', absolute_filesystem_path='/tmp/fakebag') self.bag1.payload = """/data/METADATA/0123456789-dc.xml 2655 /data/METADATA/0123456789-MRC.xml 3256 /data/IMAGES/0123456789_pg1.jp2 1778740 /data/IMAGES/0123456789_pg2.jp2 1878756 /data/IMAGES/0123456789_pg3.jp2 1915879 /data/IMAGES/0123456789_pg1.tiff 1778740 /data/IMAGES/0123456789_pg2.tiff 1878756 /data/IMAGES/0123456789_pg3.tiff 1915879 """ self.bag1.save() self.bag2 = Bag(bagname='testBag2', item=self.item, machine=self.m2, bag_type='1', absolute_filesystem_path='/tmp/fakebag') self.bag2.payload = """/data/METADATA/0123456789-dc.xml 2655 /data/METADATA/0123456789-MRC.xml 3256 /data/IMAGES/0123456789_pg1.jp2 1778740 /data/IMAGES/0123456789_pg2.jp2 1878756 /data/IMAGES/0123456789_pg3.jp2 1915879 /data/IMAGES/0123456789_pg1.tiff 1778740 /data/IMAGES/0123456789_pg2.tiff 1878756 /data/IMAGES/0123456789_pg3.tiff 1915879 """ self.bag2.save() def test_urlize_with_label_templatetag(self): bag1_files = self.bag1.list_payload() bag1_url = invapp_extras.urlize_with_label( urlize(self.bag1.access_url() + bag1_files[0][0]), bag1_files[0][0]) self.assertEqual(bag1_url, '<a href="http://dspace.wrlc.org/tmp/' 'fakebag/data/METADATA/0123456789-dc.xml">' '/data/METADATA/0123456789-dc.xml</a>') bag2_files = self.bag2.list_payload() bag2_url = invapp_extras.urlize_with_label( urlize(self.bag2.access_url() + bag2_files[0][0]), bag2_files[0][0]) self.assertEqual(bag2_url, '/data/METADATA/0123456789-dc.xml')
def test_item_no_collection(self): item = Item( id='38989/123456789', title='Little Orphan Item', local_id='123456789', collection=None, project=None, created=now(), original_item_type='1', notes='', access_loc='', stats=None) item.save()
def setUp(self): machine = Machine(url='www.gwu.edu', name='CascadeTestMachine') machine.save() collection = Collection(id='CascColl', name='CascadeTestCollection') collection.save() project = Project(id='CascProj', name='CascadeTestProject', collection=collection) project.save() item = Item(id='CascItem', title='CascadeTestItem', collection=collection, project=project) item.save() bag = Bag(bagname='CascBag', item=item, machine=machine, bag_type='1') bag.save() action = BagAction(bag=bag, action='1') action.save()
def test_stats_on_empty_objects(self): expected = self.empty_stats c1 = Collection(id='nobagscollection', name='test-collection-2', created=now()) c1.save() self.assertTrue(utils.compare_dicts(c1.stats, expected)) p1 = Project(id='nobagsproject', name='test-project-2', collection=c1, created=now()) p1.save() self.assertTrue(utils.compare_dicts(p1.stats, expected)) i1 = Item(id='nobagsitem', title='test-item-1', project=p1, collection=c1, created=now(), original_item_type='1') i1.stats = i1.collect_stats() i1.save() p1.stats = p1.collect_stats() c1.stats = c1.collect_stats() self.assertTrue(utils.compare_dicts(i1.stats, expected)) self.assertTrue(utils.compare_dicts(p1.stats, expected)) self.assertTrue(utils.compare_dicts(c1.stats, expected))
def setUp(self): self.m1 = Machine(url='http://dspace.wrlc.org', name='DSpace Server') self.m1.save() self.m2 = Machine(url='dspace.wrlc.org', name='Backup DSpace Server') self.m2.save() self.collection = Collection(id='testcoll', name='TestCollection') self.collection.save() self.project = Project(id='testproj', name='TestProject', collection=self.collection) self.project.save() self.item = Item(id='testItem', title='TestItem', collection=self.collection, project=self.project) self.item.save() self.bag1 = Bag(bagname='testBag1', item=self.item, machine=self.m1, bag_type='1', absolute_filesystem_path='/tmp/fakebag') self.bag1.payload = """/data/METADATA/0123456789-dc.xml 2655 /data/METADATA/0123456789-MRC.xml 3256 /data/IMAGES/0123456789_pg1.jp2 1778740 /data/IMAGES/0123456789_pg2.jp2 1878756 /data/IMAGES/0123456789_pg3.jp2 1915879 /data/IMAGES/0123456789_pg1.tiff 1778740 /data/IMAGES/0123456789_pg2.tiff 1878756 /data/IMAGES/0123456789_pg3.tiff 1915879 """ self.bag1.save() self.bag2 = Bag(bagname='testBag2', item=self.item, machine=self.m2, bag_type='1', absolute_filesystem_path='/tmp/fakebag') self.bag2.payload = """/data/METADATA/0123456789-dc.xml 2655 /data/METADATA/0123456789-MRC.xml 3256 /data/IMAGES/0123456789_pg1.jp2 1778740 /data/IMAGES/0123456789_pg2.jp2 1878756 /data/IMAGES/0123456789_pg3.jp2 1915879 /data/IMAGES/0123456789_pg1.tiff 1778740 /data/IMAGES/0123456789_pg2.tiff 1878756 /data/IMAGES/0123456789_pg3.tiff 1915879 """ self.bag2.save()
def setUp(self): # set up hierarchy of fake objects for bag self.c1 = Collection(id='collection_1', name='test-collection-1', created=now()) self.c1.save() self.p1 = Project(id='project_1', name='test-project-1', collection=self.c1, created=now()) self.p1.save() self.i1 = Item(id='item_1', title='test-item-1', project=self.p1, created=now(), original_item_type='1') self.i1.save() self.m1 = Machine(name='test-machine-1', url='http://test.url.com', www_root='/bags/') self.m1.save() # load bag with raw data self.bag = Bag(bagname='test-bag-11', created=now(), item=self.i1, machine=self.m1, absolute_filesystem_path='/bags/partition1/test-bag-11', bag_type='1') self.bag.stats = self.bag.collect_stats() self.bag.save()
def test_auto_id_creation(self): # test collection c1 = Collection(name='Test Collection autoID') c1.save() self.assertTrue(c1.id) self.assertTrue(c1.created) # test project p1 = Project(name='Test Project autoID', collection=c1) p1.save() self.assertTrue(p1.id) self.assertTrue(p1.created) # test item i1 = Item(title='Test Item autoID', collection=c1, project=p1, original_item_type='1') i1.save() self.assertTrue(i1.id) self.assertTrue(i1.created) # test bag + machine m1 = Machine(name='test machine zzz', url='zzz.gwu.edu') m1.save() b1 = Bag(created=now(), item=i1, machine=m1, absolute_filesystem_path='blah/blah', bag_type='1') b1.save() # test copy numbers for duplicate bags b2 = Bag(created=now(), item=i1, machine=m1, absolute_filesystem_path='blah/blah', bag_type='1') b2.save() self.assertNotEqual(b1.bagname, b2.bagname) self.assertTrue(b1.bagname.endswith('1')) self.assertTrue(b2.bagname.endswith('2')) parts1 = b1.bagname.split('_') parts2 = b2.bagname.split('_') for x, val in enumerate(parts1): if x != len(parts1) - 1: self.assertEqual(val, parts2[x]) else: self.assertTrue(int(parts2[x]) - int(val) == 1) # make sure bagname does not contain forward slash i1.id = '12345/123456789' i1.save() b3 = Bag(created=now(), item=i1, machine=m1, absolute_filesystem_path='xxxx', bag_type='1') b3.save() self.assertFalse('/' in b3.bagname)
def test_pagination(self): self.maxDiff = None c1 = Collection(id='collection_1_1_1', name='test-collection-1', created=now()) c1.save() p1 = Project(id='project_1_1_1', name='test-project-1', collection=c1, created=now()) p1.save() i1 = Item(id='item_1_1_1', title='test-item-1', project=p1, collection=c1, created=now(), original_item_type='1') i1.save() m1 = Machine(name='test-machine-1', url='test-url-1') m1.save() b1 = Bag(bagname='test-bag-1', created=now(), item=i1, machine=m1, absolute_filesystem_path='test-path1', bag_type='1') b2 = Bag(bagname='test-bag-4', created=now(), item=i1, machine=m1, absolute_filesystem_path='test-path4', bag_type='1') b3 = Bag(bagname='test-bag-5', created=now(), item=i1, machine=m1, absolute_filesystem_path='test-path5', bag_type='1') b1.payload = '' b2.payload = '' b3.payload = '' for i in range(150): b1.payload += '/data/IMAGES/' + str(i) + '.jp2 ' + \ str(random.randrange(10000, 99999)) + '\n' if i < 70: b2.payload += '/data/IMAGES/' + str(i) + '.jp2' + \ str(random.randrange(10000, 99999)) + '\n' if i < 20: b3.payload += '/data/IMAGES/' + str(i) + '.jp2' + \ str(random.randrange(10000, 99999)) + '\n' b1_files = b1.list_payload() b2_files = b2.list_payload() b3_files = b3.list_payload() b1_paginator = Paginator(b1_files, 10) b2_paginator = Paginator(b2_files, 10) b3_paginator = Paginator(b3_files, 10) b1_files = b1_paginator.page(1) b2_files = b2_paginator.page(1) b3_files = b3_paginator.page(1) expected_b1 = list(range(13)) expected_b1[0] = {'disp': '<<', 'link': None, 'disabled': True} expected_b1[1] = {'disp': '1', 'link': '?files_page=1', 'disabled': True} expected_b1[2] = {'disp': '2', 'link': '?files_page=2', 'disabled': False} expected_b1[3] = {'disp': '3', 'link': '?files_page=3', 'disabled': False} expected_b1[4] = {'disp': '4', 'link': '?files_page=4', 'disabled': False} expected_b1[5] = {'disp': '5', 'link': '?files_page=5', 'disabled': False} expected_b1[6] = {'disp': '6', 'link': '?files_page=6', 'disabled': False} expected_b1[7] = {'disp': '7', 'link': '?files_page=7', 'disabled': False} expected_b1[8] = {'disp': '8', 'link': '?files_page=8', 'disabled': False} expected_b1[9] = {'disp': '9', 'link': '?files_page=9', 'disabled': False} expected_b1[10] = {'disp': '...', 'link': None, 'disabled': True} expected_b1[11] = {'disp': '15', 'link': '?files_page=15', 'disabled': False} expected_b1[12] = {'disp': '>>', 'link': '?files_page=2', 'disabled': False} expected_b2 = list(range(9)) expected_b2[0] = {'disp': '<<', 'link': None, 'disabled': True} expected_b2[1] = {'disp': '1', 'link': '?files_page=1', 'disabled': True} expected_b2[2] = {'disp': '2', 'link': '?files_page=2', 'disabled': False} expected_b2[3] = {'disp': '3', 'link': '?files_page=3', 'disabled': False} expected_b2[4] = {'disp': '4', 'link': '?files_page=4', 'disabled': False} expected_b2[5] = {'disp': '5', 'link': '?files_page=5', 'disabled': False} expected_b2[6] = {'disp': '6', 'link': '?files_page=6', 'disabled': False} expected_b2[7] = {'disp': '7', 'link': '?files_page=7', 'disabled': False} expected_b2[8] = {'disp': '>>', 'link': '?files_page=2', 'disabled': False} expected_b3 = list(range(4)) expected_b3[0] = {'disp': '<<', 'link': None, 'disabled': True} expected_b3[1] = {'disp': '1', 'link': '?files_page=1', 'disabled': True} expected_b3[2] = {'disp': '2', 'link': '?files_page=2', 'disabled': False} expected_b3[3] = {'disp': '>>', 'link': '?files_page=2', 'disabled': False} context = RequestContext(HttpRequest()) # Test for bag with more than 100 files self.assertEqual(expected_b1, invapp_extras.pagination_boxes(context, b1_files, 'files_page')) # Test for bag with less than 100 files self.assertEqual(expected_b2, invapp_extras.pagination_boxes(context, b2_files, 'files_page')) # Test for bag with less than 20 files self.assertEqual(expected_b3, invapp_extras.pagination_boxes(context, b3_files, 'files_page'))
class ModelTestCase(TestCase): def setUp(self): # set up hierarchy of fake objects for bag self.c1 = Collection(id='collection_1', name='test-collection-1', created=now()) self.c1.save() self.p1 = Project(id='project_1', name='test-project-1', collection=self.c1, created=now()) self.p1.save() self.i1 = Item(id='item_1', title='test-item-1', project=self.p1, created=now(), original_item_type='1') self.i1.save() self.m1 = Machine(name='test-machine-1', url='http://test.url.com', www_root='/bags/') self.m1.save() # load bag with raw data self.bag = Bag(bagname='test-bag-11', created=now(), item=self.i1, machine=self.m1, absolute_filesystem_path='/bags/partition1/test-bag-11', bag_type='1') self.bag.stats = self.bag.collect_stats() self.bag.save() def test_payload(self): self.assertEqual(self.bag.stats['total_size'], 0) self.assertEqual(self.bag.stats['total_count'], 0) self.assertEqual(len(self.bag.stats['types'].keys()), 0) # now add payload data self.bag.payload = """/data/METADATA/0123456789-dc.xml 2655 /data/METADATA/0123456789-MRC.xml 3256 /data/IMAGES/0123456789_pg1.jp2 1778740 /data/IMAGES/0123456789_pg2.jp2 1878756 /data/IMAGES/0123456789_pg3.jp2 1915879 /data/IMAGES/0123456789_pg1.tiff 1778740 /data/IMAGES/0123456789_pg2.tiff 1878756 /data/IMAGES/0123456789_pg3.tiff 1915879 """ # compare output of parsing method with expected result expect = { 'total_count': 8, 'total_size': 11152661, 'types': { 'xml': {'count': 2, 'size': 5911}, 'jp2': {'count': 3, 'size': 5573375}, 'tiff': {'count': 3, 'size': 5573375} } } self.bag.stats = self.bag.collect_stats() self.bag.save() self.assertEqual(expect['total_size'], self.bag.stats['total_size']) self.assertEqual(expect['total_count'], self.bag.stats['total_count']) for t in expect['types'].keys(): self.assertEqual(expect['types'][t]['count'], self.bag.stats['types'][t]['count']) self.assertEqual(expect['types'][t]['size'], self.bag.stats['types'][t]['size']) def test_bag_access_path(self): self.assertEqual(self.bag.access_url(), 'http://test.url.com/partition1/test-bag-11') self.m1.www_root = '/bags' self.assertEqual(self.bag.access_url(), 'http://test.url.com/partition1/test-bag-11') self.m1.www_root = 'bags' self.assertEqual(self.bag.access_url(), 'http://test.url.com/partition1/test-bag-11') @skipIf(not settings.TEST_IDSERVICE.get('url') or not settings.TEST_IDSERVICE.get('requester') or not settings.TEST_IDSERVICE.get('minter'), 'Test IDService not set') def test_auto_id_creation(self): # test collection c1 = Collection(name='Test Collection autoID') c1.save() self.assertTrue(c1.id) self.assertTrue(c1.created) # test project p1 = Project(name='Test Project autoID', collection=c1) p1.save() self.assertTrue(p1.id) self.assertTrue(p1.created) # test item i1 = Item(title='Test Item autoID', collection=c1, project=p1, original_item_type='1') i1.save() self.assertTrue(i1.id) self.assertTrue(i1.created) # test bag + machine m1 = Machine(name='test machine zzz', url='zzz.gwu.edu') m1.save() b1 = Bag(created=now(), item=i1, machine=m1, absolute_filesystem_path='blah/blah', bag_type='1') b1.save() # test copy numbers for duplicate bags b2 = Bag(created=now(), item=i1, machine=m1, absolute_filesystem_path='blah/blah', bag_type='1') b2.save() self.assertNotEqual(b1.bagname, b2.bagname) self.assertTrue(b1.bagname.endswith('1')) self.assertTrue(b2.bagname.endswith('2')) parts1 = b1.bagname.split('_') parts2 = b2.bagname.split('_') for x, val in enumerate(parts1): if x != len(parts1) - 1: self.assertEqual(val, parts2[x]) else: self.assertTrue(int(parts2[x]) - int(val) == 1) # make sure bagname does not contain forward slash i1.id = '12345/123456789' i1.save() b3 = Bag(created=now(), item=i1, machine=m1, absolute_filesystem_path='xxxx', bag_type='1') b3.save() self.assertFalse('/' in b3.bagname)
def setUp(self): c1 = Collection(id='collection_1_1', name='test-collection-1', created=now()) c1.save() p1 = Project(id='project_1_1', name='test-project-1', collection=c1, created=now()) p1.save() i1 = Item(id='item_1_1', title='test-item-1', project=p1, collection=c1, created=now(), original_item_type='1') i1.save() i2 = Item(id='item_1_2', title='test-item-2', project=p1, collection=c1, created=now(), original_item_type='1') i2.save() i3 = Item(id='item_1_3', title='test-item-3', project=p1, collection=c1, created=now(), original_item_type='1') i3.save() m1 = Machine(name='test-machine-1', url='test-url-1') m1.save() b1 = Bag(bagname='test-bag-1', created=now(), item=i1, machine=m1, absolute_filesystem_path='test-path1', bag_type='1') b1.payload = """/data/METADATA/0123456789-dc.xml 11111 /data/METADATA/0123456789-MRC.xml 22222 /data/IMAGES/0123456789_pg1.jp2 3333333 /data/IMAGES/0123456789_pg2.jp2 4444444 /data/IMAGES/0123456789_pg3.jp2 5555555 /data/IMAGES/0123456789_pg1.tiff 666666 /data/IMAGES/0123456789_pg2.tiff 777777 /data/IMAGES/0123456789_pg3.tiff 888888 """ b1.stats = b1.collect_stats() b1.save() b2 = Bag(bagname='test-bag-2', created=now(), item=i1, machine=m1, absolute_filesystem_path='test-path2', bag_type='1') b2.payload = """/data/METADATA/0123456789-dc.xml 12121 /data/METADATA/0123456789-MRC.xml 23232 /data/IMAGES/0123456789_pg1.jp2 3434343 /data/IMAGES/0123456789_pg2.jp2 4545454 /data/IMAGES/0123456789_pg3.jp2 5656565 /data/IMAGES/0123456789_pg1.tiff 676767 /data/IMAGES/0123456789_pg2.tiff 787878 /data/IMAGES/0123456789_pg3.tiff 898989 """ b2.stats = b2.collect_stats() b2.save() b3 = Bag(bagname='test-bag-3', created=now(), item=i2, machine=m1, absolute_filesystem_path='test-path3', bag_type='1') b3.payload = """/data/METADATA/0123456789-dc.xml 12121 /data/METADATA/0123456789-MRC.xml 23232 /data/IMAGES/0123456789_pg1.jp2 3434343 /data/IMAGES/0123456789_pg2.jp2 4545454 /data/IMAGES/0123456789_pg3.jp2 5656565 /data/IMAGES/0123456789_pg1.tiff 676767 /data/IMAGES/0123456789_pg2.tiff 787878 /data/IMAGES/0123456789_pg3.tiff 898989 """ b3.stats = b3.collect_stats() b3.save() b4 = Bag(bagname='test-bag-4', created=now(), item=i2, machine=m1, absolute_filesystem_path='test-path4', bag_type='1') b4.payload = """/data/METADATA/0123456789-dc.xml 12345 /data/METADATA/0123456789-MRC.xml 34578 /data/IMAGES/0123456789_pg1.jp2 987654 /data/IMAGES/0123456789_pg2.jp2 3214567 /data/IMAGES/0123456789_pg3.jp2 654789 /data/IMAGES/0123456789_pg1.tiff 489751 /data/IMAGES/0123456789_pg2.tiff 584321 /data/IMAGES/0123456789_pg3.tiff 782345 """ b4.stats = b4.collect_stats() b4.save() b5 = Bag(bagname='test-bag-5', created=now(), item=i3, machine=m1, absolute_filesystem_path='test-path5', bag_type='1') b5.payload = """/data/METADATA/0123456789-dc.xml 12121 /data/METADATA/0123456789-MRC.xml 23232 /data/IMAGES/0123456789_pg1.tiff 676767 /data/IMAGES/0123456789_pg2.tiff 787878 /data/IMAGES/0123456789_pg3.tiff 898989 """ b5.stats = b5.collect_stats() b5.save() b6 = Bag(bagname='test-bag-6', created=now(), item=i3, machine=m1, absolute_filesystem_path='test-path6', bag_type='1') b6.payload = """/data/METADATA/0123456789-dc.xml 38479 /data/METADATA/0123456789-MRC.xml 62134 /data/IMAGES/0123456789_pg1.jp2 6489723 /data/IMAGES/0123456789_pg2.jp2 8984567 /data/IMAGES/0123456789_pg3.jp2 1568974 """ b6.stats = b6.collect_stats() b6.save() self.empty_stats = {'total_count': 0, 'total_size': 0, 'types': {}} self.expected = { 'items': { 'i1': { 'total_count': 16, 'total_size': 31735345, 'types': { 'xml': {'count': 4, 'size': 68686}, 'jp2': {'count': 6, 'size': 26969694}, 'tiff': {'count': 6, 'size': 4696965} } }, 'i2': { 'total_count': 16, 'total_size': 22795699, 'types': { 'xml': {'count': 4, 'size': 82276}, 'jp2': {'count': 6, 'size': 18493372}, 'tiff': {'count': 6, 'size': 4220051} } }, 'i3': { 'total_count': 10, 'total_size': 19542864, 'types': { 'xml': {'count': 4, 'size': 135966}, 'jp2': {'count': 3, 'size': 17043264}, 'tiff': {'count': 3, 'size': 2363634} } } }, 'projects': { 'p1': { 'total_count': 42, 'total_size': 74073908, 'types': { 'xml': {'count': 12, 'size': 286928}, 'jp2': {'count': 15, 'size': 62506330}, 'tiff': {'count': 15, 'size': 11280650} } } }, 'collections': { 'c1': { 'total_count': 42, 'total_size': 74073908, 'types': { 'xml': {'count': 12, 'size': 286928}, 'jp2': {'count': 15, 'size': 62506330}, 'tiff': {'count': 15, 'size': 11280650} } } } }