def test__when_user_has_allergies__return_dishes_without_allergens(self):
        user = {'username': '******', 'has_allergies': True}
        expected_menu_length = 1

        personalized_menu = personalize_menu(self.menu, user)

        assert len(personalized_menu) == expected_menu_length
    def test__when_user_dont_have_allergies__return_all_dishes(self):
        user = {'username': '******', 'has_allergies': False}
        expected_menu_length = 2

        personalized_menu = personalize_menu(self.menu, user)

        assert len(personalized_menu) == expected_menu_length
Esempio n. 3
0
def test__personalize_menu__when_user_has_allergies__return_dishes_without_allergens():
    user = {'username': '******', 'has_allergies': True}
    menu = [
        {'name': 'dish without allergens', 'allergens': []},
        {'name': 'dish with allergens', 'allergens': ['eggs', 'milk']}
    ]
    personalized_menu = personalize_menu(menu, user)
    assert len(personalized_menu) == 1
Esempio n. 4
0
def test__personalize_menu():
    menu = [{
        'name': 'dish without allergens',
        'allergens': []
    }, {
        'name': 'dish with allergens',
        'allergens': ['eggs', 'milk']
    }]

    personalized_menu = personalize_menu(menu, {
        'username': '******',
        'has_allergies': True
    })
    assert len(personalized_menu) == 1

    personalized_menu = personalize_menu(menu, {
        'username': '******',
        'has_allergies': False
    })
    assert len(personalized_menu) == 2
Esempio n. 5
0
def test__personalize_menu__parametrized(user, expected_menu_length):
    menu = [{
        'name': 'dish without allergens',
        'allergens': []
    }, {
        'name': 'dish with allergens',
        'allergens': ['eggs', 'milk']
    }]

    personalized_menu = personalize_menu(menu, user)

    assert len(personalized_menu) == expected_menu_length
def test__given_menu_contains_dishes_with_allergens__when_user_has_alergies__then_resulting_menu_should_contain_only_dishes_without_allergens(
):
    user = {'username': '******', 'has_allergies': True}
    menu = [{
        'name': 'dish without allergens',
        'allergens': []
    }, {
        'name': 'dish with allergens',
        'allergens': ['eggs', 'milk']
    }]
    personalized_menu = personalize_menu(menu, user)
    assert len(personalized_menu) == 1
Esempio n. 7
0
def test__personalize_menu__when_user_has_allergies__return_dishes_without_allergens(
):
    # arrange statements:
    user = {'username': '******', 'has_allergies': True}
    menu = [{
        'name': 'dish without allergens',
        'allergens': []
    }, {
        'name': 'dish with allergens',
        'allergens': ['eggs', 'milk']
    }]
    expected_menu_length = 1

    # act statement:
    personalized_menu = personalize_menu(menu, user)

    # assert statements:
    assert len(personalized_menu) == expected_menu_length
def test__personalize_menu__with_logic():
    users = [{
        'username': '******',
        'has_allergies': True
    }, {
        'username': '******',
        'has_allergies': False
    }]
    menu = [{
        'name': 'dish without allergens',
        'allergens': []
    }, {
        'name': 'dish with allergens',
        'allergens': ['eggs', 'milk']
    }]

    for user in users:
        personalized_menu = personalize_menu(menu, user)
        if user['has_allergies']:
            expected_menu_length = 1
        else:
            expected_menu_length = 2

        assert len(personalized_menu) == expected_menu_length
    def test__when_user_dont_have_allergies_flag__raise_exception(self):
        user = {'username': '******'}

        with pytest.raises(KeyError):
            personalize_menu(self.menu, user)
Esempio n. 10
0
    def test__when_user_has_allergies__return_dishes_without_allergens(self):
        personalized_menu = personalize_menu(self.menu, self.user)

        assert len(personalized_menu) == self.expected_menu_length