def test_decimal_calc(self): receipt = Receipt() receipt.phone = '79990000000' receipt.email = '*****@*****.**' receipt.tax_system_code = 1 receipt.items = [{ "description": "Product 1", "quantity": '2.1', "amount": { "value": 250.0, "currency": Currency.RUB }, "vat_code": "2" }, { "description": "Product 2", "quantity": 1.0, "amount": { "value": '100.01', "currency": Currency.RUB }, "vat_code": "2" }] summ = round(receipt.items[0].amount.value * receipt.items[0].quantity, 2) self.assertEqual(Decimal('525.00'), Decimal(summ)) summ = round(receipt.items[1].amount.value * receipt.items[1].quantity, 2) self.assertEqual(Decimal('100.01'), Decimal(summ))
def test_receipt_cast(self): self.maxDiff = None receipt = Receipt() receipt.phone = '79990000000' receipt.email = 'test@email' receipt.tax_system_code = 1 receipt.items = [{ "description": "Product 1", "quantity": 2.0, "amount": { "value": 250.0, "currency": Currency.RUB }, "vat_code": "2" }, ReceiptItem({ "description": "Product 2", "quantity": 1.0, "amount": { "value": 100.0, "currency": Currency.RUB }, "vat_code": 2 })] self.assertTrue(receipt.has_items()) self.assertEqual( { 'phone': '79990000000', 'email': 'test@email', 'tax_system_code': 1, 'items': [{ "description": "Product 1", "quantity": 2.0, "amount": { "value": 250.0, "currency": Currency.RUB }, "vat_code": 2 }, { "description": "Product 2", "quantity": 1.0, "amount": { "value": 100.0, "currency": Currency.RUB }, "vat_code": 2 }] }, dict(receipt)) with self.assertRaises(TypeError): receipt.tax_system_code = 'invalid type' with self.assertRaises(ValueError): receipt.phone = 'invalid phone' with self.assertRaises(TypeError): receipt.items = 'invalid items' with self.assertRaises(TypeError): receipt.items = [ 'invalid item value', { "description": "Product 2", "quantity": 1.0, "amount": { "value": 100.0, "currency": Currency.RUB }, "vat_code": 2 } ]
def test_receipt_cast(self): self.maxDiff = None receipt = Receipt() receipt.phone = '79990000000' receipt.email = '*****@*****.**' receipt.tax_system_code = 1 receipt.items = [ { "description": "Product 1", "quantity": 2.0, "amount": { "value": 250.0, "currency": Currency.RUB }, "vat_code": "2" }, ReceiptItem({ "description": "Product 2", "quantity": 1.0, "amount": { "value": 100.0, "currency": Currency.RUB }, "vat_code": 2, "payment_subject": PaymentSubject.AGENT_COMMISSION, "payment_mode": PaymentMode.ADVANCE, "product_code": "00 00 00 01 00 21 FA 41 00 23 05 41 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 12 00 AB 00", "country_of_origin_code": "RU", "customs_declaration_number": "90/210", "excise": 2.00, }) ] self.assertTrue(receipt.has_items()) self.assertEqual( { 'customer': { 'phone': '79990000000', 'email': '*****@*****.**', }, 'phone': '79990000000', 'email': '*****@*****.**', 'tax_system_code': 1, 'items': [{ "description": "Product 1", "quantity": 2.0, "amount": { "value": 250.0, "currency": Currency.RUB }, "vat_code": 2 }, { "description": "Product 2", "quantity": 1.0, "amount": { "value": 100.0, "currency": Currency.RUB }, "vat_code": 2, 'payment_subject': PaymentSubject.AGENT_COMMISSION, 'payment_mode': PaymentMode.ADVANCE, "product_code": "00 00 00 01 00 21 FA 41 00 23 05 41 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 12 00 AB 00", "country_of_origin_code": "RU", "customs_declaration_number": "90/210", "excise": 2.00, }] }, dict(receipt)) with self.assertRaises(TypeError): receipt.tax_system_code = 'invalid type' with self.assertRaises(ValueError): receipt.phone = 'invalid phone' with self.assertRaises(TypeError): receipt.items = 'invalid items' with self.assertRaises(TypeError): receipt.items = [ 'invalid item value', { "description": "Product 2", "quantity": 1.0, "amount": { "value": 100.0, "currency": Currency.RUB }, "vat_code": 2, "payment_subject": PaymentSubject.AGENT_COMMISSION, "payment_mode": PaymentMode.ADVANCE, "product_code": "00 00 00 01 00 21 FA 41 00 23 05 41 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 12 00 AB 00", "country_of_origin_code": "RU", "customs_declaration_number": "90/210", "excise": 2.00, } ]