def test_fulfill_check_transaction_has_money(self): member = Member(balance=10) transaction = PayTransaction(10) has_money = member.can_fulfill(transaction) self.assertTrue(has_money)
def save_model(self, request, obj, form, change): if change: return transaction = PayTransaction(obj.price) obj.member.fulfill(transaction) obj.member.save() super(SaleAdmin, self).save_model(request, obj, form, change)
def test_fulfill_pay_transaction_no_money(self): member = Member(balance=2) transaction = PayTransaction(10) with self.assertRaises(StregForbudError) as c: member.fulfill(transaction) self.assertTrue(c.exception) self.assertEqual(member.balance, 2)
def test_fulfill_pay_transaction_rollback(self): member = Member( balance=2 ) transaction = PayTransaction(10) member.rollback(transaction) self.assertEqual(member.balance, 12)
def test_fulfill_pay_transaction(self): member = Member( balance=100 ) transaction = PayTransaction(10) member.fulfill(transaction) self.assertEqual(member.balance, 90)
def test_order_execute_multi_transaction(self, fulfill): order = Order(self.member, self.room) item = OrderItem(self.product, order, 2) order.items.add(item) order.execute() fulfill.assert_called_once_with(PayTransaction(20))
def test_make_sale_menusale_success(self, fulfill, can_fulfill): can_fulfill.return_value = True response = self.client.get(reverse('menu_sale', args=(1, 1, 1))) self.assertTemplateUsed(response, "stregsystem/menu.html") self.assertEqual(response.status_code, 200) self.assertEqual(response.context["bought"], Product.objects.get(id=1)) self.assertEqual(response.context["member"], Member.objects.get(id=1)) fulfill.assert_called_once_with(PayTransaction(900))
def test_make_sale_quickbuy_success(self, fulfill, can_fulfill): can_fulfill.return_value = True response = self.client.post(reverse('quickbuy', args=(1, )), {"quickbuy": "jokke 1"}) self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, "stregsystem/index_sale.html") assertCountEqual(self, response.context["products"], {Product.objects.get(id=1)}) self.assertEqual(response.context["member"], Member.objects.get(username="******")) fulfill.assert_called_once_with(PayTransaction(900))
def refund(modeladmin, request, queryset): for obj in queryset: transaction = PayTransaction(obj.price) obj.member.rollback(transaction) obj.member.save() queryset.delete()
def delete_model(self, request, obj): transaction = PayTransaction(obj.price) obj.member.rollback(transaction) obj.member.save() super(SaleAdmin, self).delete_model(request, obj)
def test_pay_transaction_add(self): transaction = PayTransaction(90) transaction.add(10) self.assertEqual(transaction.change(), -100)
def test_pay_transaction_change_neg(self): transaction = PayTransaction(100) self.assertEqual(transaction.change(), -100)