Skip to content

Commit

Permalink
Add basic DB test for archives
Browse files Browse the repository at this point in the history
  • Loading branch information
marksparkza committed Nov 29, 2023
1 parent 9786ed7 commit e4e8e7a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
12 changes: 10 additions & 2 deletions test/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
from faker import Faker

from odp.db import Session
from odp.db.models import (Catalog, Client, Collection, CollectionTag, Provider, Record, RecordTag, Role, Schema, Scope, Tag, User,
Vocabulary, VocabularyTerm)
from odp.db.models import (Archive, Catalog, Client, Collection, CollectionTag, Provider, Record,
RecordTag, Role, Schema, Scope, Tag, User, Vocabulary, VocabularyTerm)
from test import datacite4_example, iso19115_example

fake = Faker()
Expand Down Expand Up @@ -329,3 +329,11 @@ def collections(obj, create, collections):
obj.collections.append(collection)
if create:
Session.commit()


class ArchiveFactory(ODPModelFactory):
class Meta:
model = Archive

id = factory.Sequence(lambda n: f'{fake.slug()}.{n}')
url = factory.Faker('url')
10 changes: 8 additions & 2 deletions test/test_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import migrate.systemdata
from odp.const import ODPScope, ODPSystemRole
from odp.db import Session
from odp.db.models import (Catalog, Client, ClientCollection, ClientScope, Collection, CollectionTag, Provider, Record, RecordTag, Role,
from odp.db.models import (Archive, Catalog, Client, ClientCollection, ClientScope, Collection, CollectionTag, Provider, Record, RecordTag, Role,
RoleCollection, RoleScope, Schema, Scope, ScopeType, Tag, User, UserRole, Vocabulary, VocabularyTerm)
from test.factories import (CatalogFactory, ClientFactory, CollectionFactory, CollectionTagFactory, ProviderFactory, RecordFactory,
from test.factories import (ArchiveFactory, CatalogFactory, ClientFactory, CollectionFactory, CollectionTagFactory, ProviderFactory, RecordFactory,
RecordTagFactory, RoleFactory, SchemaFactory, ScopeFactory, TagFactory, UserFactory, VocabularyFactory)


Expand Down Expand Up @@ -43,6 +43,12 @@ def test_db_setup():
)


def test_create_archive():
archive = ArchiveFactory()
result = Session.execute(select(Archive)).scalar_one()
assert (result.id, result.url) == (archive.id, archive.url)


def test_create_catalog():
catalog = CatalogFactory()
result = Session.execute(select(Catalog)).scalar_one()
Expand Down

0 comments on commit e4e8e7a

Please sign in to comment.