Example #1
0
 def test_sync_id_with_duplicate_othercatalognumbers(self):
     with connection.cursor() as cursor:
         cursor.execute(
             "CREATE TABLE temp (id text, occurrenceid text, othercatalognumbers text)"
         )
         cursor.execute(
             "INSERT INTO temp VALUES ('urn:uuid:1', 'urn:uuid:1', 'b55cbe46-5f2f-4c07-8223-9d4b0c8ed811')"
         )
         cursor.execute(
             "INSERT INTO temp VALUES ('urn:uuid:2', 'urn:uuid:2', 'b55cbe46-5f2f-4c07-8223-9d4b0c8ed811')"
         )
         cursor.execute(
             "INSERT INTO temp VALUES ('urn:uuid:3', 'urn:uuid:3', '3136D80A-E74C-11E4-A2DC-00155D012A60')"
         )
         cursor.execute(
             "INSERT INTO temp VALUES ('urn:uuid:4', 'urn:uuid:4', '3136D80A-E74C-11E4-A2DC-00155D012A60,5FF9E4CE-E74D-11E4-891B-00155D012A60')"
         )
         cursor.execute(
             "INSERT INTO temp VALUES ('urn:uuid:5', 'urn:uuid:5', 'http://purl.org/nhmuio/id/bdb4f713-5ef6-472b-9e9c-3d03dcb4b6b7')"
         )
         cursor.execute(
             "INSERT INTO temp VALUES ('urn:uuid:6', 'urn:uuid:6', 'bdb4f713-5ef6-472b-9e9c-3d03dcb4b6b7')"
         )
         self.assertTrue(
             migration_processing.sync_id_column('occurrenceid'))
         cursor.execute('SELECT * FROM temp')
         self.assertEqual([('urn:uuid:1', 'urn:uuid:1', ''),
                           ('urn:uuid:2', 'urn:uuid:2', ''),
                           ('urn:uuid:3', 'urn:uuid:3', ''),
                           ('urn:uuid:4', 'urn:uuid:4', ''),
                           ('urn:uuid:5', 'urn:uuid:5', ''),
                           ('urn:uuid:6', 'urn:uuid:6', '')],
                          cursor.fetchall())
Example #2
0
 def test_sync_id_column_with_no_coreid_col_returns_false(self):
     with connection.cursor() as cursor:
         cursor.execute(
             "CREATE TABLE temp (id text, heading text)"
         )  # This happens e.g. http://data.nina.no:8080/ipt/archive.do?r=arko_strandeng occurrence.txt
         cursor.execute("INSERT INTO temp VALUES ('urn:uuid:1', 'b')")
         self.assertFalse(
             migration_processing.sync_id_column('occurrenceid'))
Example #3
0
 def test_sync_id_with_invalid_othercatalognumbers(self):
     with connection.cursor() as cursor:
         cursor.execute(
             "CREATE TABLE temp (id text, occurrenceid text, othercatalognumbers text)"
         )
         cursor.execute(
             "INSERT INTO temp VALUES ('urn:uuid:1', 'urn:uuid:1', 'abc')")
         self.assertTrue(
             migration_processing.sync_id_column('occurrenceid'))
         cursor.execute('SELECT * FROM temp')
         columns = [col[0] for col in cursor.description]
Example #4
0
 def test_sync_id_column_add_new_id_col(self):
     with connection.cursor() as cursor:
         cursor.execute(
             "CREATE TABLE temp (eventid text, heading2 text, heading3 text)"
         )
         cursor.execute(
             "INSERT INTO temp VALUES ('urn:uuid:ba128c35-5e8f-408f-8597-00b1972dace1', 'a', 'b')"
         )
         self.assertTrue(migration_processing.sync_id_column('eventid'))
         cursor.execute('SELECT * FROM temp')
         columns = [col[0] for col in cursor.description]
         self.assertEqual(
             dict(zip(columns, cursor.fetchone())), {
                 'eventid': 'urn:uuid:ba128c35-5e8f-408f-8597-00b1972dace1',
                 'id': 'urn:uuid:ba128c35-5e8f-408f-8597-00b1972dace1',
                 'heading2': 'a',
                 'heading3': 'b'
             })
Example #5
0
 def test_sync_id_column_replace_id_col(self):
     with connection.cursor() as cursor:
         cursor.execute(
             "CREATE TABLE temp (id text, occurrenceid text,  eventid text, heading text)"
         )
         cursor.execute(
             "INSERT INTO temp VALUES ('urn:uuid:1', 'urn:uuid:2', 'urn:uuid:1', 'b')"
         )
         self.assertTrue(
             migration_processing.sync_id_column('occurrenceid'))
         cursor.execute('SELECT * FROM temp')
         columns = [col[0] for col in cursor.description]
         self.assertEqual(
             dict(zip(columns, cursor.fetchone())), {
                 'id': 'urn:uuid:2',
                 'occurrenceid': 'urn:uuid:2',
                 'eventid': 'urn:uuid:1',
                 'heading': 'b'
             })
Example #6
0
 def test_sync_id_with_purl_othercatalognumbers_uuid(self):
     with connection.cursor() as cursor:
         cursor.execute(
             "CREATE TABLE temp (id text, occurrenceid text, othercatalognumbers text)"
         )
         cursor.execute(
             "INSERT INTO temp VALUES ('urn:uuid:1', 'urn:uuid:1', 'b55cbe46-5f2f-4c07-8223-9d4b0c8ed811')"
         )
         self.assertTrue(
             migration_processing.sync_id_column('occurrenceid'))
         cursor.execute('SELECT * FROM temp')
         columns = [col[0] for col in cursor.description]
         self.assertEqual(
             dict(zip(columns, cursor.fetchone())), {
                 'id': 'b55cbe46-5f2f-4c07-8223-9d4b0c8ed811',
                 'occurrenceid': 'urn:uuid:1',
                 'othercatalognumbers':
                 'b55cbe46-5f2f-4c07-8223-9d4b0c8ed811'
             })
Example #7
0
 def test_sync_id_with_purl_othercatalognumbers_url(self):
     with connection.cursor() as cursor:
         cursor.execute(
             "CREATE TABLE temp (id text, occurrenceid text, othercatalognumbers text)"
         )
         cursor.execute(
             "INSERT INTO temp VALUES ('urn:uuid:1', 'urn:uuid:1', 'http://purl.org/nhmuio/id/82b6903f-7613-4aba-b83b-948d0df6391a')"
         )
         self.assertTrue(
             migration_processing.sync_id_column('occurrenceid'))
         cursor.execute('SELECT * FROM temp')
         columns = [col[0] for col in cursor.description]
         self.assertEqual(
             dict(zip(columns, cursor.fetchone())), {
                 'id': '82b6903f-7613-4aba-b83b-948d0df6391a',
                 'occurrenceid': 'urn:uuid:1',
                 'othercatalognumbers':
                 '82b6903f-7613-4aba-b83b-948d0df6391a'
             })