Skip to content

Commit

Permalink
Merge e5df5ce into e51581a
Browse files Browse the repository at this point in the history
  • Loading branch information
Wim-De-Clercq committed May 2, 2023
2 parents e51581a + e5df5ce commit e009bb5
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 34 deletions.
Expand Up @@ -16,8 +16,12 @@


def upgrade():
op.alter_column('concept', 'concept_id', _type=sa.String)
with op.batch_alter_table('concept') as batch_op:
batch_op.alter_column('concept_id', type_=sa.String, existing_type=sa.Integer)


def downgrade():
op.alter_column('concept', 'concept_id', _type=sa.Integer)
# Drop concepts which have non-integer concept_id
op.execute("DELETE FROM concept WHERE cast(cast(concept_id AS INTEGER) AS TEXT) != concept_id")
with op.batch_alter_table('concept') as batch_op:
batch_op.alter_column('concept_id', existing_type=sa.String, type_=sa.Integer)
4 changes: 2 additions & 2 deletions atramhasis/data/datamanagers.py
Expand Up @@ -5,11 +5,11 @@
:versionadded: 0.4.1
"""
import uuid

from datetime import date
from datetime import datetime

import dateutil.relativedelta
import sqlalchemy as sa
from skosprovider_sqlalchemy.models import Collection
from skosprovider_sqlalchemy.models import Concept
from skosprovider_sqlalchemy.models import ConceptScheme
Expand Down Expand Up @@ -221,7 +221,7 @@ def get_all_label_types(self):
def get_next_cid(self, conceptscheme_id, id_generation_strategy):
if id_generation_strategy == IDGenerationStrategy.NUMERIC:
max_id = self.session.execute(
select(func.max(Thing.concept_id))
select(func.max(sa.cast(Thing.concept_id, sa.Integer)))
.filter_by(conceptscheme_id=conceptscheme_id)
).scalar_one()
return max_id + 1 if max_id else 1
Expand Down
2 changes: 1 addition & 1 deletion atramhasis/scripts/import_file.py
Expand Up @@ -226,7 +226,7 @@ def provider_to_db(provider, conceptscheme, session):
import provider data into the database
"""
session.add(conceptscheme)
import_provider(provider, conceptscheme, session)
import_provider(provider, session, conceptscheme)
session.commit()


Expand Down
18 changes: 9 additions & 9 deletions atramhasis/scripts/initializedb.py
Expand Up @@ -37,6 +37,7 @@ def main(argv=sys.argv):
db_session = sessionmaker(bind=engine)()
import_provider(
trees,
db_session,
ConceptScheme(
id=1,
uri='urn:x-skosprovider:trees',
Expand All @@ -45,10 +46,10 @@ def main(argv=sys.argv):
Label('Different types of trees', 'prefLabel', 'en')
]
),
db_session
)
import_provider(
geo,
db_session,
ConceptScheme(
id=2,
uri='urn:x-skosprovider:geo',
Expand All @@ -57,10 +58,10 @@ def main(argv=sys.argv):
Label('Geography', 'prefLabel', 'en')
]
),
db_session
)
import_provider(
styles_and_cultures,
db_session,
ConceptScheme(
id=3,
uri='https://id.erfgoed.net/thesauri/stijlen_en_culturen',
Expand All @@ -69,10 +70,10 @@ def main(argv=sys.argv):
Label('Styles and Cultures', 'prefLabel', 'en')
]
),
db_session
)
import_provider(
materials,
db_session,
ConceptScheme(
id=4,
uri='https://id.erfgoed.net/thesauri/materialen',
Expand All @@ -81,10 +82,10 @@ def main(argv=sys.argv):
Label('Materials', 'prefLabel', 'en')
]
),
db_session
)
import_provider(
eventtypes,
db_session,
ConceptScheme(
id=5,
uri='https://id.erfgoed.net/thesauri/gebeurtenistypes',
Expand All @@ -93,10 +94,10 @@ def main(argv=sys.argv):
Label('Event types', 'prefLabel', 'en')
]
),
db_session
)
import_provider(
heritagetypes,
db_session,
ConceptScheme(
id=6,
uri='https://id.erfgoed.net/thesauri/erfgoedtypes',
Expand All @@ -105,10 +106,10 @@ def main(argv=sys.argv):
Label('Heritage types', 'prefLabel', 'en')
]
),
db_session
)
import_provider(
periods,
db_session,
ConceptScheme(
id=7,
uri='https://id.erfgoed.net/thesauri/dateringen',
Expand All @@ -117,10 +118,10 @@ def main(argv=sys.argv):
Label('Periods', 'prefLabel', 'en')
]
),
db_session
)
import_provider(
species,
db_session,
ConceptScheme(
id=8,
uri='https://id.erfgoed.net/thesauri/soorten',
Expand All @@ -129,10 +130,10 @@ def main(argv=sys.argv):
Label('Species', 'prefLabel', 'en')
]
),
db_session
)
import_provider(
bluebirds,
db_session,
ConceptScheme(
id=9,
uri='https://id.bluebirds.org',
Expand All @@ -141,7 +142,6 @@ def main(argv=sys.argv):
Label('Blue birds', 'prefLabel', 'en')
]
),
db_session
)
db_session.commit()
db_session.close()
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Expand Up @@ -7,7 +7,7 @@ openapi-spec-validator==0.4.0 # https://github.com/p1c2u/openapi-core/issues/44

