Exemplo n.º 1
0
 def test_create_from_rows(self):
     #('PID', 'entity_type', 'title', 'document_type', 'url', 'enabled', 'notes', 'format', 'reference', 'order')
     row_pack = [
         [
             u'1812-A', u'work', u'Naderend onweer', u'data',
             u'http://www.vlaamsekunstcollectie.be/collection.aspx?p=0848cab7-2776-4648-9003-25957707491a&inv=1812-A',
             u'1', u'', u'html', u'', u''
         ],
         [
             u'1812-A', u'work', u'Naderend onweer', u'representation',
             u'http://www.vlaamsekunstcollectie.be/proxy.aspx?server=62.221.199.163&port=28301&overlaytext=&overlaytextalpha=14&overlaytextfontname=verdana&overlaytextfontsize=8&overlaytextfontcolor=000000&overlaytextbackgroundcolor=cccccc&cache=yes&borderwidth=0&borderheight=0&bordercolor=999999&passepartoutwidth=6&passepartoutheight=6&passepartoutcolor=ffffff&bg=ffffff&filename=gent%2F1812-A.jpg',
             u'1', u'', u'1', u'1', u''
         ]
     ]
     import_id = '123'
     entity, documents = EntityApi().create_from_rows(row_pack, import_id)
     d_e = EntityApi().read_by_original_id(row_pack[0][0])
     assert d_e == entity
     assert len(Entity.query.all()) == 1
     d_d = Document.query.filter(Document.entity_id == entity.id).all()
     assert len(d_d) == 2
     assert 'data' in [d.type for d in d_d]
     assert 'representation' in [d.type for d in d_d]
     for d in d_d:
         if d.type == 'data':
             assert d.url == 'http://www.vlaamsekunstcollectie.be/collection.aspx?p=0848cab7-2776-4648-9003-25957707491a&inv=1812-A'
         if d.type == 'representation':
             assert d.url == 'http://www.vlaamsekunstcollectie.be/proxy.aspx?server=62.221.199.163&port=28301&overlaytext=&overlaytextalpha=14&overlaytextfontname=verdana&overlaytextfontsize=8&overlaytextfontcolor=000000&overlaytextbackgroundcolor=cccccc&cache=yes&borderwidth=0&borderheight=0&bordercolor=999999&passepartoutwidth=6&passepartoutheight=6&passepartoutcolor=ffffff&bg=ffffff&filename=gent%2F1812-A.jpg'
         assert d.entity_id == '1812-A'
     assert len(Data.query.all()) == 1
     assert len(Representation.query.all()) == 1
Exemplo n.º 2
0
 def test_read(self):
     e = EntityApi().create({
         'PID': u'1812-A',
         'entity_type': u'work',
         'title': u'Naderend onweer',
     })
     d_e = EntityApi().read(e.id)
     assert d_e == e
Exemplo n.º 3
0
 def test_unicode_create_from_rows(self):
     import_id = '123'
     row_pack = [[
         u'1813-A', u'work', u'Le &àçèé£$^=°-)', u'data',
         u'http://www.vlaamsekunstcollectie.be/collection.aspx?p=0848cab7-2776-4648-9003-25957707491a&inv=1812-A',
         u'1', u'', u'html', u'', u''
     ]]
     EntityApi().create_from_rows(row_pack, import_id)
     d = EntityApi().read_by_original_id('1813-A')
     assert d.title == u'Le &àçèé£$^=°-)'
Exemplo n.º 4
0
 def test_entitycollision_create_from_rows(self):
     import_id = '123'
     row_pack = [[
         u'1814(A', u'work', u'Naderend onweer', u'data',
         u'http://www.vlaamsekunstcollectie.be/collection.aspx?p=0848cab7-2776-4648-9003-25957707491a&inv=1812-A',
         u'1', u'', u'html', u'', u''
     ]]
     EntityApi().create_from_rows(row_pack, import_id)
     row_pack = [[
         u'1814_A', u'work', u'Naderende storm', u'data',
         u'http://www.vlaamsekunstcollectie.be/collection.aspx?p=0848cab7-2776-4648-9003-25957707491a&inv=1812-A',
         u'1', u'', u'html', u'', u''
     ]]
     self.assertRaises(EntityCollisionException,
                       EntityApi().create_from_rows, row_pack, import_id)
Exemplo n.º 5
0
 def test_update(self):
     self.assertRaises(NotImplementedError, DataApi().update, 1, {})
     return
     entity = EntityApi().create({'PID': '123', 'entity_type': 'work'})
     input_data = {'entity_id': entity.id, 'format': 'html', 'url': 'http://foo.bar', 'enabled': 1, 'notes': 'A Test'}
     updated_data = {'entity_id': entity.id, 'format': 'pdf', 'url': 'http://foo.bar', 'enabled': 1, 'notes': 'A Test'}
     self.t_update(api_class=DataApi, input_data=input_data, updated_data=updated_data)
