Exemple #1
0
    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'))
Exemple #2
0
    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}
                    }
                }
            }
        }