def test_get_default_account(self, account_retrieve_mock): account_retrieve_mock.return_value = FAKE_ACCOUNT Account.get_default_account() account_retrieve_mock.assert_called_once_with( api_key=settings.STRIPE_SECRET_KEY)
def test__attach_objects_post_save_hook( self, fileupload_retrieve_mock, account_retrieve_mock ): fake_account = deepcopy(FAKE_ACCOUNT) fake_account["settings"]["branding"]["icon"] = None account_retrieve_mock.return_value = fake_account Account.sync_from_stripe_data(fake_account) fileupload_retrieve_mock.assert_called_with( id=fake_account["settings"]["branding"]["logo"], api_key=djstripe_settings.STRIPE_SECRET_KEY, expand=[], stripe_account=fake_account["id"], )
def test_file_upload_api_retrieve(self, mock_file_upload_retrieve): """Expect file_upload to use the ID of the account referring to it to retrieve itself. """ # Create files icon_file = File._get_or_create_from_stripe_object( data=FAKE_FILEUPLOAD_ICON)[0] logo_file = File._get_or_create_from_stripe_object( data=FAKE_FILEUPLOAD_LOGO)[0] # Create account to associate the files to it account = Account._get_or_create_from_stripe_object( data=FAKE_ACCOUNT)[0] # Call the API retrieve methods. icon_file.api_retrieve() logo_file.api_retrieve() # Ensure the correct Account ID was used in retrieval mock_file_upload_retrieve.assert_has_calls(( call(id=icon_file.id, api_key=ANY, expand=ANY, stripe_account=account.id), call(id=logo_file.id, api_key=ANY, expand=ANY, stripe_account=account.id), ))
def test_get_default_account(self, file_retrieve_mock, account_retrieve_mock): account_retrieve_mock.return_value = deepcopy(FAKE_ACCOUNT) account = Account.get_default_account() account_retrieve_mock.assert_called_once_with( api_key=djstripe_settings.STRIPE_SECRET_KEY ) self.assertGreater(len(account.business_profile), 0) self.assertGreater(len(account.settings), 0) self.assertEqual(account.branding_icon.id, FAKE_FILEUPLOAD_ICON["id"]) self.assertEqual(account.branding_logo.id, FAKE_FILEUPLOAD_LOGO["id"]) self.assertEqual(account.settings["branding"]["icon"], account.branding_icon.id) self.assertEqual(account.settings["branding"]["logo"], account.branding_logo.id) self.assertNotEqual(account.branding_logo.id, account.branding_icon.id) self.assert_fks(account, expected_blank_fks={}) self.assertEqual(account.business_url, "https://djstripe.com") account.business_profile = None self.assertEqual(account.business_url, "")
def test_livemode_populates_correctly_for_testmode( self, fileupload_retrieve_mock, account_retrieve_mock, _account, is_platform ): fake_account = _account fake_account["settings"]["branding"]["icon"] = None account_retrieve_mock.return_value = fake_account platform_account = FAKE_PLATFORM_ACCOUNT.create() # Account.get_or_retrieve_for_api_key is called and since the passed in api_key doesn't have an owner acount, # key is refreshed and the current mocked _account is assigned as the owner account. # This essentially turns all these cases into Platform Account cases. # And that is why Account.get_or_retrieve_for_api_key is patched with patch.object( Account, "get_or_retrieve_for_api_key", return_value=platform_account ): account = Account.sync_from_stripe_data( fake_account, api_key=djstripe_settings.STRIPE_SECRET_KEY ) assert account.djstripe_owner_account == platform_account if is_platform is True: assert account.livemode is None else: assert account.livemode is False
def test_get_default_account(self, fileupload_retrieve_mock, account_retrieve_mock): account_retrieve_mock.return_value = deepcopy(FAKE_ACCOUNT) account = Account.get_default_account() account_retrieve_mock.assert_called_once_with( api_key=STRIPE_SECRET_KEY) self.assertGreater(len(account.business_profile), 0) self.assertGreater(len(account.settings), 0) self.assertEqual(account.branding_icon.id, FAKE_FILEUPLOAD_ICON["id"]) self.assertEqual(account.branding_logo.id, FAKE_FILEUPLOAD_LOGO["id"]) self.assertEqual(account.settings["branding"]["icon"], account.branding_icon.id) self.assertEqual(account.settings["branding"]["logo"], account.branding_logo.id) with self.assertWarns(DeprecationWarning): self.assertEqual(account.business_logo.id, account.branding_icon.id) self.assertNotEqual(account.branding_logo.id, account.branding_icon.id) self.assert_fks(account, expected_blank_fks={})
def test_account__create_from_stripe_object( mock_super__create_from_stripe_object, mock_account_id, other_mock_account_id, expected_stripe_account, ): """Ensure that we are setting the ID value correctly.""" mock_data = {"id": mock_account_id} Account._create_from_stripe_object(data=mock_data, stripe_account=other_mock_account_id) mock_super__create_from_stripe_object.assert_called_once_with( data=mock_data, current_ids=None, pending_relations=None, save=True, stripe_account=expected_stripe_account, )
def test_get_connected_account_from_token(self, fileupload_retrieve_mock, account_retrieve_mock): account_retrieve_mock.return_value = deepcopy(FAKE_ACCOUNT) account = Account.get_connected_account_from_token("fake_token") account_retrieve_mock.assert_called_once_with(api_key="fake_token") self.assert_fks(account, expected_blank_fks={})
def test_get_default_account(self, fileupload_retrieve_mock, account_retrieve_mock): account_retrieve_mock.return_value = FAKE_ACCOUNT account = Account.get_default_account() account_retrieve_mock.assert_called_once_with( api_key=STRIPE_SECRET_KEY) self.assert_fks(account, expected_blank_fks={})
def test_account_str_restricted_key(self, account_retrieve_mock): """ Test that we do not attempt to retrieve account ID with restricted keys. """ assert djstripe_settings.STRIPE_SECRET_KEY == "rk_test_blah" account = Account.get_default_account() assert account is None account_retrieve_mock.assert_not_called()
def test_get_stripe_dashboard_url( self, fileupload_retrieve_mock, account_retrieve_mock ): fake_account = deepcopy(FAKE_ACCOUNT) account = Account.sync_from_stripe_data(fake_account) self.assertEqual( account.get_stripe_dashboard_url(), f"https://dashboard.stripe.com/{account.id}/" f"{'test/' if not account.livemode else ''}dashboard", )
def test__str__null_settings_null_business_profile( self, fileupload_retrieve_mock, account_retrieve_mock, ): """Test that __str__ doesn't crash when settings and business_profile are NULL.""" fake_account = deepcopy(FAKE_ACCOUNT) fake_account["settings"] = None fake_account["business_profile"] = None account_retrieve_mock.return_value = fake_account account = Account.sync_from_stripe_data(fake_account) assert str(account) == "<id=acct_1032D82eZvKYlo2C>"
def test_get_default_account_null_logo(self, fileupload_retrieve_mock, account_retrieve_mock): fake_account = deepcopy(FAKE_ACCOUNT) fake_account["business_logo"] = None account_retrieve_mock.return_value = fake_account account = Account.get_default_account() account_retrieve_mock.assert_called_once_with( api_key=STRIPE_SECRET_KEY) self.assert_fks(account, expected_blank_fks={"djstripe.Account.business_logo"})
def test_account_str( fileupload_retrieve_mock, account_retrieve_mock, business_profile_update, settings_dashboard_update, expected_account_str, ): fake_account = deepcopy(FAKE_ACCOUNT) fake_account["business_profile"].update(business_profile_update) fake_account["settings"]["dashboard"].update(settings_dashboard_update) account_retrieve_mock.return_value = fake_account account = Account.get_default_account() assert str(account) == expected_account_str
def test_sync_from_stripe_data( self, fileupload_retrieve_mock, account_retrieve_mock ): fake_account = deepcopy(FAKE_ACCOUNT) account = Account.sync_from_stripe_data(fake_account) self.assertGreater(len(account.business_profile), 0) self.assertGreater(len(account.settings), 0) self.assertEqual(account.branding_icon.id, FAKE_FILEUPLOAD_ICON["id"]) self.assertEqual(account.branding_logo.id, FAKE_FILEUPLOAD_LOGO["id"]) self.assertEqual(account.settings["branding"]["icon"], account.branding_icon.id) self.assertEqual(account.settings["branding"]["logo"], account.branding_logo.id) self.assertNotEqual(account.branding_logo.id, account.branding_icon.id) self.assert_fks(account, expected_blank_fks={}) self.assertEqual(account.business_url, "https://djstripe.com")
def test_get_default_account_null_logo( self, fileupload_retrieve_mock, account_retrieve_mock ): fake_account = deepcopy(FAKE_ACCOUNT) fake_account["settings"]["branding"]["icon"] = None fake_account["settings"]["branding"]["logo"] = None account_retrieve_mock.return_value = fake_account account = Account.get_default_account() account_retrieve_mock.assert_called_once_with( api_key=djstripe_settings.STRIPE_SECRET_KEY ) self.assert_fks( account, expected_blank_fks={ "djstripe.Account.branding_logo", "djstripe.Account.branding_icon", }, )
def test_business_url(self, fileupload_retrieve_mock, account_retrieve_mock): fake_account = deepcopy(FAKE_ACCOUNT) account = Account.sync_from_stripe_data(fake_account) self.assertEqual(fake_account["business_profile"]["url"], account.business_url)
def test__find_owner_account(self, fileupload_retrieve_mock, account_retrieve_mock): fake_account = deepcopy(FAKE_ACCOUNT) account = Account.sync_from_stripe_data(fake_account) self.assertEqual(None, Account._find_owner_account(account))
def test_get_default_account(self, account_retrieve_mock): account_retrieve_mock.return_value = FAKE_ACCOUNT Account.get_default_account() account_retrieve_mock.assert_called_once_with(api_key=settings.STRIPE_SECRET_KEY)
def test__str__null_settings_null_business_profile(): """Test that __str__ doesn't crash when settings and business_profile are NULL.""" account = Account() account.settings = None account.business_profile = None assert str(account) == "<id=>"
def test__find_owner_account(self, fileupload_retrieve_mock, account_retrieve_mock): fake_account = deepcopy(FAKE_ACCOUNT) account = Account.sync_from_stripe_data(fake_account) self.assertEqual(account.djstripe_owner_account.id, FAKE_PLATFORM_ACCOUNT["id"])
def test_get_account_by_api_key(self): account = Account.get_or_retrieve_for_api_key(self.apikey_test.secret) assert account == self.account
def test_branding_icon(self, fileupload_retrieve_mock, account_retrieve_mock): fake_account = deepcopy(FAKE_ACCOUNT) account = Account.sync_from_stripe_data(fake_account) self.assertEqual( fake_account["settings"]["branding"]["icon"], account.branding_icon.id )
def test_get_connected_account_from_token(self, account_retrieve_mock): account_retrieve_mock.return_value = FAKE_ACCOUNT Account.get_connected_account_from_token("fake_token") account_retrieve_mock.assert_called_once_with(api_key="fake_token")