-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master' into afo-register
- Loading branch information
Showing
21 changed files
with
166 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from marshmallow import Schema, fields, validate, post_load | ||
from ebl.common.domain.accession import Accession | ||
|
||
|
||
class AbstractMuseumNumberSchema(Schema): | ||
prefix = fields.String(required=True, validate=validate.Length(min=1)) | ||
number = fields.String( | ||
required=True, validate=(validate.Length(min=1), validate.ContainsNoneOf(".")) | ||
) | ||
suffix = fields.String(required=True, validate=validate.ContainsNoneOf(".")) | ||
|
||
|
||
class AccessionSchema(AbstractMuseumNumberSchema): | ||
@post_load | ||
def create_accession(self, data, **kwargs) -> Accession: | ||
return Accession(**data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from ebl.transliteration.domain.museum_number import MuseumNumber | ||
import functools | ||
import attr | ||
import re | ||
|
||
|
||
@functools.total_ordering | ||
@attr.s(auto_attribs=True, frozen=True, order=False) | ||
class Accession(MuseumNumber): | ||
@staticmethod | ||
def of(source: str) -> "Accession": | ||
if match := re.compile(r"(.+?)\.([^.]+)(?:\.([^.]+))?").fullmatch(source): | ||
return Accession(match[1], match[2], match[3] or "") | ||
else: | ||
raise ValueError(f"'{source}' is not a valid accession number.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import pytest | ||
from ebl.common.application.schemas import AccessionSchema | ||
from ebl.common.domain.accession import Accession | ||
|
||
|
||
ACCESSION = Accession("A", "38") | ||
ACCESSION_DTO = {"prefix": "A", "number": "38", "suffix": ""} | ||
|
||
|
||
def test_of(): | ||
assert Accession.of("A.38") == ACCESSION | ||
|
||
|
||
def test_of_invalid(): | ||
with pytest.raises(ValueError, match="'invalid.' is not a valid accession number."): | ||
Accession.of("invalid.") | ||
|
||
|
||
def test_serialize(): | ||
assert AccessionSchema().dump(ACCESSION) == ACCESSION_DTO | ||
|
||
|
||
def test_deserialize(): | ||
assert AccessionSchema().load(ACCESSION_DTO) == ACCESSION |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,9 @@ | ||
from marshmallow import Schema, fields, post_load, validate | ||
|
||
from marshmallow import post_load | ||
from ebl.transliteration.domain.museum_number import MuseumNumber | ||
from ebl.common.application.schemas import AbstractMuseumNumberSchema | ||
|
||
|
||
class MuseumNumberSchema(Schema): | ||
prefix = fields.String(required=True, validate=validate.Length(min=1)) | ||
number = fields.String( | ||
required=True, validate=(validate.Length(min=1), validate.ContainsNoneOf(".")) | ||
) | ||
suffix = fields.String(required=True, validate=validate.ContainsNoneOf(".")) | ||
|
||
class MuseumNumberSchema(AbstractMuseumNumberSchema): | ||
@post_load | ||
def create_museum_number(self, data, **kwargs) -> MuseumNumber: | ||
return MuseumNumber(**data) |
Oops, something went wrong.