# skosprovider
skosprovider==1.2.0
skosprovider_sqlalchemy==2.0.1
skosprovider_sqlalchemy==2.1.1
pyramid_skosprovider==1.2.0
skosprovider_rdf==1.3.0
skosprovider_getty==1.1.0
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -48,7 +48,7 @@ def run(self):
'transaction',
'zope.sqlalchemy',
'skosprovider',
'skosprovider_sqlalchemy>=2.0.1',
'skosprovider_sqlalchemy>=2.1.1',
'skosprovider_rdf',
'skosprovider_getty',
'pyramid_skosprovider',
Expand Down
20 changes: 11 additions & 9 deletions tests/__init__.py
Expand Up @@ -9,6 +9,7 @@
from skosprovider.registry import Registry
from skosprovider.skos import ConceptScheme
from skosprovider.uri import UriPatternGenerator
from skosprovider_sqlalchemy.models import Concept
from skosprovider_sqlalchemy.providers import SQLAlchemyProvider
from skosprovider_sqlalchemy.utils import import_provider
from sqlalchemy import engine_from_config
Expand Down Expand Up @@ -77,14 +78,14 @@ def fill_db():
from skosprovider_sqlalchemy.models import ConceptScheme
with db_session() as session:
import_provider(trees,
ConceptScheme(id=1, uri='urn:x-skosprovider:trees'),
session)
session,
ConceptScheme(id=1, uri='urn:x-skosprovider:trees'))
import_provider(material_data.materials,
ConceptScheme(id=4, uri='urn:x-vioe:materials'),
session)
session,
ConceptScheme(id=4, uri='urn:x-vioe:materials'))
import_provider(data.geo,
ConceptScheme(id=2, uri='urn:x-vioe:geography'),
session)
session,
ConceptScheme(id=2, uri='urn:x-vioe:geography'))
import_provider(
DictionaryProvider(
{'id': 'MISSING_LABEL', 'default_language': 'nl'},
Expand All @@ -97,8 +98,9 @@ def fill_db():
],
}]
),
ConceptScheme(id=9, uri='urn:x-vioe:test'),
session)
session,
ConceptScheme(id=9, uri='urn:x-vioe:test')
)
import_provider(
DictionaryProvider(
{'id': 'manual-ids', 'default_language': 'nl'},
Expand All @@ -118,8 +120,8 @@ def fill_db():
],
}]
),
ConceptScheme(id=10, uri='urn:x-vioe:manual'),
session,
ConceptScheme(id=10, uri='urn:x-vioe:manual'),
)
session.add(ConceptScheme(id=3, uri='urn:x-vioe:styles'))
for scheme_id in (5, 6, 7, 8):
Expand Down
11 changes: 7 additions & 4 deletions tests/test_functional.py
Expand Up @@ -204,7 +204,7 @@ def test_get_concept(self):
self.assertEqual('200 OK', res.status)
self.assertIn('application/json', res.headers['Content-Type'])
self.assertIsNotNone(res.json['id'])
self.assertEqual(res.json['id'], 1)
self.assertEqual(res.json['id'], '1')
self.assertEqual(res.json['type'], 'concept')
self.assertIn('sortLabel', [label['type'] for label in res.json['labels']])

