Skip to content

Commit

Permalink
Finish renaming from category to catalogue
Browse files Browse the repository at this point in the history
  • Loading branch information
timsavage committed Oct 3, 2023
1 parent 743d98e commit 55422e5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
20 changes: 10 additions & 10 deletions oscar_odin/mappings/catalogue.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from oscar.core.loading import get_class, get_model

from .. import resources
from ..resources.category import Structure
from ..resources.catalogue import Structure
from ._common import map_queryset

__all__ = (
Expand All @@ -34,7 +34,7 @@ class ProductImageToResource(odin.Mapping):
"""Map from an image model to a resource."""

from_obj = ProductImageModel
to_obj = resources.category.Image
to_obj = resources.catalogue.Image

@odin.map_field
def original(self, value: ImageFieldFile) -> str:
Expand All @@ -44,10 +44,10 @@ def original(self, value: ImageFieldFile) -> str:


class CategoryToResource(odin.Mapping):
"""Map from a category model to a resource."""
"""Map from a catalogue model to a resource."""

from_obj = CategoryModel
to_obj = resources.category.Category
to_obj = resources.catalogue.Category

@odin.assign_field
def meta_title(self) -> str:
Expand All @@ -66,14 +66,14 @@ class ProductClassToResource(odin.Mapping):
"""Map from a product class model to a resource."""

from_obj = ProductClassModel
to_obj = resources.category.ProductClass
to_obj = resources.catalogue.ProductClass


class ProductToResource(odin.Mapping):
"""Map from a product model to a resource."""

from_obj = ProductModel
to_obj = resources.category.Product
to_obj = resources.catalogue.Product

@odin.map_field
def structure(self, value: str) -> Structure:
Expand All @@ -91,7 +91,7 @@ def meta_title(self) -> str:
return self.source.get_meta_title()

@odin.assign_field(to_list=True)
def images(self) -> List[resources.category.Image]:
def images(self) -> List[resources.catalogue.Image]:
"""Map related image."""
items = self.source.get_all_images()
return map_queryset(ProductImageToResource, items, context=self.context)
Expand Down Expand Up @@ -143,7 +143,7 @@ def attributes(self) -> Dict[str, Any]:
}

@odin.assign_field
def children(self) -> Tuple[Optional[List[resources.category.Product]]]:
def children(self) -> Tuple[Optional[List[resources.catalogue.Product]]]:
"""Children of parent products."""

if self.context.get("include_children", False) and self.source.is_parent:
Expand Down Expand Up @@ -203,7 +203,7 @@ def product_to_resource(
user: Optional[AbstractUser] = None,
include_children: bool = False,
**kwargs,
) -> Union[resources.category.Product, Iterable[resources.category.Product]]:
) -> Union[resources.catalogue.Product, Iterable[resources.catalogue.Product]]:
"""Map a product model to a resource.
This method will except either a single product or an iterable of product
Expand All @@ -229,7 +229,7 @@ def product_queryset_to_resources(
user: Optional[AbstractUser] = None,
include_children: bool = False,
**kwargs,
) -> Iterable[resources.category.Product]:
) -> Iterable[resources.catalogue.Product]:
"""Map a queryset of product models to a list of resources.
The request and user are optional, but if provided they are supplied to the
Expand Down
10 changes: 5 additions & 5 deletions tests/mappings/test_catalogue.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.test import TestCase
from oscar.core.loading import get_model

from oscar_odin.mappings import category
from oscar_odin.mappings import catalogue

Product = get_model("catalogue", "Product")

Expand All @@ -12,29 +12,29 @@ class TestProduct(TestCase):
def test_mapping__basic_model_to_resource(self):
product = Product.objects.first()

actual = category.product_to_resource(product)
actual = catalogue.product_to_resource(product)

self.assertEqual(product.title, actual.title)

def test_mapping__basic_product_with_out_of_stock_children(self):
product = Product.objects.get(id=1)

actual = category.product_to_resource(product)
actual = catalogue.product_to_resource(product)

self.assertEqual(product.title, actual.title)

def test_mapping__where_is_a_parent_product_do_not_include_children(self):
product = Product.objects.get(id=8)

actual = category.product_to_resource(product)
actual = catalogue.product_to_resource(product)

self.assertEqual(product.title, actual.title)
self.assertIsNone(actual.children)

def test_mapping__where_is_a_parent_product_include_children(self):
product = Product.objects.get(id=8)

actual = category.product_to_resource(product, include_children=True)
actual = catalogue.product_to_resource(product, include_children=True)

self.assertEqual(product.title, actual.title)
self.assertIsNotNone(actual.children)
Expand Down
2 changes: 1 addition & 1 deletion tests/resources/test_catalogue.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@

class TestProduct(TestCase):
def test_init(self):
target = resources.category.Product()
target = resources.catalogue.Product()

self.assertIsNotNone(target)

0 comments on commit 55422e5

Please sign in to comment.