def test_request_validate(self): request = PaymentRequest() with self.assertRaises(ValueError): request.validate() request.amount = Amount({'value': 0.0, 'currency': Currency.RUB}) with self.assertRaises(ValueError): request.validate() request.amount = Amount({'value': 0.1, 'currency': Currency.RUB}) request.receipt = { 'phone': '79990000000', 'items': [{ "description": "Product 1", "quantity": 2.0, "amount": { "value": 250.0, "currency": Currency.RUB }, }, { "description": "Product 2", "quantity": 1.0, "amount": { "value": 100.0, "currency": Currency.RUB }, }] } with self.assertRaises(ValueError): request.validate() request.receipt = { '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 }] } with self.assertRaises(ValueError): request.validate() request = PaymentRequest() request.amount = Amount({'value': 0.1, 'currency': Currency.RUB}) request.payment_token = '123' request.payment_method_id = '123' with self.assertRaises(ValueError): request.validate() request = PaymentRequest() request.amount = Amount({'value': 0.1, 'currency': Currency.RUB}) request.payment_token = '123' request.payment_method_data = PaymentDataWebmoney() with self.assertRaises(ValueError): request.validate() request = PaymentRequest() request.amount = Amount({'value': 0.1, 'currency': Currency.RUB}) request.payment_method_id = '123' request.payment_method_data = PaymentDataWebmoney() with self.assertRaises(ValueError): request.validate()
def test_request_validate_expiry(self, modtime): modtime.now.return_value = datetime(year=2019, month=3, day=10) request = PaymentRequest() request.amount = Amount({'value': 0.1, 'currency': Currency.RUB}) request.payment_method_data = PaymentDataBankCard( card={ "number": "4111111111111111", "expiry_year": "2019", "expiry_month": "11", "csc": "111" }) # Should pass other validations request.validate() # Obviously expired request.payment_method_data.card.expiry_year = '2018' with self.assertRaises(ValueError): request.validate() # Same month request.payment_method_data.card.expiry_year = '2019' request.payment_method_data.card.expiry_month = '03' request.validate() # Just a notch before expiration (same timezone) modtime.now.return_value = datetime(year=2019, month=3, day=31, hour=23, minute=59, second=59) request.payment_method_data.card.expiry_year = '2019' request.payment_method_data.card.expiry_month = '03' request.validate() # Just a notch before expiration (worst timezone case) client_tz = timezone(timedelta(hours=-12)) bank_tz = timezone(timedelta(hours=+14)) tz_offset = datetime.now(client_tz) - datetime.now(bank_tz) tz_offset += timedelta(hours=1) # DST modtime.now.return_value += tz_offset request.validate() # Couple days after expiration modtime.now.return_value = datetime(year=2019, month=4, day=3) with self.assertRaises(ValueError): request.validate()