Ejemplo n.º 1
0
    def list_savings_goals(self, access_token):
        """
        Gets a lists of the customer's savings goals

        :param access_token: the oauth bearer token
        :return: the json response dict
        """
        type_validation([access_token],
                        list_savings_goals_parameter_definition)
        url = "{api_url}/api/v1/savings-goals".format(
            api_url=self.options["api_url"])
        logging.debug("GET {url}".format(url=url))
        return request.get(url, headers=default_headers(access_token))
Ejemplo n.º 2
0
    def get_mandate(self, access_token, mandate_id):
        """
        Gets a specific direct debit mandates

        :param access_token: the oauth bearer token
        :param mandate_id: the unique mandate ID
        :return: the json response dict
        """
        type_validation([access_token], list_mandates_parameter_definition)
        url = "{api_url}/api/v1/direct-debit/mandates/{mandate_id}".format(
            api_url=self.options["api_url"], mandate_id=mandate_id)
        logging.debug("GET {url}".format(url=url))
        return request.get(url, headers=default_headers(access_token))
Ejemplo n.º 3
0
    def get_savings_goal(self, access_token, savings_goal_id):
        """
        Gets a specific savings goal

        :param access_token: the oauth bearer token
        :param savings_goal_id: the savings goal's ID
        :return: the json response dict
        """
        type_validation([access_token, savings_goal_id],
                        get_savings_goals_parameter_definition)
        url = "{api_url}/api/v1/savings-goals/{goal_id}".format(
            api_url=self.options["api_url"], goal_id=savings_goal_id)
        logging.debug("GET {url}".format(url=url))
        return request.get(url, headers=default_headers(access_token))
Ejemplo n.º 4
0
def test_delete_mandate(requests_mock):
    mock_url = "http://localhost"
    mock_access_token = "0123456789"
    mandate_id = "12345-12345"

    mock_object = Starling({
        "api_url": mock_url
    })

    requests_mock.delete("{}/api/v1/direct-debit/mandates/{}".format(mock_url, mandate_id),
                         headers=default_headers(mock_access_token),
                         request_headers=expect_authorization_header(mock_access_token),
                         status_code=204)

    mock_object.delete_mandate(mandate_id, access_token=mock_access_token)
Ejemplo n.º 5
0
def test_delete_savings_goal(requests_mock):
    mock_url = "http://localhost"
    mock_access_token = "0123456789"

    mock_object = Starling({"api_url": mock_url})

    savings_goal_id = "12345-12345"

    requests_mock.delete(
        "{}/api/v1/savings-goals/{}".format(mock_url, savings_goal_id),
        headers=default_headers(mock_access_token),
        request_headers=expect_authorization_header(mock_access_token),
        status_code=204)

    mock_object.delete_savings_goal(savings_goal_id,
                                    access_token=mock_access_token)
Ejemplo n.º 6
0
    def create_savings_goal(self,
                            access_token,
                            savings_goal_id,
                            name,
                            target_amount,
                            currency="GBP",
                            target_currency="GBP",
                            base64_encoded_photo=None):
        """
        Creates a savings goal

        :param access_token: the oauth bearer token
        :param savings_goal_id: the saving's goal's ID
        :param name: the name of the savings goal
        :param target_amount: the target amount in minor units (e.g. 1234 => £12.34)
        :param currency: the currency of the savings goal, defaults to 'GBP'
        :param target_currency: the target currency, defaults to 'GBP'
        :param base64_encoded_photo: base64 encoded image to associate with the goal. (optional)
        :return: the json response dict
        """

        type_validation([
            access_token, name, currency, target_amount, target_currency,
            base64_encoded_photo
        ], create_savings_goals_parameter_definition)

        data = {
            "name": name,
            "currency": currency,
            "target": {
                "targetAmount": target_amount,
                "targetCurrency": target_currency
            }
        }

        if base64_encoded_photo is not None:
            data["base64EncodedPhoto"] = base64_encoded_photo

        url = "{api_url}/api/v1/savings-goals/{goal_id}".format(
            api_url=self.options["api_url"], goal_id=savings_goal_id)

        logging.debug("PUT {url}".format(url=url))

        return request.put(url,
                           headers=default_headers(access_token),
                           data=data)
Ejemplo n.º 7
0
def test_delete_contact_account(requests_mock):
    mock_url = "http://localhost"
    mock_access_token = "0123456789"

    contact_id = "fc17e7d5-ff2c-4a3c-8f64-9ac93d80de62"

    mock_object = Starling({"api_url": mock_url})

    requests_mock.delete(
        "{}/api/v1/contacts/{}".format(mock_url, contact_id),
        headers=default_headers(mock_access_token),
        request_headers=expect_authorization_header(mock_access_token),
        status_code=204)

    mocked_response = mock_object.delete_contact(
        contact_id, access_token=mock_access_token)

    assert mocked_response == {}
