def test_add_coupon_by_object(self, customer_retrieve_mock, coupon_retrieve_mock): self.assertEqual(self.customer.coupon, None) coupon = Coupon.sync_from_stripe_data(FAKE_COUPON) self.customer.add_coupon(coupon) customer_retrieve_mock.assert_called_once_with( api_key="", expand=["default_source"], id=FAKE_CUSTOMER["id"] )
def test_add_coupon_by_object(self, customer_retrieve_mock, coupon_retrieve_mock): self.assertEqual(self.customer.coupon, None) coupon = Coupon.sync_from_stripe_data(FAKE_COUPON) fake_discount = deepcopy(FAKE_DISCOUNT_CUSTOMER) def fake_customer_save(self, *args, **kwargs): # fake the api coupon update behaviour coupon = self.pop("coupon", None) if coupon: self["discount"] = fake_discount else: self["discount"] = None return self with patch("tests.CustomerDict.save", new=fake_customer_save): self.customer.add_coupon(coupon) customer_retrieve_mock.assert_called_once_with( api_key=STRIPE_SECRET_KEY, expand=["default_source"], id=FAKE_CUSTOMER["id"] ) self.customer.refresh_from_db() self.assert_fks(self.customer, expected_blank_fks={})
def test_add_coupon_by_object(self, customer_retrieve_mock, coupon_retrieve_mock): self.assertEqual(self.customer.coupon, None) coupon = Coupon.sync_from_stripe_data(FAKE_COUPON) fake_discount = deepcopy(FAKE_DISCOUNT_CUSTOMER) def fake_customer_save(self, *args, **kwargs): # fake the api coupon update behaviour coupon = self.pop("coupon", None) if coupon: self["discount"] = fake_discount else: self["discount"] = None return self with patch("tests.CustomerDict.save", new=fake_customer_save): self.customer.add_coupon(coupon) customer_retrieve_mock.assert_called_once_with( api_key=STRIPE_SECRET_KEY, expand=["default_source"], id=FAKE_CUSTOMER["id"]) self.customer.refresh_from_db() self.assert_fks(self.customer, expected_blank_fks={})
def test_sync_customer_delete_discount(self): test_coupon = Coupon.sync_from_stripe_data(FAKE_COUPON) self.customer.coupon = test_coupon self.customer.save() self.assertEqual(self.customer.coupon.stripe_id, FAKE_COUPON["id"]) customer = Customer.sync_from_stripe_data(FAKE_CUSTOMER) self.assertEqual(customer.coupon, None)
def test_sync_customer_delete_discount(self): test_coupon = Coupon.sync_from_stripe_data(FAKE_COUPON) self.customer.coupon = test_coupon self.customer.save() self.assertEqual(self.customer.coupon.id, FAKE_COUPON["id"]) customer = Customer.sync_from_stripe_data(FAKE_CUSTOMER) self.assertEqual(customer.coupon, None)
def test_decimal_percent_off_coupon(self, inputted, expected): fake_coupon = deepcopy(FAKE_COUPON) fake_coupon["percent_off"] = inputted coupon = Coupon.sync_from_stripe_data(fake_coupon) field_data = coupon.percent_off assert isinstance(field_data, Decimal) assert field_data == expected
def test_sync_customer_discount_already_present(self, coupon_retrieve_mock): fake_customer = deepcopy(FAKE_CUSTOMER) fake_customer["discount"] = deepcopy(FAKE_DISCOUNT_CUSTOMER) # Set the customer's coupon to be what we'll sync customer = Customer.objects.get(id=FAKE_CUSTOMER["id"]) customer.coupon = Coupon.sync_from_stripe_data(FAKE_COUPON) customer.save() customer = Customer.sync_from_stripe_data(fake_customer) self.assertEqual(customer.coupon.id, FAKE_COUPON["id"])
def test_sync_customer_discount_already_present(self, coupon_retrieve_mock): fake_customer = deepcopy(FAKE_CUSTOMER) fake_customer["discount"] = deepcopy(FAKE_DISCOUNT_CUSTOMER) # Set the customer's coupon to be what we'll sync customer = Customer.objects.get(stripe_id=FAKE_CUSTOMER["id"]) customer.coupon = Coupon.sync_from_stripe_data(FAKE_COUPON) customer.save() customer = Customer.sync_from_stripe_data(fake_customer) self.assertEqual(customer.coupon.stripe_id, FAKE_COUPON["id"])
def test_customer_discount_deleted(self, event_retrieve_mock, coupon_retrieve_mock): coupon = Coupon.sync_from_stripe_data(FAKE_COUPON) self.customer.coupon = coupon fake_stripe_event = deepcopy(FAKE_EVENT_CUSTOMER_DISCOUNT_DELETED) event = Event.sync_from_stripe_data(fake_stripe_event) event.invoke_webhook_handlers() self.assertIsNotNone(event.customer) self.assertEqual(event.customer.id, FAKE_CUSTOMER["id"]) self.assertIsNone(event.customer.coupon)
def test_customer_discount_deleted(self, event_retrieve_mock, coupon_retrieve_mock): coupon = Coupon.sync_from_stripe_data(FAKE_COUPON) self.customer.coupon = coupon fake_stripe_event = deepcopy(FAKE_EVENT_CUSTOMER_DISCOUNT_DELETED) event = Event.sync_from_stripe_data(fake_stripe_event) event.validate() event.process() self.assertTrue(event.processed) self.assertIsNotNone(event.customer) self.assertEqual(event.customer.stripe_id, FAKE_CUSTOMER["id"]) self.assertIsNone(event.customer.coupon)
def test_add_coupon_by_object(self, customer_retrieve_mock, coupon_retrieve_mock): self.assertEqual(self.customer.coupon, None) coupon = Coupon.sync_from_stripe_data(FAKE_COUPON) self.customer.add_coupon(coupon) customer_retrieve_mock.assert_called_once()
def test_retrieve_coupon(self): coupon_data = deepcopy(FAKE_COUPON) coupon = Coupon.sync_from_stripe_data(coupon_data) self.assertEqual(coupon.stripe_id, FAKE_COUPON["id"])