Esempio n. 1
0
    def test_check_no_url(self):
        guard = ProductSupermarketGuard()
        product_supermarket = ProductSupermarket(product=self.product,
                                                 supermarket=self.supermarket,
                                                 price_update_url=None)

        self.assertFalse(guard.check(product_supermarket),
                         'No URL is expected')
Esempio n. 2
0
    def test_check_no_supermarket(self):
        guard = ProductSupermarketGuard()
        product_supermarket = ProductSupermarket(
            product=self.product,
            supermarket=None,
            price_update_url='http://www.mysupermarket.co.uk')

        self.assertFalse(guard.check(product_supermarket),
                         'No supermarket is expected')
Esempio n. 3
0
 def setUp(self):
     self.category = Category('Breads')
     self.sub_category = SubCategory('Gluten Free Breads',
                                     category=self.category)
     product = Product(name='Warburtons Gluten Free Tiger Artisan Bloomer',
                       gtin='1234567890123',
                       price=3.20,
                       sub_category=self.sub_category)
     supermarket = SupermarketVO(_id='e6981d6ea68b4cc682bbb03139ef679e',
                                 name='MySupermarket',
                                 is_active=True)
     self.product_supermarket = ProductSupermarket(
         product=product,
         supermarket=supermarket,
         price_update_url='http://www.mysupermarket.co.uk')
     self.product_supermarket_with_id = ProductSupermarket(
         product=product,
         supermarket=supermarket,
         price_update_url='http://www.mysupermarket.co.uk',
         _id='fdf88acb94984a859bd342c05ead9beb')
Esempio n. 4
0
class ProductSupermarketTest(TestCase):
    def setUp(self):
        self.category = Category('Breads')
        self.sub_category = SubCategory('Gluten Free Breads',
                                        category=self.category)
        product = Product(name='Warburtons Gluten Free Tiger Artisan Bloomer',
                          gtin='1234567890123',
                          price=3.20,
                          sub_category=self.sub_category)
        supermarket = SupermarketVO(_id='e6981d6ea68b4cc682bbb03139ef679e',
                                    name='MySupermarket',
                                    is_active=True)
        self.product_supermarket = ProductSupermarket(
            product=product,
            supermarket=supermarket,
            price_update_url='http://www.mysupermarket.co.uk')
        self.product_supermarket_with_id = ProductSupermarket(
            product=product,
            supermarket=supermarket,
            price_update_url='http://www.mysupermarket.co.uk',
            _id='fdf88acb94984a859bd342c05ead9beb')

    def test_create_product_supermarket(self):
        self.assertIsNotNone(self.product_supermarket)

    def test_create_product_supermarket_with_id(self):
        self.assertIsNotNone(self.product_supermarket_with_id)
        self.assertEqual(self.product_supermarket_with_id.id,
                         'fdf88acb94984a859bd342c05ead9beb')

    def test_product_supermarket_as_json(self):
        expected = {
            'id': self.product_supermarket.id,
            'price_update_url': 'http://www.mysupermarket.co.uk',
            'is_active_tracking': False,
            'current_price': 0,
            'last_update': None,
            'product': {
                'id': self.product_supermarket.product.id,
                'name': 'Warburtons Gluten Free Tiger Artisan Bloomer'
            },
            'supermarket': {
                'id': self.product_supermarket.supermarket.id,
                'name': 'MySupermarket'
            },
        }
        self.assertEqual(self.product_supermarket.as_json(), expected)
Esempio n. 5
0
 def setUp(self):
     self.product_repo = mock.Mock()
     self.supermarket_dao = mock.Mock()
     self.product_supermarket_repo = mock.Mock()
     self.product_supermarket_factory = ProductSupermarketFactory(
         self.product_repo, self.supermarket_dao,
         self.product_supermarket_repo)
     self.category = Category('Breads')
     self.sub_category = SubCategory('Gluten Free Breads',
                                     category=self.category)
     self.product = Product(
         name='Warburtons Gluten Free Tiger Artisan Bloomer',
         gtin='1234567890123',
         price=3.20,
         sub_category=self.sub_category)
     self.supermarket = SupermarketVO(
         _id='e6981d6ea68b4cc682bbb03139ef679e',
         name='MySupermarket',
         is_active=True)
     self.existing_product_supermarket = ProductSupermarket(
         product=self.product,
         supermarket=self.supermarket,
         price_update_url='http://www.mysupermarket.co.uk')
Esempio n. 6
0
    def get_supermarkets_to_tracking_product(self, product_id):
        product = ProductRepository().get_by_id(product_id)
        if not product:
            raise ProductNotFoundException(product_id)

        active_supermarkets = SupermarketDAO().get_actives()
        product_supermarkets = super().session.query(
            ProductSupermarket).filter_by(product_id=product_id).all()

        supermarkets_to_track = []
        for active_supermarket in active_supermarkets:
            found = False
            for product_supermarket in product_supermarkets:
                if product_supermarket.supermarket == active_supermarket:
                    supermarkets_to_track.append(product_supermarket)
                    found = True
            if not found:
                supermarkets_to_track.append(
                    ProductSupermarket(product=product,
                                       supermarket=active_supermarket,
                                       price_update_url=None))

        return supermarkets_to_track
Esempio n. 7
0
 def __new_product_supermarket(self, product, supermarket,
                               price_update_url):
     return ProductSupermarket(product=product,
                               supermarket=supermarket,
                               price_update_url=price_update_url)
Esempio n. 8
0
 def test_check_ok(self):
     product_supermarket = ProductSupermarket(
         product=self.product,
         supermarket=self.supermarket,
         price_update_url='http://www.mysupermarket.co.uk')
     self.assertTrue(ProductSupermarketGuard().check(product_supermarket))