Ejemplo n.º 8
0
def test_get_contacts(requests_mock):
    mock_url = "http://localhost"
    mock_access_token = "0123456789"

    mock_object = Starling({"api_url": mock_url})

    with open("test/responses/v1-get-contacts.json") as f:
        expected_response = json.load(f)

        requests_mock.get(
            "{}/api/v1/contacts".format(mock_url),
            headers=default_headers(mock_access_token),
            request_headers=expect_authorization_header(mock_access_token),
            json=expected_response)

        mocked_response = mock_object.get_contacts(mock_access_token)

        assert expected_response == mocked_response
Ejemplo n.º 9
0
def test_get_mandate(requests_mock):
    mock_url = "http://localhost"
    mock_access_token = "0123456789"
    mandate_id = "12345-12345"

    mock_object = Starling({
        "api_url": mock_url
    })

    with open("test/responses/v1-get-mandate.json") as f:
        expected_response = json.load(f)

        requests_mock.get("{}/api/v1/direct-debit/mandates/{}".format(mock_url, mandate_id),
                          headers=default_headers(mock_access_token),
                          request_headers=expect_authorization_header(mock_access_token),
                          json=expected_response)

        mocked_response = mock_object.get_mandate(mandate_id, access_token=mock_access_token)

        assert expected_response == mocked_response
Ejemplo n.º 10
0
def test_starling_client(requests_mock):
    """test static access token provided in client instance"""
    mock_url = "http://localhost"
    mock_access_token = "0123456789"

    mock_object = Starling({
        "api_url": mock_url
    })

    with open("test/responses/v1-get-accounts.json") as f:
        expected_response = json.load(f)

        requests_mock.get("{}/api/v1/accounts".format(mock_url),
                          headers=default_headers(mock_access_token),
                          request_headers=expect_authorization_header(mock_access_token),
                          json=expected_response)

        mocked_response = mock_object.get_account(mock_access_token)

        assert expected_response == mocked_response
Ejemplo n.º 11
0
def test_get_contact_account(requests_mock):
    mock_url = "http://localhost"
    mock_access_token = "0123456789"

    contact_id = "fc17e7d5-ff2c-4a3c-8f64-9ac93d80de62"

    mock_object = Starling({"api_url": mock_url})

    with open("test/responses/v1-get-contact-account.json") as f:
        expected_response = json.load(f)

        requests_mock.get(
            "{}/api/v1/contacts/{}".format(mock_url, contact_id),
            headers=default_headers(mock_access_token),
            request_headers=expect_authorization_header(mock_access_token),
            json=expected_response)

        mocked_response = mock_object.get_contact_account(
            contact_id, access_token=mock_access_token)

        assert expected_response == mocked_response
Ejemplo n.º 12
0
def test_get_savings_goal(requests_mock):
    mock_url = "http://localhost"
    mock_access_token = "0123456789"

    mock_object = Starling({"api_url": mock_url})

    savings_goal_id = "12345-12345"

    with open("test/responses/v1-get-savings-goal.json") as f:
        expected_response = json.load(f)

        requests_mock.get(
            "{}/api/v1/savings-goals/{}".format(mock_url, savings_goal_id),
            headers=default_headers(mock_access_token),
            request_headers=expect_authorization_header(mock_access_token),
            json=expected_response)

        mocked_response = mock_object.get_savings_goal(
            savings_goal_id, access_token=mock_access_token)

        assert expected_response == mocked_response
Ejemplo n.º 13
0
    def make_local_payment(self, access_token, destination_account_uid, reference, amount):
        """
        Makes a payment on behalf of the customer to another UK bank account using the Faster Payments network

        :param access_token: the oauth bearer token
        :param destination_account_uid:
        :param reference: the payment reference, max. 18 characters
        :param amount: the amount to be send
        :return: the json response dict
        """
        type_validation([access_token, destination_account_uid, reference, amount],
                        make_local_payment_parameter_definition)
        url = "{api_url}/api/v1/payments/local".format(api_url=self.options["api_url"])
        logging.debug("POST {url}".format(url=url))
        return request.post(url, headers=default_headers(access_token), data={
            "destinationAccountUid": destination_account_uid,
            "payment": {
                "amount": amount,
            },
            "reference": reference
        })
Ejemplo n.º 14
0
def test_get_transaction_with_unspecified_source(requests_mock):
    mock_url = "http://localhost"
    mock_access_token = "0123456789"

    mock_object = Starling({"api_url": mock_url})

    transaction_id = "32b4d093-f3b3-45da-9f89-d6a1395ab397"

    with open("test/responses/v1-get-transaction.json") as f:
        expected_response = json.load(f)

        requests_mock.get(
            "{}/api/v1/transactions/{}".format(mock_url, transaction_id),
            headers=default_headers(mock_access_token),
            request_headers=expect_authorization_header(mock_access_token),
            json=expected_response)

        mocked_response = mock_object.get_transaction(
            transaction_id, "", access_token=mock_access_token)

        assert expected_response == mocked_response
