

def test_can_pass_fail_on_duplicate_payment_method(self):
    config = Configuration.instantiate()
    result = braintree.Customer.create()
    customer_id = result.customer.id
    client_token = TestHelper.generate_decoded_client_token({
        'customer_id': customer_id,
    })
    authorization_fingerprint = json.loads(client_token)['authorizationFingerprint']
    http = ClientApiHttp(config, {
        'authorization_fingerprint': authorization_fingerprint,
        'shared_customer_identifier': 'fake_identifier',
        'shared_customer_identifier_type': 'testing',
    })
    (status_code, response) = http.add_card({
        'credit_card': {
            'number': '4111111111111111',
            'expiration_month': '11',
            'expiration_year': '2099',
        },
    })
    self.assertEqual(status_code, 201)
    client_token = TestHelper.generate_decoded_client_token({
        'customer_id': customer_id,
        'options': {
            'fail_on_duplicate_payment_method': True,
        },
    })
    authorization_fingerprint = json.loads(client_token)['authorizationFingerprint']
    http.set_authorization_fingerprint(authorization_fingerprint)
    (status_code, response) = http.add_card({
        'credit_card': {
            'number': '4111111111111111',
            'expiration_month': '11',
            'expiration_year': '2099',
        },
    })
    self.assertEqual(status_code, 422)
    customer = braintree.Customer.find(customer_id)
    self.assertEqual(len(customer.credit_cards), 1)

dataset/ETHPy150Open braintree/braintree_python/tests/integration/test_client_token.py TestClientToken.test_can_pass_fail_on_duplicate_payment_method/original