def test_positive_add_item_in_shopping_list(self, additional_items): shopping_items = [ generate_shopping_item() for _ in range(generate_number(max=3)) ] shopping_list = generate_shopping_list(items=shopping_items) code, data = self.client.create_shopping_list(**shopping_list) shopping_list_id = data['id'] assert code == STATUS_CODES.ok code, add_item_data = self.client.add_item_to_shopping_list( shopping_list_id, items=additional_items) assert code == STATUS_CODES.ok sort_fn = lambda it: tuple( it.get(key) for key in ['name', 'quantity', 'comment']) checks.eq_list(add_item_data.get('items', []), additional_items or [], sorted_fn=sort_fn) assert not add_item_data['combinedItems'] assert not add_item_data['recipes'] code, sl_data = self.client.get_shopping_lists() assert code == STATUS_CODES.ok assert len(sl_data) == 1 interested_shopping_list = sl_data[0] assert interested_shopping_list['id'] == shopping_list_id expected_items = (shopping_list['items'] or []) + (additional_items or []) assert interested_shopping_list['itemsCount'] == len(expected_items)
def test_negative_create_shopping_list_with_max_items(self): shopping_list = generate_shopping_list( items=[generate_shopping_item() for i in range(101)]) code, data = self.client.create_shopping_list(**shopping_list) assert code == STATUS_CODES.bad assert data['code'] assert MSG_MAX_ITEM_DESCRIPTION_ERROR in data['description']
def test_negative_add_item_to_empty_shopping_list_more_than_max(self): additional_items = [ generate_shopping_item() for _ in range(MAX_ITEM_IN_LIST + 1) ] shopping_list = generate_shopping_list(items=[]) code, data = self.client.create_shopping_list(**shopping_list) assert code == STATUS_CODES.ok shopping_list_id = data['id'] code, add_item_data = self.client.add_item_to_shopping_list( shopping_list_id, items=additional_items) assert code == STATUS_CODES.bad assert add_item_data['code'] assert MSG_MAX_ITEM_DESCRIPTION_ERROR in add_item_data['description']
def test_positive_get_shopping_list(self): items = [ generate_shopping_item() for i in range(generate_number(0, 1)) ] shopping_list = generate_shopping_list(items=items) code, sl_data = self.client.create_shopping_list(**shopping_list) assert code == STATUS_CODES.ok code, data = self.client.get_shopping_lists() assert code == STATUS_CODES.ok assert len(data) == 1 shopping_list = data[0] assert shopping_list['id'] == sl_data['id'] assert shopping_list['itemsCount'] == len(items)
def test_negative_delete_items_more_than_max(self): shopping_list_id, items = self.prepare_shopping_list(MAX_ITEM_IN_LIST) additional_items = [generate_shopping_item()] code, add_item_data = self.client.add_item_to_shopping_list(shopping_list_id, items=additional_items) assert code == STATUS_CODES.ok expected_items = items + add_item_data['items'] code, add_item_data = self.client.add_item_to_shopping_list( shopping_list_id, items=[{'id': it['id'], 'deleted': True} for it in expected_items] ) assert code == STATUS_CODES.bad assert add_item_data['code'] assert MSG_MAX_ITEM_DESCRIPTION_ERROR in add_item_data['description'] code, data = self.client.get_shopping_lists() assert code == STATUS_CODES.ok assert len(expected_items) == data[0]['itemsCount']
def test_negative_add_item_to_not_exist_shopping_list(self): code, data = self.client.add_item_to_shopping_list( '106faac3fe6014c48b5ac931a77f111162a', items=[generate_shopping_item()]) assert code == STATUS_CODES.bad assert data['code'] == 'shoppingList.notFound'
import pytest from utils import run_test, checks from utils.generate import generate_number from utils.common import STATUS_CODES, get_params_argv from actions_api.whisk import get_auth_client, generate_shopping_item, generate_shopping_list, MAX_ITEM_IN_LIST, \ MSG_MAX_ITEM_DESCRIPTION_ERROR ITEMS_FOR_PARAMETRIZE = get_params_argv({ 'zero_items': [], 'without_items_field': None, 'one_item': [generate_shopping_item()], 'max_item': [generate_shopping_item() for i in range(MAX_ITEM_IN_LIST)], }) class TestAddItemInShoppingList: def setup(self): self.client = get_auth_client() @pytest.mark.parametrize('additional_items', **ITEMS_FOR_PARAMETRIZE) def test_positive_add_item_in_shopping_list(self, additional_items): shopping_items = [ generate_shopping_item() for _ in range(generate_number(max=3)) ] shopping_list = generate_shopping_list(items=shopping_items) code, data = self.client.create_shopping_list(**shopping_list) shopping_list_id = data['id'] assert code == STATUS_CODES.ok code, add_item_data = self.client.add_item_to_shopping_list(
def prepare_shopping_list(self, count_of_product=2): items = [generate_shopping_item() for i in range(count_of_product)] shopping_list = generate_shopping_list(items=items) code, sl_data = self.client.create_shopping_list(**shopping_list) assert code == STATUS_CODES.ok return sl_data['id'], sl_data['items']