コード例 #1
0
 def test_utils_store_entities_with_parent_missing(self):
     from organicseeds_webshop_api import utils
     from organicseeds_webshop_api import models
     self.testdata["items"][0]["parent_id"] = "wrong_id"
     self.testdata["items"][0]["id"] = "itemka32"
     parent = models.ItemGroup()
     self.app_root["item_groups"]["karotten"] = parent
     models.ItemGroup().__children__
     utils.store(self.testdata["items"], models.Item, "items", self.request)
     item = self.app_root["items"]["itemka32"]
     assert item.__parent__ is None
     assert parent.__children__ == []
コード例 #2
0
 def test_models_get_url_path_with_parent(self):
     from organicseeds_webshop_api import models
     child = models.Item({"id": "child",
                          "url_slug": {"default": "child_slug"}})
     parent = models.ItemGroup({"id": "parent",
                                "url_slug": {"default": "parent_slug",
                                             "fr": "parent_slug_fr"}})
     child.__parent__ = parent
     child_path = models._get_url_path(child, "fr")
     assert child_path == "/parent_slug_fr/child_slug"
コード例 #3
0
 def test_utils_delete_entities_with_parents(self):
     from organicseeds_webshop_api import utils
     from organicseeds_webshop_api import models
     item = utils.store(self.testdata["items"], models.Item, "items",
                        self.request)[0]
     parent = models.ItemGroup()
     item.__parent__ = parent
     parent.__children__.append(item)
     utils.delete(self.testdata["items"], "items", self.request)
     assert item.__parent__ is None
     assert item not in parent.__children__
コード例 #4
0
    def test_utils_store_entities_with_quality(self):
        from organicseeds_webshop_api import utils
        from organicseeds_webshop_api import models
        quality = {"id": "quality"}
        parent = models.ItemGroup()
        parent.from_appstruct({"qualities": [quality]})
        self.app_root["item_groups"]["parent"] = parent

        self.testdata["items"][0]["parent_id"] = "parent"
        self.testdata["items"][0]["quality_id"] = "quality"
        utils.store(self.testdata["items"], models.Item, "items", self.request)
        item = self.app_root["items"]["itemka32"]
        assert item.quality is quality
コード例 #5
0
    def test_models_item_group_to_data_inherited_attributes(self):
        from organicseeds_webshop_api import models
        child = models.ItemGroup()
        parent1 = models.Category()
        parent2 = models.Category()
        child.__parent__ = parent1
        parent1.__parent__ = parent2
        child["text_attributes"] = [{"id": 1, "test": 1}]
        parent2["text_attributes"] = [{"id": 1, "text": 2}]
        parent2["bool_attributes"] = [{"id": 2}]

        assert child.to_data()["text_attributes"] == [{"id": 1, "test": 1}]
        assert child.to_data()["bool_attributes"] == [{"id": 2}]
コード例 #6
0
    def test_utils_store_entities_with_quality_wrong_id(self):
        from organicseeds_webshop_api import utils
        from organicseeds_webshop_api import models
        from organicseeds_webshop_api.exceptions import _400
        quality = {"id": "quality"}
        parent = models.ItemGroup()
        parent.from_appstruct({"qualities": [quality]})
        self.app_root["item_groups"]["parent"] = parent

        self.testdata["items"][0]["parent_id"] = "parent"
        self.testdata["items"][0]["wrong_quality_id"] = "quality"
        with pytest.raises(_400):
            utils.store(self.testdata["items"], models.Item, "items",
                        self.request)
コード例 #7
0
    def test_models_data_to_data_with_url_path(self):
        from organicseeds_webshop_api import models

        data = models.Data()
        assert data.to_data() == {}

        appstruct = {"url_slug": {"default": "slug"}}
        data = models.Data(appstruct)
        assert data.to_data("default")["url_path"] == u"/slug"
        category = models.Category(appstruct)
        assert category.to_data("default")["url_path"] == u"/slug"
        item_group = models.ItemGroup(appstruct)
        assert item_group.to_data("default")["url_path"] == u"/slug"
        item = models.Item(appstruct)
        assert item.to_data("default")["url_path"] == u"/slug"