Exemplo n.º 6
0
 def test_update(self):
     self.assertRaises(NotImplementedError, RepresentationApi().update, 1, {})
     return
     entity = EntityApi().create({'PID': u'1812-A', 'entity_type': u'work'})
     input_data = {
         'entity_id': entity.id,
         'order': 1,
         'label': 'Foo',
         'url': 'http://www.foo.bar',
         'enabled': 1,
         'notes': 'A Test',
         'reference': 1,
         'document_type': 'representation'
     }
     updated_data = {
         'entity_id': entity.id,
         'order': 1,
         'label': 'Foobar',
         'url': 'http://www.foo.bar.x',
         'enabled': 1,
         'notes': 'A Test (2)',
         'reference': 1,
         'document_type': 'representation'
     }
     self.t_update(RepresentationApi, input_data, updated_data)
Exemplo n.º 7
0
 def test_get_in_order(self):
     entity = EntityApi().create({'PID': u'1812-A', 'entity_type': u'work'})
     input_data = {
         'entity_id': entity.id,
         'order': 1,
         'label': 'Foo',
         'url': 'http://www.foo.bar',
         'enabled': 1,
         'notes': 'A Test',
         'reference': 1,
         'document_type': 'representation'
     }
     r_a = RepresentationApi().create(input_data)
     input_data_extra = {
         'entity_id': entity.id,
         'order': 2,
         'label': 'Foo',
         'url': 'http://www.foo.bar.x',
         'enabled': 1,
         'notes': 'A Test (2)',
         'reference': 0,
         'document_type': 'representation'
     }
     r_b = RepresentationApi().create(input_data_extra)
     l = RepresentationApi().get_in_order(entity.id)
     assert len(l) == 2
     assert l[0] == r_a
     assert l[1] == r_b
Exemplo n.º 8
0
    def test_csv_importer(self):
        records = [
            [
                u'1812-A', u'work', u'Naderend onweer', u'data',
                u'http://www.vlaamsekunstcollectie.be/collection.aspx?p=0848cab7-2776-4648-9003-25957707491a&inv=1812-A',
                u'1', u'', u'html', u'', u''
            ],
            [
                u'1812-A', u'work', u'Naderend onweer', u'representation',
                u'http://www.vlaamsekunstcollectie.be/proxy.aspx?server=62.221.199.163&port=28301&overlaytext=&overlaytextalpha=14&overlaytextfontname=verdana&overlaytextfontsize=8&overlaytextfontcolor=000000&overlaytextbackgroundcolor=cccccc&cache=yes&borderwidth=0&borderheight=0&bordercolor=999999&passepartoutwidth=6&passepartoutheight=6&passepartoutcolor=ffffff&bg=ffffff&filename=gent%2F1812-A.jpg',
                u'1', u'', u'1', u'1', u''
            ],
            [
                u'1813-A', u'work', u'Na de regen', u'data',
                u'http://www.vlaamsekunstcollectie.be/collection.aspx?p=0848cab7-2776-4648-9003-25957707491a&inv=1812-A',
                u'1', u'', u'html', u'', u''
            ],
            [
                u'1813-A', u'work', u'Na de regen', u'representation',
                u'http://www.vlaamsekunstcollectie.be/proxy.aspx?server=62.221.199.163&port=28301&overlaytext=&overlaytextalpha=14&overlaytextfontname=verdana&overlaytextfontsize=8&overlaytextfontcolor=000000&overlaytextbackgroundcolor=cccccc&cache=yes&borderwidth=0&borderheight=0&bordercolor=999999&passepartoutwidth=6&passepartoutheight=6&passepartoutcolor=ffffff&bg=ffffff&filename=gent%2F1812-A.jpg',
                u'1', u'', u'1', u'1', u''
            ],
        ]
        import_id = '123'
        c_importer = CSVImporter(records, import_id)
        c_importer.store()

        # Most tests are done by test_entity
        assert len(Entity.query.all()) == 1
        d_e = EntityApi().read_by_original_id(records[0][0])
        assert d_e.original_id == '1812-A'
        assert len(c_importer.failures) == 0
        assert len(c_importer.bad_records) == 0
Exemplo n.º 9
0
 def get_original(self, original_entity_id):
     try:
         existing_entity = EntityApi().read_by_original_id(
             original_entity_id)
     except ItemDoesNotExist:
         return None
     return self.output(existing_entity)
Exemplo n.º 10
0
 def test_list(self):
     self.assertRaises(NotImplementedError, EntityApi().list)
     return
     input_data = {
         'PID': u'1812-A',
         'entity_type': u'work',
         'title': u'Naderend onweer',
     }
     self.t_list(EntityApi, input_data)
Exemplo n.º 11
0
 def test_unrecognizeddocumenttype_create_from_rows(self):
     import_id = '123'
     row_pack = [[
         u'1813-A', u'work', u'Naderend onweer', u'exception',
         u'http://www.vlaamsekunstcollectie.be/collection.aspx?p=0848cab7-2776-4648-9003-25957707491a&inv=1812-A',
         u'1', u'', u'html', u'', u''
     ]]
     self.assertRaises(UnrecognizedDocumentType,
                       EntityApi().create_from_rows, row_pack, import_id)