Expand Down Expand Up @@ -351,11 +351,14 @@ def test_edit_concept_not_found(self):
self.assertIn('application/json', res.headers['Content-Type'])

def test_delete_concept(self):
new_id = 1
res = self.testapp.delete('/conceptschemes/TREES/c/' + str(new_id), headers=self._get_default_headers())
new_id = '1'
res = self.testapp.delete(f'/conceptschemes/TREES/c/{new_id}', headers=self._get_default_headers())
self.assertEqual('200 OK', res.status)
self.assertIsNotNone(res.json['id'])
self.assertEqual(new_id, res.json['id'])
from skosprovider_sqlalchemy.models import Concept
concepten = self.session.query(Concept).all()
print()

def test_delete_concept_not_found(self):
res = self.testapp.delete('/conceptschemes/TREES/c/7895', headers=self._get_default_headers(),
Expand Down Expand Up @@ -697,7 +700,7 @@ def test_match_filter(self):
self.assertEqual(
[
{
'id': 1,
'id': '1',
'uri': 'urn:x-skosprovider:trees/1',
'type': 'concept',
'label': 'De Lariks',
Expand Down
10 changes: 5 additions & 5 deletions tests/test_import_scripts.py
Expand Up @@ -47,8 +47,8 @@ def _check_trees(self, conceptscheme_label):
self.assertEqual(conceptscheme_label, sql_prov.concept_scheme.label('en').label)
obj_1 = [item for item in dump if item['uri'] == 'http://id.trees.org/2'][0]
self.assertEqual(obj_1['broader'], [])
self.assertEqual(obj_1['id'], 2)
self.assertEqual(obj_1['member_of'], [3])
self.assertEqual(obj_1['id'], '2')
self.assertEqual(obj_1['member_of'], ['3'])
self.assertEqual(obj_1['narrower'], [])
label_en = [label for label in obj_1['labels'] if label['language'] == 'en'][0]
self.assertDictEqual(label_en, {'label': 'The Chestnut', 'language': 'en', 'type': 'prefLabel'})
Expand All @@ -66,20 +66,20 @@ def _check_menu(self, uri_pattern=None):
self.assertEqual(11, len(sql_prov.get_all()))
eb = sql_prov.get_by_id(1)
self.assertIsInstance(eb, Concept)
self.assertEqual(1, eb.id)
self.assertEqual('1', eb.id)
self.assertEqual(uri_pattern % '1', eb.uri)
self.assertEqual('Egg and Bacon', eb.label().label)
self.assertEqual('prefLabel', eb.label().type)
self.assertEqual([], eb.notes)
eb = sql_prov.get_by_uri(uri_pattern % '3')
self.assertIsInstance(eb, Concept)
self.assertEqual(3, eb.id)
self.assertEqual('3', eb.id)
self.assertEqual(uri_pattern % '3', eb.uri)
spam = sql_prov.find({'label': 'Spam'})
self.assertEqual(8, len(spam))
eb = sql_prov.get_by_id(11)
self.assertIsInstance(eb, Concept)
self.assertEqual(11, eb.id)
self.assertEqual('11', eb.id)
self.assertEqual('Lobster Thermidor', eb.label().label)
self.assertIsInstance(eb.notes[0], Note)
self.assertIn('Mornay', eb.notes[0].note)
Expand Down

0 comments on commit e009bb5

Please sign in to comment.