def callbacks_create(ctx):
    with balanced.key_switcher(None):
        secret = balanced.APIKey().save().secret
        with balanced.key_switcher(secret):
            mp = balanced.Marketplace().save()
            balanced.Callback(
                uri=mp.callbacks_uri,
                url='http://www.example.com/cb/nu',
                method='post',
            ).save()
        return ctx.last_req, ctx.last_resp
def callbacks_create(ctx):
    with balanced.key_switcher(None):
        secret = balanced.APIKey().save().secret
        with balanced.key_switcher(secret):
            mp = balanced.Marketplace().save()
            balanced.Callback(
                uri=mp.callbacks_uri,
                url='http://www.example.com/cb/nu',
                method='post',
            ).save()
        return ctx.last_req, ctx.last_resp
def marketplaces_create(ctx):
    with balanced.key_switcher(None):
        secret = balanced.APIKey().save().secret
        with balanced.key_switcher(secret):
            balanced.Marketplace(**{
                'support_email_address': '*****@*****.**',
                'name': 'Seller of things',
                'domain_url': 'example.com',
                'support_phone_number': '+12125551212',
                'meta': {
                    'my-useful-data': 'abc123'
                }
            }).save()
            return ctx.last_req, ctx.last_resp
Beispiel #4
0
def marketplaces_create(ctx):
    with balanced.key_switcher(None):
        secret = balanced.APIKey().save().secret
        with balanced.key_switcher(secret):
            balanced.Marketplace(**{
                'support_email_address': '*****@*****.**',
                'name': 'Seller of things',
                'domain_url': 'example.com',
                'support_phone_number': '+12125551212',
                'meta': {
                    'my-useful-data': 'abc123'
                }
            }).save()
            return ctx.last_req, ctx.last_resp
    def test_authenticated_listing_fail_kyc(self):
        email_address = '*****@*****.**'
        self._create_user(email_address)
        payload = self._listing_payload_fail_kyc()
        user = User.query.filter(User.email_address == email_address).one()
        resp = self.client.post('/list', data=payload)
        self.assertEqual(resp.status_code, 302)
        self.assertIn('/list/1/redirect', resp.data)

        # create the account for realz
        with balanced.key_switcher(None):
            api_key = balanced.APIKey(
                **self._merchant_payload(email_address)
            ).save()

        merchant_uri = api_key.merchant.uri

        # GET the redirect uri
        uri = '/accounts/verify'
        uri += '?listing_id={}&email_address={}&merchant_uri={}'.format(
            1, email_address, merchant_uri,
        )
        user = User.query.filter(User.email_address == email_address).one()
        self.assertFalse(user.account_uri)
        resp = self.client.get(uri)
        self.assertEqual(resp.status_code, 302)
        self.assertIn('/list/1/complete', resp.data)
    def test_authenticated_listing_fail_kyc(self):
        email_address = '*****@*****.**'
        self._create_user(email_address)
        payload = self._listing_payload_fail_kyc()
        user = User.query.filter(User.email_address == email_address).one()
        resp = self.client.post('/list', data=payload)
        self.assertEqual(resp.status_code, 302)
        self.assertIn('/list/1/complete', resp.data)

        # create the account for realz
        with balanced.key_switcher(None):
            api_key = balanced.APIKey(
                **self._merchant_payload(email_address)).save()

        merchant_uri = api_key.merchant.uri

        # GET the redirect uri
        uri = '/accounts/verify'
        uri += '?listing_id={}&email_address={}&merchant_uri={}'.format(
            1,
            email_address,
            merchant_uri,
        )
        user = User.query.filter(User.email_address == email_address).one()
        self.assertFalse(user.account_uri)
        resp = self.client.get(uri)
        self.assertEqual(resp.status_code, 302)
        self.assertIn('/list/1/complete', resp.data)
    def test_anonymous_listing_fail_kyc(self):
        email_address = '*****@*****.**'
        payload = self._guest_listing_payload_fail_kyc(email_address)
        resp = self.client.post('/list', data=payload)
        self.assertEqual(resp.status_code, 302)
        self.assertIn('/list/1/complete', resp.data)

        # create the account for realz
        with balanced.key_switcher(None):
            api_key = balanced.APIKey(
                **self._merchant_payload(email_address)).save()

        merchant_uri = api_key.merchant.uri

        # GET the redirect uri
        uri = '/accounts/verify'
        uri += '?listing_id={}&email_address={}&merchant_uri={}'.format(
            1,
            email_address,
            merchant_uri,
        )

        resp = self.client.get(uri)
        self.assertEqual(resp.status_code, 302)
        self.assertIn('/list/1/complete', resp.data)
 def test_create_merchants_with_same_identity_on_same_marketplace(self):
     with balanced.key_switcher(None):
         api_key = balanced.APIKey().save()
     merchant = api_key.merchant
     merch_account_1 = self.mp.create_merchant(self._email_address(), merchant_uri=merchant.uri)
     merch_account_2 = self.mp.create_merchant(self._email_address(), merchant_uri=merchant.uri)
     self.assertEqual(merch_account_1.roles, ["merchant"])
     self.assertEqual(merch_account_2.roles, ["merchant"])
 def test_upgrade_account_to_merchant_success(self):
     card = self.mp.create_card(**cards.CARD)
     with balanced.key_switcher(None):
         api_key = balanced.APIKey().save()
     merchant = api_key.merchant
     buyer = self.mp.create_buyer(self._email_address(), card.uri)
     self.assertItemsEqual(buyer.roles, ['buyer'])
     buyer.promote_to_merchant(merchant.uri)
     self.assertItemsEqual(buyer.roles, ['buyer', 'merchant'])
 def test_upgrade_account_to_merchant_success(self):
     card = self.mp.create_card(**cards.CARD)
     with balanced.key_switcher(None):
         api_key = balanced.APIKey().save()
     merchant = api_key.merchant
     buyer = self.mp.create_buyer(self._email_address(), card.uri)
     self.assertItemsEqual(buyer.roles, ['buyer'])
     buyer.promote_to_merchant(merchant.uri)
     self.assertItemsEqual(buyer.roles, ['buyer', 'merchant'])
 def test_create_merchants_with_same_identity_on_same_marketplace(self):
     with balanced.key_switcher(None):
         api_key = balanced.APIKey().save()
     merchant = api_key.merchant
     merch_account_1 = self.mp.create_merchant(self._email_address(),
                                               merchant_uri=merchant.uri)
     merch_account_2 = self.mp.create_merchant(self._email_address(),
                                               merchant_uri=merchant.uri)
     self.assertEqual(merch_account_1.roles, ['merchant'])
     self.assertEqual(merch_account_2.roles, ['merchant'])
