Пример #1
0
    def test_owner_add_items(self):  # 3.1
        # setup owner
        Bridge.register_user('username', 'password')
        Bridge.login('username', 'password')
        Bridge.open_shop('username', 'shop_name')

        # owner add items
        # item is = 1
        is_added = Bridge.add_item_to_shop(shop_name='shop_name',
                                           item_name='item_name1',
                                           item_category='item_category',
                                           keywords='keywords',
                                           price=10,
                                           quantity=100,
                                           username='******',
                                           kind='regular',
                                           url=None,
                                           item_rating=0,
                                           sum_of_ranking=0,
                                           num_of_reviews=0)
        self.assertTrue(is_added)
        # item is = 2
        is_added = Bridge.add_item_to_shop(shop_name='shop_name',
                                           item_name='item_name2',
                                           item_category='item_category',
                                           keywords='keywords',
                                           price=10,
                                           quantity=100,
                                           username='******',
                                           kind='regular',
                                           url=None,
                                           item_rating=0,
                                           sum_of_ranking=0,
                                           num_of_reviews=0)
        self.assertTrue(is_added)
        # item is = 3
        is_added = Bridge.add_item_to_shop(shop_name='shop_name',
                                           item_name='item_name3',
                                           item_category='item_category',
                                           keywords='keywords',
                                           price=10,
                                           quantity=100,
                                           username='******',
                                           kind='regular',
                                           url=None,
                                           item_rating=0,
                                           sum_of_ranking=0,
                                           num_of_reviews=0)
        self.assertTrue(is_added)

        is_edited = Bridge.edit_item_name(item_id=1,
                                          username='******',
                                          item_name='NEW NAME')
        self.assertTrue(is_edited)
Пример #2
0
    def test_cart_items(self):  # 1.5
        # open shop
        Bridge.register_user('username', 'password')
        Bridge.login('username', 'password')
        Bridge.open_shop('username', 'shop_name')
        # item is = 1
        Bridge.add_item_to_shop(shop_name='shop_name',
                                item_name='item_name1',
                                item_category='item_category',
                                keywords='keywords',
                                price=10,
                                quantity=100,
                                username='******',
                                kind='regular',
                                url=None,
                                item_rating=0,
                                sum_of_ranking=0,
                                num_of_reviews=0)
        # item is = 2
        Bridge.add_item_to_shop(shop_name='shop_name',
                                item_name='item_name2',
                                item_category='item_category',
                                keywords='keywords',
                                price=10,
                                quantity=100,
                                username='******',
                                kind='regular',
                                url=None,
                                item_rating=0,
                                sum_of_ranking=0,
                                num_of_reviews=0)
        # item is = 3
        Bridge.add_item_to_shop(shop_name='shop_name',
                                item_name='item_name3',
                                item_category='item_category',
                                keywords='keywords',
                                price=10,
                                quantity=100,
                                username='******',
                                kind='regular',
                                url=None,
                                item_rating=0,
                                sum_of_ranking=0,
                                num_of_reviews=0)
        username = '******'
        access_token = hashlib.md5(username.encode()).hexdigest()
        Consumer.loggedInUsers[access_token] = username
        Consumer.loggedInUsersShoppingCart[access_token] = []
        Bridge.buy_item(login_token=access_token,
                        username='******',
                        shop_name='shop_name',
                        item_id=1,
                        quantity=10)
        self.assertTrue(
            Bridge.is_item_bought(login_token=access_token, item_id=1))

        Bridge.buy_item(login_token=access_token,
                        username='******',
                        shop_name='shop_name',
                        item_id=2,
                        quantity=10)
        self.assertTrue(
            Bridge.is_item_bought(login_token=access_token, item_id=2))

        Bridge.buy_item(login_token=access_token,
                        username='******',
                        shop_name='shop_name',
                        item_id=3,
                        quantity=10)
        self.assertTrue(
            Bridge.is_item_bought(login_token=access_token, item_id=3))

        is_bought = Bridge.buy_item(login_token=access_token,
                                    username='******',
                                    shop_name='shop_name',
                                    item_id=4,
                                    quantity=10)
        self.assertFalse(is_bought)

        is_bought = Bridge.buy_item(login_token=access_token,
                                    username='******',
                                    shop_name='shop_name',
                                    item_id=3,
                                    quantity=150)
        self.assertFalse(is_bought)

        # remove item from cart
        is_removed = Bridge.remove_item_from_cart(username='******',
                                                  item_id=1)
        self.assertTrue(is_removed)
