Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make import_provider work with string concept_ids. #98

Merged
merged 1 commit into from
Mar 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions skosprovider_sqlalchemy/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ def import_provider(provider, conceptscheme, session):
c = provider.get_by_id(stuff['id'])
if isinstance(c, Concept):
cm = ConceptModel(
concept_id=int(c.id),
concept_id=c.id,
uri=c.uri,
conceptscheme=conceptscheme
)
elif isinstance(c, Collection):
cm = CollectionModel(
concept_id=int(c.id),
concept_id=c.id,
uri=c.uri,
conceptscheme=conceptscheme
)
Expand Down
31 changes: 25 additions & 6 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,23 @@ def test_empty_provider(self):
scheme = self.session.get(ConceptSchemeModel, 68)
assert scheme == cs

def test_string_concept_id_provider(self):
from skosprovider_sqlalchemy.models import (
ConceptScheme as ConceptSchemeModel
)
from skosprovider.providers import DictionaryProvider

p = DictionaryProvider(
{'id': 'EMPTY'}, [{'id': 'manual-1', 'uri': 'urn:x-skosprovider:manual/manual-1'}]
)
cs = self._get_cs()
self.session.add(cs)
import_provider(p, cs, self.session)
scheme = self.session.get(ConceptSchemeModel, 68)
assert scheme == cs
assert len(scheme.concepts) == 1
assert scheme.concepts[0].concept_id == 'manual-1'

def test_menu(self):
from skosprovider_sqlalchemy.models import (
Concept as ConceptModel
Expand All @@ -332,7 +349,7 @@ def test_menu(self):
ConceptModel.concept_id == '11'
)
).scalar_one()
assert 11 == lobster.concept_id
assert '11' == lobster.concept_id
assert 'urn:x-skosprovider:menu:11' == lobster.uri
assert 'Lobster Thermidor' == str(lobster.label())
assert 1 == len(lobster.notes)
Expand All @@ -347,14 +364,16 @@ def test_geo(self):
cs = self._get_cs()
self.session.add(cs)
import_provider(geoprovider, cs, self.session)
self.session.flush()
self.session.expire_all()
world = self.session.execute(
select(ConceptModel)
.filter(
ConceptModel.conceptscheme == cs,
ConceptModel.concept_id == '1'
)
).scalar_one()
assert world.concept_id == 1
assert world.concept_id == '1'
assert 'urn:x-skosprovider:geography:1' == world.uri
assert 'World' == str(world.label('en'))
assert 1 == len(world.labels)
Expand All @@ -367,7 +386,7 @@ def test_geo(self):
CollectionModel.concept_id == '333'
)
).scalar_one()
assert 333 == dutch.concept_id
assert '333' == dutch.concept_id
assert 'urn:x-skosprovider:geography:333' == dutch.uri
assert 'collection' == dutch.type
assert 1 == len(dutch.labels)
Expand All @@ -380,10 +399,10 @@ def test_geo(self):
ConceptModel.concept_id == '10',
)
).scalar_one()
assert 10 == netherlands.concept_id
assert '10' == netherlands.concept_id
assert 'concept' == netherlands.type
assert 1 == len(netherlands.labels)
assert 2 == netherlands.broader_concepts.pop().concept_id
assert '2' == netherlands.broader_concepts.pop().concept_id
assert 1 == len(netherlands.related_concepts)

def test_buildings(self):
Expand Down Expand Up @@ -562,7 +581,7 @@ def test_geo(self):
visit = vc.visit(cs)
assert 10 == len(visit)
world = visit[0]
assert self.session.get(ConceptModel, world['id']).concept_id == 1
assert self.session.get(ConceptModel, world['id']).concept_id == '1'
assert 1 == world['lft']
assert 20 == world['rght']
assert 1 == world['depth']
Expand Down