def test_foodtomodel_query_if_aliments_exist(): sess = MockDBSession() sess.one = dummy_error_func # raise AttributeError if called food = koreafood.Food('FOOD') food.aliment = {'weight': 0} with pytest.raises(AttributeError): koreafood.food_to_model(sess, food)
def test_foodtomodel_parse_aliment(): def raises_noresult(*args, **kwarg): raise NoResultFound s = MockDBSession() s.one = raises_noresult f = koreafood.Food('FOOD') a = dummy_fuzzy_aliment() # Function `food_to_model` takes argument food.aliment as dictionary of # lists(fixed order), so for testing we should reorder lists as # SUT-expected order. columns = [ 'weight', 'energy', 'moisture', 'protein', 'fat', 'nonfiborous', 'fiber', 'ash', 'calcium', 'potassium', 'retinol_equivalent', 'retinol', 'betacarotene', 'thiamin', 'riboflavin', 'niacin', 'ascobic_acid' ] aliment_list = ['2.0'] # weight=1.0 weight = float(aliment_list[0]) for n in range(1, 1+len(columns[1:])): aliment_list.append('{:,}'.format(getattr(a, columns[n]))) f.aliment = {a.name: aliment_list} result = koreafood.food_to_model(s, f) assert result.name == f.name assert result.category_big == f.category_big assert result.category_small == f.category_small assert len(result.aliments) == 1 assert isinstance(result.aliments[0], model.koreafood.Aliment) for column_name in columns[1:]: c = getattr(result.aliments[0], column_name) assert c == getattr(a, column_name) / weight
def test_foodtomodel_returns_model_food(): s = MockDBSession() f = koreafood.Food('FOOD') result = koreafood.food_to_model(s, f) assert isinstance(result, model.koreafood.Food)
def test_foodtomodel_query_aliment(): expect = model.koreafood.Aliment(name='ALIMENT') s = MockDBSession(expect) f = koreafood.Food('FOOD') f.aliment = {'aliment': expect} result = koreafood.food_to_model(s, f) assert len(result.aliments) == 1 assert result.aliments[0] == expect
def test_foodtomodel_reflects_model_food_without_aliment(): sess = MockDBSession() food = koreafood.Food('FOOD') food.category_big = 'CATEGORY_BIG' food.category_small = 'CATEGORY_SMALL' result = koreafood.food_to_model(sess, food) assert result.name == food.name assert result.category_big == food.category_big assert result.category_small == food.category_small assert not result.aliments
def test_foodtomodel_no_query_if_no_aliments(): sess = MockDBSession() sess.one = dummy_error_func food = koreafood.Food('FOOD') koreafood.food_to_model(sess, food)