def test_get_calls_item_model(self): with mock.patch('genie.wishlist.models.wishlist.ItemModel.get' ) as mocked_item, mock.patch( 'genie.wishlist.models.wishlist.BaseModel.get'): WishlistModel.get(id='a') mocked_item.assert_called_with(wishlist_id='a')
async def test_get_calls_cache_and_model(self, item_model): with mock.patch.object(Cache, 'get') as mocked_cache: wishlist_model = WishlistModel(id='a', items=[item_model]) mocked_cache.return_value = wishlist_model.to_dict() wishlist = await Wishlist('a').get() mocked_cache.assert_called_with('a') wishlist == wishlist_model
def test_save_calls_item_save_and_base_save(self, item_model, customer_model): wishlist = WishlistModel(id='a', items=[item_model], customer=customer_model) with mock.patch('genie.wishlist.models.wishlist.BaseModel.save' ) as mocked_save: with mock.patch.object(item_model, 'save') as mocked_item_save: wishlist.save() assert mocked_save.called assert mocked_item_save.called
def test_remove_item_should_decrement_items(self, item_model): item_model_a = item_model item_model_b = ItemModel( sku='82727b28-d6b3-813c-5139-50d3b28c16d4-b', title='Alcool em gel', image_url=('http://challenge-api.luizalabs.com/images/' '82727b28-d6b3-813c-5139-50d3b28c16d4.jpg'), price=Decimal('34.9'), brand='epoch magia', review_score=4.3) wishlist = WishlistModel(id='a', items=[item_model_a, item_model_b]) wishlist.remove_item(sku=item_model_a.sku) assert wishlist.items == [item_model_b]
async def test_get_calls_catalog_and_model(self, mocked_catalog_backend, item_model): with mocked_catalog_backend as mocked_catalog: with mock.patch('genie.wishlist.models.wishlist.WishlistModel.get' ) as mocked_model: wishlist = Wishlist('a') with mock.patch.object(wishlist, 'save'): mocked_model.return_value = WishlistModel( id='a', items=[item_model]) await wishlist.get() mocked_catalog.assert_called_with(sku=item_model.sku) mocked_model.assert_called_with(id='a')
def test_add_item_should_increment_items(self, item_model): wishlist = WishlistModel(id='a') assert wishlist.items is None wishlist.add_item(item_model) assert wishlist.items == [item_model] wishlist.add_item(item_model) assert wishlist.items == [item_model, item_model]
def test_save_without_customer_raises_customer_error(self, item_model): wishlist = WishlistModel(id='a', items=[item_model]) with pytest.raises(CustomerNotSet): wishlist.save()
def test_from_dict_returns_model_instance(self): wishlist = WishlistModel.from_dict(data={'id': 'a'}) assert isinstance(wishlist, WishlistModel) assert wishlist.id == 'a'