Пример #3
0
    def test_buy(self):  # 1.7
        # setup shop
        Bridge.register_user('ownerUser', 'password')
        Bridge.login('ownerUser', 'password')
        Bridge.open_shop('ownerUser', 'my_shop')
        Bridge.register_user('clientUser', 'password')
        Bridge.search_shop('my_shop')

        # add items to shop
        Bridge.add_item_to_shop(shop_name='my_shop',
                                item_name='item_name1',
                                item_category='item_category',
                                keywords='keywords',
                                price=10,
                                quantity=10,
                                username='******',
                                kind='regular',
                                url=None,
                                item_rating=0,
                                sum_of_ranking=0,
                                num_of_reviews=0)
        Bridge.add_item_to_shop(shop_name='my_shop',
                                item_name='item_name2',
                                item_category='item_category',
                                keywords='keywords',
                                price=10,
                                quantity=20,
                                username='******',
                                kind='regular',
                                url=None,
                                item_rating=0,
                                sum_of_ranking=0,
                                num_of_reviews=0)
        Bridge.add_item_to_shop(shop_name='my_shop',
                                item_name='item_name3',
                                item_category='item_category',
                                keywords='keywords',
                                price=10,
                                quantity=30,
                                username='******',
                                kind='regular',
                                url=None,
                                item_rating=0,
                                sum_of_ranking=0,
                                num_of_reviews=0)
        Bridge.add_item_to_shop(shop_name='my_shop',
                                item_name='item_name4',
                                item_category='item_category',
                                keywords='keywords',
                                price=10,
                                quantity=40,
                                username='******',
                                kind='regular',
                                url=None,
                                item_rating=0,
                                sum_of_ranking=0,
                                num_of_reviews=0)
        Bridge.add_item_to_shop(shop_name='my_shop',
                                item_name='item_name5',
                                item_category='item_category',
                                keywords='keywords',
                                price=10,
                                quantity=50,
                                username='******',
                                kind='regular',
                                url=None,
                                item_rating=0,
                                sum_of_ranking=0,
                                num_of_reviews=0)

        # add items to cart
        username = '******'
        access_token = hashlib.md5(username.encode()).hexdigest()
        Consumer.loggedInUsers[access_token] = username
        Consumer.loggedInUsersShoppingCart[access_token] = []
        Bridge.buy_item(access_token, 'clientUser', 'my_shop', 1, 10)
        Bridge.buy_item(access_token, 'clientUser', 'my_shop', 2, 10)
        Bridge.buy_item(access_token, 'clientUser', 'my_shop', 3, 10)
        Bridge.buy_item(access_token, 'clientUser', 'my_shop', 4, 10)
        Bridge.buy_item(access_token, 'clientUser', 'my_shop', 5, 10)

        # check total cost is calculated right
        self.assertEqual(Bridge.get_cart_cost(access_token), 500)

        # buy!
        self.assertTrue(Bridge.pay_cart(access_token))

        # check quantity in store changed
        self.assertEqual(Bridge.quantity_in_store(1), 0)
        self.assertEqual(Bridge.quantity_in_store(2), 10)
        self.assertEqual(Bridge.quantity_in_store(3), 20)
        self.assertEqual(Bridge.quantity_in_store(4), 30)
        self.assertEqual(Bridge.quantity_in_store(5), 40)
        # alternative scenario - item quantity is not enough
        self.assertFalse(
            Bridge.buy_item(access_token, 'clientUser', 'my_shop', 1, 10))

        # alternative scenario - added items, but another user already bought them
        username2 = 'clientUser2'
        access_token2 = hashlib.md5(username2.encode()).hexdigest()
        Consumer.loggedInUsers[access_token2] = username2
        Consumer.loggedInUsersShoppingCart[access_token2] = []
        Bridge.register_user('clientUser2', 'password')
        Bridge.buy_item(access_token, 'clientUser', 'my_shop', 2, 10)
        Bridge.buy_item(access_token2, 'clientUser2', 'my_shop', 2, 10)

        self.assertTrue(isinstance(Bridge.pay_cart(access_token2), list))
        self.assertTrue(isinstance(Bridge.pay_cart(access_token), str))