def test_put(self):
        bucket = Bucket()
        bucket.put(Choice(self.latte.id, 1))

        bucket_repo = BucketRepository()
        bucket_repo.update_bucket(self.CUSTOMER_ID, bucket)
        expected = {self.CUSTOMER_ID: bucket}
        self.assertEqual(expected, bucket_repo.buckets)
    def setUp(self):
        super(TestOrderRepository, self).setUp()
        bucket = Bucket()
        bucket.put(Choice(self.latte.id, 1))

        self.bucket_repo = BucketRepository()
        self.bucket_repo.update_bucket(self.CUSTOMER_ID, bucket)

        self.order_repo = OrderRepository()
    def test_add_items_to_bucket(self):
        items = [Choice(self.latte.id, 1)]
        with self.assertRaises(ExceedOnHandError):
            self.order_service.add_items_to_bucket(self.CUSTOMER_ID, items)

        items = [Choice(self.americano.id, 1), Choice(self.espresso.id, 1)]
        self.order_service.add_items_to_bucket(self.CUSTOMER_ID, items)

        expected = {
            self.latte.id: 1,
            self.americano.id: 1,
            self.espresso.id: 1
        }
        self.assertEqual(expected,
                         self.bucket_repo.get_bucket(self.CUSTOMER_ID).items)

        with self.assertRaises(DoesNotExistItemError):
            self.order_service.add_items_to_bucket(self.CUSTOMER_ID,
                                                   [Choice(0, 12)])
示例#4
0
    def test_put(self):
        expected = {}
        for coffee in self.coffee_list:
            cnt = 1
            expected[coffee.id] = cnt

        # check inventory after first putting items
        self.assertEqual(expected, self.coffee_repo.inventory)

        choice = Choice(self.latte.id, 3)
        self.coffee_repo.put(choice)
        expected[choice.id] += choice.count

        # check inventory after second putting latte 3 cups
        self.assertEqual(expected, self.coffee_repo.inventory)
        self.assertNotEqual({}, self.coffee_repo.inventory)

        # check negative count
        with self.assertRaises(NegativeIntegerError):
            self.coffee_repo.put(Choice(self.latte.id, -2))
    def setUp(self):
        super().setUp()
        bucket = Bucket()
        bucket.put(Choice(self.latte.id, 1))

        self.bucket_repo = BucketRepository()
        self.bucket_repo.update_bucket(self.CUSTOMER_ID, bucket)
        self.order_repo = OrderRepository()

        self.order_service = OrderService(self.coffee_repo, self.bucket_repo,
                                          self.order_repo, self.menu)
    def test_get_bucket(self):
        bucket = Bucket()
        bucket.put(Choice(self.latte.id, 1))

        bucket_repo = BucketRepository()
        bucket_repo.update_bucket(self.CUSTOMER_ID, bucket)

        expected = bucket
        self.assertEqual(expected, bucket_repo.get_bucket(self.CUSTOMER_ID))

        # check empty bucket
        self.assertEqual({}, bucket_repo.get_bucket(2))
示例#7
0
    def setUp(self):
        self.latte = Coffee(id=self.LATTE_ID, name='latte', price=4000)
        self.espresso = Coffee(id=self.ESPRESSO_ID,
                               name='espresso',
                               price=2000)
        self.americano = Coffee(id=self.AMERICANO_ID,
                                name='americano',
                                price=500)

        self.menu = Menu()
        self.coffee_list = [self.latte, self.espresso, self.americano]
        self.menu.add_items(self.coffee_list)

        self.coffee_repo = CoffeeRepository()

        for coffee in self.coffee_list:
            cnt = 1
            choice = Choice(coffee.id, cnt)
            self.coffee_repo.put(choice)
示例#8
0
 def test_put(self):
     bucket = Bucket()
     bucket.put(Choice(self.latte.id, 1))
     self.assertEqual(1, bucket.items[self.latte.id])
     with self.assertRaises(NegativeIntegerError):
         bucket.put(Choice(self.latte.id, -1))
示例#9
0
 def test_get_item(self):
     bucket = Bucket()
     bucket.put(Choice(self.latte.id, 1))
     self.assertEqual(1, bucket.get_item(self.latte.id))
     self.assertEqual(0, bucket.get_item(self.americano.id))