Exemplo n.º 1
0
    def build_round(self, round_size=15):
        self.test_initiator = TestUser("Test Initiator", Americano())
        test_round = Round(self.test_initiator)
        for idx in range(round_size):
            usr = TestUser(f"Round User {idx}", Americano())
            test_round.add(usr, self.build_order())

        return test_round
Exemplo n.º 2
0
    def test_add_get_delete(self):
        us = UserService()

        user1 = User("Test User", Americano())
        user2 = User("Tess User", Americano())
        us.add(user1)
        us.add(user2)

        self.assertEqual(user1, us.get_with_uid(user1.uid))
        self.assertEqual(user2, us.get_with_uid(user2.uid))

        us.delete(user2)
        self.assertEqual(None, us.get_with_uid(user2.uid))
Exemplo n.º 3
0
    def build_order(self):
        order = RoundOrder()
        order.add_item(Espresso())
        order.add_item(DoubleEspresso())
        order.add_item(Americano())

        return order
Exemplo n.º 4
0
    def test_add_empty(self):
        test_round = self.build_round(0)
        round_user = TestUser("Round User", Americano())
        order = self.build_order()
        test_round.add(round_user, order)

        expected_orders = {round_user.uid: order}
        self.assertEqual(test_round.orders, expected_orders)
Exemplo n.º 5
0
    def test_change_name(self):
        us = UserService()

        initial_name = "Old Name"
        user = User(initial_name, Americano())
        uid = user.uid

        us.add(user)

        new_name = "New Name"
        us.change_name(user.uid, new_name)
        self.assertEqual(us.get_with_uid(uid).name, new_name)
Exemplo n.º 6
0
    def test_change_drink(self):
        us = UserService()

        initial_drink = Americano()
        user = User("Test User", initial_drink)
        uid = user.uid

        us.add(user)

        new_drink = Espresso()
        us.change_drink(uid, new_drink)

        self.assertEqual(new_drink, us.get_with_uid(uid).fav_drink)
Exemplo n.º 7
0
    def test_add_many(self):
        test_round = self.build_round(100)

        current_orders = test_round.orders.copy()
        new_orders = {}

        for idx in range(100):
            round_user = TestUser(f"Round User {idx}", Americano())
            order = self.build_order()
            new_orders[round_user.uid] = order
            test_round.add(round_user, order)

        expected_orders = dict(current_orders)
        expected_orders.update(new_orders)

        self.assertEqual(test_round.orders, expected_orders)
Exemplo n.º 8
0
class TestUser(unittest.TestCase):
    drink = Americano()

    def test_init(self):
        name = "Test Name"

        test_user = User(name, TestUser.drink)
        self.assertEqual(test_user.name, name)
        self.assertEqual(test_user.fav_drink, TestUser.drink)

    def test_badname(self):
        name = "#¢∞§¶£$%^& ª•%^#¢ª•("
        self.assertRaises(ValueError, User, name, TestUser.drink)

    def test_baddrink(self):
        name = "Test Name"
        drink = "Americano"
        self.assertRaises(ValueError, User, name, drink)