Skip to content

Commit

Permalink
Fix up tests a bit more
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathangreen committed Jun 27, 2024
1 parent ab5fe08 commit f234f88
Show file tree
Hide file tree
Showing 16 changed files with 327 additions and 72 deletions.
2 changes: 1 addition & 1 deletion src/palace/manager/core/opds_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def opds2_cached_retrieve(uri: str) -> str:
filename = parsed.path.removeprefix("/").replace("/", "_")
package_file = resources / "cached" / netloc_dir / filename
# if not package_file.is_file():
# cached_dir = cast(Path, resources / "cached" / netloc_dir)
# cached_dir = resources / "cached" / netloc_dir
# cached_dir.mkdir(parents=True, exist_ok=True)
# (cached_dir / filename).write_text(requests.get(uri).text)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://drafts.opds.io/schema/acquisition-object.schema.json",
"title": "OPDS Acquisition Object",
"type": "object",
"properties": {
"type": {
"type": "string"
},
"child": {
"type": "array",
"items": {
"$ref": "acquisition-object.schema.json"
}
}
},
"required": [
"type"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://drafts.opds.io/schema/properties.schema.json",
"title": "OPDS Link Properties",
"type": "object",
"properties": {
"numberOfItems": {
"description": "Provide a hint about the expected number of items returned",
"type": "integer",
"minimum": 0
},
"price": {
"description": "The price of a publication is tied to its acquisition link",
"type": "object",
"properties": {
"value": {
"type": "number",
"minimum": 0
},
"currency": {
"type": "string",
"enum": [
"AED", "AFN", "ALL", "AMD", "ANG", "AOA", "ARS", "AUD", "AWG", "AZN", "BAM", "BBD", "BDT",
"BGN", "BHD", "BIF", "BMD", "BND", "BOB", "BOV", "BRL", "BSD", "BTN", "BWP", "BYN", "BZD",
"CAD", "CDF", "CHE", "CHF", "CHW", "CLF", "CLP", "CNY", "COP", "COU", "CRC", "CUC", "CUP",
"CVE", "CZK", "DJF", "DKK", "DOP", "DZD", "EGP", "ERN", "ETB", "EUR", "FJD", "FKP", "GBP",
"GEL", "GHS", "GIP", "GMD", "GNF", "GTQ", "GYD", "HKD", "HNL", "HRK", "HTG", "HUF", "IDR",
"ILS", "INR", "IQD", "IRR", "ISK", "JMD", "JOD", "JPY", "KES", "KGS", "KHR", "KMF", "KPW",
"KRW", "KWD", "KYD", "KZT", "LAK", "LBP", "LKR", "LRD", "LSL", "LYD", "MAD", "MDL", "MGA",
"MKD", "MMK", "MNT", "MOP", "MRU", "MUR", "MVR", "MWK", "MXN", "MXV", "MYR", "MZN", "NAD",
"NGN", "NIO", "NOK", "NPR", "NZD", "OMR", "PAB", "PEN", "PGK", "PHP", "PKR", "PLN", "PYG",
"QAR", "RON", "RSD", "RUB", "RWF", "SAR", "SBD", "SCR", "SDG", "SEK", "SGD", "SHP", "SLL",
"SOS", "SRD", "SSP", "STN", "SVC", "SYP", "SZL", "THB", "TJS", "TMT", "TND", "TOP", "TRY",
"TTD", "TWD", "TZS", "UAH", "UGX", "USD", "USN", "UYI", "UYU", "UZS", "VEF", "VES", "VND",
"VUV", "WST", "XAF", "XAG", "XAU", "XBA", "XBB", "XBC", "XBD", "XCD", "XDR", "XOF", "XPD",
"XPF", "XPT", "XSU", "XTS", "XUA", "XXX", "YER", "ZAR", "ZMW", "ZWL"
]
}
},
"required": [
"currency",
"value"
]
},
"indirectAcquisition": {
"description": "Indirect acquisition provides a hint for the expected media type that will be acquired after additional steps",
"type": "array",
"items": {
"$ref": "acquisition-object.schema.json"
}
},
"holds": {
"description": "Library-specific feature for unavailable books that support a hold list",
"type": "object",
"properties": {
"total": {
"type": "integer",
"minimum": 0
},
"position": {
"type": "integer",
"minimum": 0
}
}
},
"copies": {
"description": "Library-specific feature that contains information about the copies that a library has acquired",
"type": "object",
"properties": {
"total": {
"type": "integer",
"minimum": 0
},
"available": {
"type": "integer",
"minimum": 0
}
}
},
"availability": {
"description": "Indicates the availability of a given resource",
"type": "object",
"properties": {
"state": {
"type": "string",
"enum": [
"available",
"unavailable",
"reserved",
"ready"
]
},
"since": {
"description": "Timestamp for the previous state change",
"type": "string",
"anyOf": [
{
"format": "date"
},
{
"format": "date-time"
}
]
},
"until": {
"description": "Timestamp for the next state change",
"type": "string",
"anyOf": [
{
"format": "date"
},
{
"format": "date-time"
}
]
}
},
"required": [
"state"
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://readium.org/webpub-manifest/schema/experimental/presentation/properties.schema.json",
"title": "Presentation Hints - Link Properties",
"type": "object",
"properties": {
"clipped": {
"description": "Specifies whether or not the parts of a linked resource that flow out of the viewport are clipped.",
"type": "boolean"
},
"fit": {
"description": "Specifies constraints for the presentation of a linked resource within the viewport.",
"type": "string",
"enum": [
"contain",
"cover",
"width",
"height"
]
},
"orientation": {
"description": "Suggested orientation for the device when displaying the linked resource.",
"type": "string",
"enum": [
"auto",
"landscape",
"portrait"
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://readium.org/webpub-manifest/schema/extensions/divina/properties.schema.json",
"title": "Divina Profile - Link Properties",
"type": "object",
"properties": {
"break-scroll-before": {
"description": "Specifies that an item in the reading order should break the current continuous scroll and start a new one.",
"type": "boolean",
"default": false
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://readium.org/webpub-manifest/schema/extensions/encryption/properties.schema.json",
"title": "Encryption Module - Link Properties",
"type": "object",
"properties": {
"encrypted": {
"description": "Indicates that a resource is encrypted/obfuscated and provides relevant information for decryption",
"type": "object",
"properties": {
"algorithm": {
"description": "Identifies the algorithm used to encrypt the resource",
"type": "string",
"format": "uri"
},
"compression": {
"description": "Compression method used on the resource",
"type": "string"
},
"originalLength": {
"description": "Original length of the resource in bytes before compression and/or encryption",
"type": "integer"
},
"profile": {
"description": "Identifies the encryption profile used to encrypt the resource",
"type": "string",
"format": "uri"
},
"scheme": {
"description": "Identifies the encryption scheme used to encrypt the resource",
"type": "string",
"format": "uri"
}
},
"required": [
"algorithm"
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://readium.org/webpub-manifest/schema/extensions/epub/properties.schema.json",
"title": "EPUB Profile - Link Properties",
"type": "object",
"properties": {
"contains": {
"description": "Identifies content contained in the linked resource, that cannot be strictly identified using a media type.",
"type": "array",
"items": {
"type": "string",
"enum": [
"mathml",
"onix",
"remote-resources",
"js",
"svg",
"xmp"
]
},
"uniqueItems": true
},
"layout": {
"description": "Hints how the layout of a specific resource should be presented",
"type": "string",
"enum": [
"fixed",
"reflowable"
]
}
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
15 changes: 1 addition & 14 deletions tests/fixtures/api_odl.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from palace.manager.sqlalchemy.model.licensing import LicensePool
from palace.manager.sqlalchemy.model.resource import HttpResponseTuple
from palace.manager.sqlalchemy.model.work import Work
from tests.fixtures.files import FilesFixture
from tests.fixtures.files import FilesFixture, ODL2APIFilesFixture

if TYPE_CHECKING:
from tests.fixtures.database import DatabaseTransactionFixture
Expand Down Expand Up @@ -95,19 +95,6 @@ def api_odl_files_fixture() -> ODLAPIFilesFixture:
return ODLAPIFilesFixture()


class ODL2APIFilesFixture(FilesFixture):
"""A fixture providing access to ODL2 files."""

def __init__(self):
super().__init__("odl2")


@pytest.fixture()
def api_odl2_files_fixture() -> ODL2APIFilesFixture:
"""A fixture providing access to ODL2 files."""
return ODL2APIFilesFixture()


class MockGet:
def __init__(self):
self.responses = []
Expand Down
26 changes: 26 additions & 0 deletions tests/fixtures/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,32 @@ def opds_files_fixture() -> OPDSFilesFixture:
return OPDSFilesFixture()


class OPDS2FilesFixture(FilesFixture):
"""A fixture providing access to OPDS2 files."""

def __init__(self):
super().__init__("opds2")


@pytest.fixture()
def opds2_files_fixture() -> OPDS2FilesFixture:
"""A fixture providing access to OPDS2 files."""
return OPDS2FilesFixture()


class ODL2APIFilesFixture(FilesFixture):
"""A fixture providing access to ODL2 files."""

def __init__(self):
super().__init__("odl2")


@pytest.fixture()
def api_odl2_files_fixture() -> ODL2APIFilesFixture:
"""A fixture providing access to ODL2 files."""
return ODL2APIFilesFixture()


class SampleCoversFixture(FilesFixture):
"""A fixture providing access to sample cover images."""

Expand Down
4 changes: 2 additions & 2 deletions tests/fixtures/odl.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
from palace.manager.sqlalchemy.model.resource import Representation
from palace.manager.sqlalchemy.model.work import Work
from palace.manager.util.http import HTTP
from tests.fixtures.api_odl import ODL2APIFilesFixture, ODLAPIFilesFixture
from tests.fixtures.api_odl import ODLAPIFilesFixture
from tests.fixtures.database import DatabaseTransactionFixture
from tests.fixtures.files import FilesFixture
from tests.fixtures.files import FilesFixture, ODL2APIFilesFixture
from tests.mocks.mock import MockRequestsResponse


Expand Down
8 changes: 2 additions & 6 deletions tests/manager/api/test_odl2.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,9 @@
from palace.manager.sqlalchemy.model.work import Work
from palace.manager.sqlalchemy.util import create
from palace.manager.util.datetime_helpers import utc_now
from tests.fixtures.api_odl import (
LicenseHelper,
LicenseInfoHelper,
MockGet,
ODL2APIFilesFixture,
)
from tests.fixtures.api_odl import LicenseHelper, LicenseInfoHelper, MockGet
from tests.fixtures.database import DatabaseTransactionFixture
from tests.fixtures.files import ODL2APIFilesFixture
from tests.fixtures.odl import ODL2APITestFixture, ODL2TestFixture


Expand Down
15 changes: 1 addition & 14 deletions tests/manager/core/test_opds2_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from palace.manager.sqlalchemy.model.work import Work
from palace.manager.util.datetime_helpers import utc_now
from tests.fixtures.database import DatabaseTransactionFixture
from tests.fixtures.files import FilesFixture
from tests.fixtures.files import OPDS2FilesFixture


class OPDS2Test:
Expand Down Expand Up @@ -91,19 +91,6 @@ class TestOPDS2ImporterFixture:
library: Library


class OPDS2FilesFixture(FilesFixture):
"""A fixture providing access to OPDS2 files."""

def __init__(self):
super().__init__("opds2")


@pytest.fixture()
def opds2_files_fixture() -> OPDS2FilesFixture:
"""A fixture providing access to OPDS2 files."""
return OPDS2FilesFixture()


@pytest.fixture
def opds2_importer_fixture(
db: DatabaseTransactionFixture,
Expand Down
Loading

0 comments on commit f234f88

Please sign in to comment.