Пример #1
0
    def test_check_invalid_price(self):
        no_price = Product(name='Warburtons Gluten Free Tiger Artisan Bloomer',
                           gtin='1234567890123',
                           price=0,
                           sub_category=self.sub_category)
        greater_then_one_million = Product(
            name='Warburtons Gluten Free Tiger Artisan Bloomer',
            gtin='1234567890123',
            price=1000001,
            sub_category=self.sub_category)

        self.assertFalse(ProductGuard().check(no_price), 'No price expected.')
        self.assertFalse(ProductGuard().check(greater_then_one_million),
                         'Price greater than 1 million expected.')
Пример #2
0
    def test_check_no_gtin(self):
        product = Product(name='Warburtons Gluten Free Tiger Artisan Bloomer',
                          gtin=None,
                          price=3.20,
                          sub_category=self.sub_category)

        self.assertFalse(ProductGuard().check(product), 'No GTIN expected')
Пример #3
0
    def test_check_invalid_gtin(self):
        less_than_13 = Product(
            name='Warburtons Gluten Free Tiger Artisan Bloomer',
            gtin='123456789012',
            price=3.20,
            sub_category=self.sub_category)
        greater_than_13 = Product(
            name='Warburtons Gluten Free Tiger Artisan Bloomer',
            gtin='12345678901234',
            price=3.20,
            sub_category=self.sub_category)

        self.assertFalse(ProductGuard().check(less_than_13),
                         'GTIN less than 13 characters expected.')
        self.assertFalse(ProductGuard().check(greater_than_13),
                         'GTIN greater than 13 characters expected.')
Пример #4
0
    def test_check_no_name(self):
        product = Product(name=None,
                          gtin='1234567890123',
                          price=3.20,
                          sub_category=self.sub_category)

        self.assertFalse(ProductGuard().check(product), 'Name not expected.')
Пример #5
0
    def test_check_ok(self):
        product = Product(name='Warburtons Gluten Free Tiger Artisan Bloomer',
                          gtin='1234567890123',
                          price=3.20,
                          sub_category=self.sub_category)

        self.assertTrue(ProductGuard().check(product))
Пример #6
0
    def test_check_invalid_name(self):
        product = Product(name='Wa',
                          gtin='1234567890123',
                          price=3.20,
                          sub_category=self.sub_category)

        self.assertFalse(ProductGuard().check(product),
                         'A short name is expected')
Пример #7
0
    def test_check_invalid_category(self):
        no_category = Product(
            name='Warburtons Gluten Free Tiger Artisan Bloomer',
            gtin='1234567890123',
            price=3.20,
            sub_category=None)

        self.assertFalse(ProductGuard().check(no_category),
                         'No category expected.')
Пример #8
0
    def default_product_with(self, name, gtin, price, sub_category_id):
        sub_category = self.__sub_category_repo.get_by_id(sub_category_id)
        if not sub_category:
            raise ProductRequiresSubCategoryException(sub_category_id)

        # if not gtin_should_be_unique_validation(self.__product_repo, gtin):
        #     raise ProductWithDuplicatedGtinException(gtin)

        product = Product(name=name,
                          gtin=gtin,
                          price=price,
                          sub_category=sub_category)

        guard = ProductGuard()
        if not guard.check(product):
            raise ProductException(guard.get_issues())

        return product
Пример #9
0
    def default_product_to_update(self, _id, name, gtin, price,
                                  sub_category_id):
        sub_category = self.__sub_category_repo.get_by_id(sub_category_id)
        if not sub_category:
            raise ProductRequiresSubCategoryException(sub_category_id)

        product = self.__product_repo.get_by_id(_id)
        if not product:
            raise ProductNotFoundException(_id)

        if gtin != product.gtin:
            if not gtin_should_be_unique_validation(self.__product_repo, gtin):
                raise ProductWithDuplicatedGtinException(gtin)

        product.name = name
        product.gtin = gtin
        product.price = price
        product.sub_category = sub_category

        guard = ProductGuard()
        if not guard.check(product):
            raise ProductException(guard.get_issues())

        return product