Exemplo n.º 12
0
 def test_read(self):
     self.assertRaises(NotImplementedError, RepresentationApi().read, 1)
     return
     entity = EntityApi().create({'PID': u'1812-A', 'entity_type': u'work'})
     input_data_min = {
         'entity_id': entity.id,
         'order': 1
     }
     self.t_read(RepresentationApi, input_data_min)
Exemplo n.º 13
0
 def test_unrecognizedentitytype_create_from_rows(self):
     # ('PID', 'entity_type', 'title', 'document_type', 'url', 'enabled', 'notes', 'format', 'reference', 'order')
     import_id = '123'
     row_pack = [[
         u'1812-A', u'exception', u'Naderend onweer', u'data',
         u'http://www.vlaamsekunstcollectie.be/collection.aspx?p=0848cab7-2776-4648-9003-25957707491a&inv=1812-A',
         u'1', u'', u'html', u'', u''
     ]]
     self.assertRaises(UnrecognizedEntityType,
                       EntityApi().create_from_rows, row_pack, import_id)
Exemplo n.º 14
0
 def store(self):
     e_api = EntityApi()
     try:
         entity, documents = e_api.create_from_rows(self.records, self.import_id)
     #except UnicodeEncodeError as e:
     #    a_exc = traceback.format_exc().splitlines()
     #    error_msg = u'Entity {0}: {1}'.format(self.records[0][0], a_exc)
     #    self.failures.append(error_msg)
     #    self.bad_records += self.records
     #    app.logger.error(error_msg)
     #    e_api.rollback()
     except Exception as e:
         a_exc = traceback.format_exc().splitlines()
         error_msg = u'Entity {0}: {1}'.format(self.records[0][0], a_exc[-1])
         self.failures.append(error_msg)
         self.bad_records += self.records
         app.logger.error(error_msg)
         e_api.rollback()
     else:
         import_log(self.import_id, 'Added/updated PID {0}'.format(entity.id))
Exemplo n.º 15
0
 def test_update(self):
     self.assertRaises(NotImplementedError, EntityApi().update, 1, {})
     return
     input_data = {
         'PID': u'1812-A',
         'entity_type': u'work',
         'title': u'Naderend onweer'
     }
     updated_data = {
         'PID': u'1812-A',
         'entity_type': u'work',
         'title': u'Na regen komt zonneschijn'
     }
     self.t_update(EntityApi, input_data, updated_data)
Exemplo n.º 16
0
 def test_by_entity_id_url_and_type(self):
     entity = EntityApi().create({'PID': u'1812-A', 'entity_type': u'work'})
     input_data = {
         'entity_id': entity.id,
         'order': 1,
         'label': 'Foo',
         'url': 'http://www.foo.bar',
         'enabled': 1,
         'notes': 'A Test',
         'reference': 1,
         'document_type': 'representation'
     }
     r = RepresentationApi().create(input_data)
     l = RepresentationApi().by_entity_id_url_and_type(entity.id, 'http://www.foo.bar', 'representation')
     assert r == l
Exemplo n.º 17
0
 def test_create(self):
     #'entity_id', 'format', 'url', 'enabled', 'notes'
     entity = EntityApi().create({'PID': '123', 'entity_type': 'work'})
     input_data_max = {
         'entity_id': entity.id,
         'format': 'html',
         'url': 'http://foo.bar',
         'enabled': 1,
         'notes': 'A Test'
     }
     input_data_min = {
         'entity_id': entity.id,
         'format': 'html'
     }
     d = self.t_create(api_class=DataApi, db_class=Data, input_data_max=input_data_max, input_data_min=input_data_min)
     assert d.entity_id == entity.id
Exemplo n.º 18
0
 def test_create(self):
     entity = EntityApi().create({'PID': u'1812-A', 'entity_type': u'work'})
     input_data = {
         'entity_id': entity.id,
         'order': 1,
         'label': 'Foo',
         'url': 'http://www.foo.bar',
         'enabled': 1,
         'notes': 'A Test',
         'reference': 1,
         'document_type': 'representation'
     }
     input_data_min = {
         'entity_id': entity.id,
         'order': 1
     }
     self.t_create(input_data, input_data_min, Representation, RepresentationApi)
Exemplo n.º 19
0
 def test_by_format_and_identity_id(self):
     entity = EntityApi().create({'PID': '123', 'entity_type': 'work'})
     d = DataApi().create(
         {'entity_id': entity.id, 'format': 'html', 'url': 'http://foo.bar', 'enabled': 1, 'notes': 'A Test'})
     d_e = DataApi().by_format_and_entity_id('html', entity.id)
     assert d == d_e
Exemplo n.º 20
0
 def get(self, entity_id):
     try:
         existing_entity = EntityApi().read(entity_id)
     except ItemDoesNotExist:
         return None
     return self.output(existing_entity)
Exemplo n.º 21
0
 def test_list(self):
     self.assertRaises(NotImplementedError, DataApi().list)
     return
     entity = EntityApi().create({'PID': '123', 'entity_type': 'work'})
     self.t_list(api_class=DataApi, input_data={'entity_id': entity.id, 'format': 'html'})