예제 #1
0
class ShopTestCase(unittest.TestCase):
    def setUp(self):
        self.user = User()

    def test_delete_shopping_list(self):
        self.user.shopping_lists = {
            'tuesday': ['food', 'fuel'],
            'wednesday': ['clothes', 'tomatoes']
        }
        self.assertEqual(self.user.delete_shopping_list('tuesday'),
                         {'wednesday': ['clothes', 'tomatoes']})

    def test_shopping_list_initialy_empty(self):
        self.assertEqual(self.user.shopping_lists, {})

    def test_create_shopping_list_successfully(self):
        initial_list_count = len(self.user.shopping_lists)
        tuesday_list = self.user.create_shopping_list('Tuesday')
        self.assertTrue(tuesday_list)
        new_list_count = len(self.user.shopping_lists)
        self.assertEqual(new_list_count - initial_list_count, 1)

    def test_updating_non_existing_shopping_list_item(self):
        self.user.shopping_lists = {'tuesday_list': ['food']}
        self.assertEqual(self.user.update_shopping_list_item(
            'tuesday_list', 'flas', 'flat'),
                         'Item not in list',
                         msg='Item not in list')

    def test_create_shopping_list_when_list_already_exists(self):
        self.user.shopping_lists = {'tuesday': ['food']}
        self.assertEqual(self.user.create_shopping_list('tuesday', 'food'),
                         'Shopping List already exists!',
                         msg='Shopping List already exists!')

    def test_update_shopping_list(self):
        self.user.shopping_lists = {'tuesday': ['food']}
        self.assertEqual(
            self.user.update_shopping_list('tuesday', 'tuesday_list'),
            {'tuesday_list': ['food']})

    def test_updating_non_existing_shopping_list(self):
        self.user.shopping_lists = {'Tuesday': ['food']}
        self.assertEqual(self.user.update_shopping_list('Shoe', 'flats'),
                         'list name does not exist here',
                         msg='list name does not exist here')

    def test_update_shopping_list_item(self):
        self.user.shopping_lists = {'food': ['apple']}
        self.assertEqual(
            self.user.update_shopping_list_item('food', 'apple', 'apple'),
            {'food': ['apple']})

    def test_read_shopping_list_items(self):
        self.user.shopping_lists = {'food': ['onions', 'apples']}
        self.assertEqual(self.user.read_list('food'), ['onions', 'apples'])
예제 #2
0
class TestUser(unittest.TestCase):
    """Tests for the User class"""
    def setUp(self):
        self.flavia = User('fnshemerirwe', '*****@*****.**',
                           '1234567890')

    def test_login_with_correct_credentials(self):
        """User can login with correct credentails correct"""
        self.assertTrue(
            self.flavia.login('*****@*****.**', '1234567890'))

    def test_login_with_incorrect_email_correct_password(self):
        """User login is rejected  with incorrect email."""
        self.assertFalse(self.flavia.login('*****@*****.**', '1234567890'),
                         msg="User\
         can login with incorrect email")

    def test_login_with_correct_email_incorrect_password(self):
        """User login is rejected is rejected with incorrect password"""
        self.assertFalse(self.flavia.login('*****@*****.**',
                                           '5236912'),
                         msg="User\
        can login with incorrect password")

    def test_login_with_incorrect_credentials(self):
        """User login is rejected is rejected with incorrect credentials"""
        self.assertFalse(self.flavia.login('*****@*****.**', '5236912'),
                         msg="User\
        can login with incorrect credentials")

    def test_create_shopping_list(self):
        """User can create a shopping list"""
        self.flavia.create_shopping_list('monday')
        self.assertEqual(self.flavia.shopping_lists, ['monday'],
                         msg="User can not \
        create a new shopping list")

    def test_create_shopping_list_with_non_empty_shopping_lists(self):
        """User can create shopping lists even with extising shopping lists"""
        self.flavia.shopping_lists.append('monday')
        self.flavia.shopping_lists.append('tuesday')
        self.flavia.create_shopping_list('wednesday')
        self.assertEqual(self.flavia.shopping_lists,
                         ['monday', 'tuesday', 'wednesday'],
                         msg="User can not create a new shopping \
                         list after creating a previous one")

    def test_delete_shopping_list_from_empty_shopping_lists(self):
        """User can not delete shopping list without creating any shopping list"""
        self.assertRaises(ValueError, self.flavia.delete_shopping_list,
                          'monday')

    def test_delete_shopping_list_from_shopping_lists(self):
        """User can delete any created shopping list"""
        self.flavia.shopping_lists.append('monday')
        self.flavia.shopping_lists.append('tuesday')
        self.flavia.delete_shopping_list('monday')
        self.assertEqual(self.flavia.shopping_lists, ['tuesday'],
                         msg="User can not delete a shopping list \
                         that is in shopping list")

    def test_delete_non_existing_shopping_list_from_shopping_lists(self):
        """User can not delete a shoping list he did not create"""
        self.flavia.shopping_lists.append('monday')
        self.flavia.shopping_lists.append('tuesday')
        self.assertRaises(ValueError, self.flavia.delete_shopping_list,
                          'wednesday')

    def test_view_empty_shopping_lists(self):
        """User View empty shopping lists"""
        self.assertEqual(self.flavia.view_shopping_lists(), [],
                         msg="Can not display empty shopping list")

    def test_view_shopping_lists_created(self):
        """User can view all shopping lists created"""
        self.flavia.shopping_lists.append('monday')
        self.flavia.shopping_lists.append('tuesday')
        self.flavia.shopping_lists.append('wednesday')
        self.flavia.shopping_lists.append('thursday')
        self.assertEqual(self.flavia.view_shopping_lists(),
                         ['monday', 'tuesday', 'wednesday', 'thursday'],
                         msg='Can not display shopping lists correctly')