Skip to content

Commit

Permalink
Fixed test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
acuriel committed Sep 2, 2024
1 parent 8bd6e9e commit 9a836db
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
4 changes: 1 addition & 3 deletions ninja/ordering_schema.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from abc import ABC, abstractmethod
from typing import Any, List, TypeVar

from django.db.models import QuerySet
Expand All @@ -9,7 +8,7 @@
QS = TypeVar("QS", bound=QuerySet)


class OrderingBaseSchema(Schema, ABC):
class OrderingBaseSchema(Schema):
order_by: List[str] = []

class Config(Schema.Config):
Expand All @@ -28,7 +27,6 @@ def validate_order_by_field(cls, value: List[str]) -> List[str]:

return value

@abstractmethod
def sort(self, elements: Any) -> Any:
raise NotImplementedError

Expand Down
9 changes: 9 additions & 0 deletions tests/test_ordering_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from django.db.models import QuerySet

from ninja import OrderingSchema
from ninja.ordering_schema import OrderingBaseSchema


class FakeQS(QuerySet):
Expand Down Expand Up @@ -83,3 +84,11 @@ def test_sort__should_call_order_by_on_queryset_with_expected_args():
queryset = ordering_schema.sort(queryset)
assert queryset.is_ordered
assert queryset.order_by_args == tuple(order_by_value)


def test_sort__should_raise_not_implemented_error():
class DummyOrderingSchema(OrderingBaseSchema):
pass

with pytest.raises(NotImplementedError):
DummyOrderingSchema().sort(FakeQS())

0 comments on commit 9a836db

Please sign in to comment.