Beispiel #12
0
    def setUpClass(cls):
        with balanced.key_switcher(None):
            cls.api_key = balanced.APIKey().save()
        balanced.configure(cls.api_key.secret)
        cls.marketplace = balanced.Marketplace().save()
        cls.user = User.objects.create_user('john', '*****@*****.**', 'pass')
        cls.user.save()

        card = balanced.Card(**FIXTURES['card']).save()
        cls.card = models.Card.create_from_card_uri(cls.user, card.uri)
        cls.buyer = cls.card.user.balanced_account
        # put some money in the escrow account
        cls.buyer.debit(100 * 100, 'test')  # $100.00
def marketplaces_update(ctx):
    with balanced.key_switcher(None):
        secret = balanced.APIKey().save().secret
        with balanced.key_switcher(secret):
            mp = balanced.Marketplace(
                **{
                    'support_email_address': '*****@*****.**',
                    'name': 'Seller of things',
                    'domain_url': 'example.com',
                    'support_phone_number': '+12125551212',
                    'meta': {
                        'my-useful-data': 'abc123'
                    }
                }).save()

            mp.support_email_address = '*****@*****.**'
            mp.name = 'Seller of thingz'
            mp.support_phone_number = '+18185551212'
            mp.meta.update({'even-more-useful-data': '321cba'})
            mp.save()

            return ctx.last_req, ctx.last_resp
Beispiel #14
0
    def setUpClass(cls):
        with balanced.key_switcher(None):
            cls.api_key = balanced.APIKey().save()
        balanced.configure(cls.api_key.secret)
        cls.marketplace = balanced.Marketplace().save()
        cls.user = User.objects.create_user('john', '*****@*****.**', 'pass')
        cls.user.save()

        card = balanced.Card(**FIXTURES['card']).save()
        cls.card = models.Card.create_from_card_uri(cls.user, card.uri)
        cls.buyer = cls.card.user.balanced_account
        # put some money in the escrow account
        cls.buyer.debit(100 * 100, 'test')  # $100.00
def marketplaces_update(ctx):
    with balanced.key_switcher(None):
        secret = balanced.APIKey().save().secret
        with balanced.key_switcher(secret):
            mp = balanced.Marketplace(**{
                'support_email_address': '*****@*****.**',
                'name': 'Seller of things',
                'domain_url': 'example.com',
                'support_phone_number': '+12125551212',
                'meta': {
                    'my-useful-data': 'abc123'
                }
            }).save()

            mp.support_email_address = '*****@*****.**'
            mp.name = 'Seller of thingz'
            mp.support_phone_number = '+18185551212'
            mp.meta.update({
                'even-more-useful-data': '321cba'
            })
            mp.save()

            return ctx.last_req, ctx.last_resp
    def test_anonymous_listing_fail_kyc(self):
        email_address = '*****@*****.**'
        payload = self._guest_listing_payload_fail_kyc(email_address)
        resp = self.client.post('/list', data=payload)
        self.assertEqual(resp.status_code, 302)
        self.assertIn('/list/1/redirect', resp.data)

        # create the account for realz
        with balanced.key_switcher(None):
            api_key = balanced.APIKey(
                **self._merchant_payload(email_address)
            ).save()

        merchant_uri = api_key.merchant.uri

        # GET the redirect uri
        uri = '/accounts/verify'
        uri += '?listing_id={}&email_address={}&merchant_uri={}'.format(
            1, email_address, merchant_uri,
        )

        resp = self.client.get(uri)
        self.assertEqual(resp.status_code, 302)
        self.assertIn('/list/1/complete', resp.data)
Beispiel #17
0
 def test_client_key_switch(self):
     the_config = balanced.config
     current_key = the_config.api_key_secret
     with balanced.key_switcher('new_key'):
         self.assertEqual(the_config.api_key_secret, 'new_key')
     self.assertEqual(the_config.api_key_secret, current_key)
Beispiel #18
0
 def test_client_key_switch(self):
     the_config = balanced.config
     current_key = the_config.api_key_secret
     with balanced.key_switcher('new_key'):
         self.assertEqual(the_config.api_key_secret, 'new_key')
     self.assertEqual(the_config.api_key_secret, current_key)