Ejemplo n.º 15
0
def test_create_contact_account(requests_mock):
    mock_url = "http://localhost"
    mock_access_token = "0123456789"

    name = "Mickey Mouse"
    account_number = "87654321"
    sort_code = "60-83-71"

    mock_object = Starling({"api_url": mock_url})

    requests_mock.post(
        "{}/api/v1/contacts".format(mock_url),
        headers=default_headers(mock_access_token),
        request_headers=expect_authorization_header(mock_access_token),
        status_code=202)

    mocked_response = mock_object.create_contact(
        name, account_number, sort_code, access_token=mock_access_token)

    print(mocked_response)

    assert mocked_response == {}
Ejemplo n.º 16
0
    def get_transaction(self, access_token, transaction_id, source):
        """
        Makes a payment on behalf of the customer to another UK bank account using the Faster Payments network

        :param access_token: the oauth bearer token
        :param transaction_id: the unique transaction ID
        :param source: the transaction type (e.g. faster payments, mastercard)
                       if not specified, only generic transaction information is provided
        :return: the json response dict
        """

        type_validation([access_token, transaction_id, source],
                        get_transaction_parameter_definition)

        url = "{api_url}/api/v1/transactions{source}/{id}".format(
            api_url=self.options["api_url"],
            source=transaction_source(source),
            id=transaction_id)

        logging.debug("GET {url}".format(url=url))

        return request.get(url, headers=default_headers(access_token))
Ejemplo n.º 17
0
def test_get_outgoing_fps_transaction(requests_mock):
    mock_url = "http://localhost"
    mock_access_token = "0123456789"

    mock_object = Starling({"api_url": mock_url})

    transaction_id = "b5c65fd2-1795-4262-93f0-f0490759bf1f"
    source = "FASTER_PAYMENTS_OUT"

    with open("test/responses/v1-get-transaction-fps-out.json") as f:
        expected_response = json.load(f)

        requests_mock.get(
            "{}/api/v1/transactions/fps/out/{}".format(mock_url,
                                                       transaction_id),
            headers=default_headers(mock_access_token),
            request_headers=expect_authorization_header(mock_access_token),
            json=expected_response)

        mocked_response = mock_object.get_transaction(
            transaction_id, source, access_token=mock_access_token)

        assert expected_response == mocked_response
Ejemplo n.º 18
0
def test_get_specific_card_transaction(requests_mock):
    mock_url = "http://localhost"
    mock_access_token = "0123456789"

    mock_object = Starling({"api_url": mock_url})

    transaction_id = "77b7d507-6546-4301-a841-fbf570de65c6"
    source = "MASTER_CARD"

    with open("test/responses/v1-get-transaction-card.json") as f:
        expected_response = json.load(f)

        requests_mock.get(
            "{}/api/v1/transactions/mastercard/{}".format(
                mock_url, transaction_id),
            headers=default_headers(mock_access_token),
            request_headers=expect_authorization_header(mock_access_token),
            json=expected_response)

        mocked_response = mock_object.get_transaction(
            transaction_id, source, access_token=mock_access_token)

        assert expected_response == mocked_response
Ejemplo n.º 19
0
def test_add_money_to_savings_goal(requests_mock):
    mock_url = "http://localhost"
    mock_access_token = "0123456789"

    mock_object = Starling({"api_url": mock_url})

    savings_goal_id = "12345-12345"
    transaction_id = "54321-54321"
    minor_amount = 111
    savings_currency = "BRL"

    requests_mock.put(
        "{}/api/v1/savings-goals/{}/add-money/{}".format(
            mock_url, savings_goal_id, transaction_id),
        headers=default_headers(mock_access_token),
        request_headers=expect_authorization_header(mock_access_token),
        status_code=202)

    mock_object.add_money_to_savings_goal(savings_goal_id,
                                          transaction_id,
                                          minor_amount,
                                          currency=savings_currency,
                                          access_token=mock_access_token)
Ejemplo n.º 20
0
def test_get_transactions(requests_mock):
    mock_url = "http://localhost"
    mock_access_token = "0123456789"

    mock_object = Starling({"api_url": mock_url})

    from_date = "2017-03-01"
    to_date = "2017-03-06"

    with open("test/responses/v1-get-transactions.json") as f:
        expected_response = json.load(f)

        requests_mock.get(
            "{}/api/v1/transactions?from={}&to={}".format(
                mock_url, from_date, to_date),
            headers=default_headers(mock_access_token),
            request_headers=expect_authorization_header(mock_access_token),
            json=expected_response)

        mocked_response = mock_object.get_transactions(
            "2017-03-01", "2017-03-06", "", access_token=mock_access_token)

        assert expected_response == mocked_response
Ejemplo n.º 21
0
def test_make_local_payment(requests_mock):
    mock_url = "http://localhost"
    mock_access_token = "0123456789"

    mock_object = Starling({"api_url": mock_url})

    destination_account_uid = "11eb8d9b-386a-43ba-825d-7edee5c6b01a"
    reference = "dinner"
    amount = "10"

    requests_mock.post(
        "{}/api/v1/payments/local".format(mock_url),
        headers=default_headers(mock_access_token),
        request_headers=expect_authorization_header(mock_access_token),
        status_code=202)

    try:
        mock_object.make_local_payment(destination_account_uid,
                                       reference,
                                       amount,
                                       access_token=mock_access_token)
        assert True
    except:
        assert False