Beispiel #1
0
 def test_raises_a_protocol_error_if_an_error_is_present_in_the_response(self, mocked_post):
     mocked_response = unittest.mock.Mock(status_code=400, content='{}')
     mocked_response.json.return_value = {'type': 'bad'}
     mocked_post.return_value = mocked_response
     client = Client('id-123456789', 'secret-123456789')
     with pytest.raises(ProtocolError):
         client.user.authenticate('*****@*****.**', 'pwd123456')
Beispiel #2
0
 def test_raises_a_protocol_error_if_a_response_cannot_be_deserialized(self, mocked_post):
     mocked_response = unittest.mock.Mock(status_code=200, content='BAD')
     mocked_response.json.side_effect = ValueError()
     mocked_post.return_value = mocked_response
     client = Client('id-123456789', 'secret-123456789')
     with pytest.raises(ProtocolError):
         client.item.list()
Beispiel #3
0
 def test_raises_a_transport_error_if_an_unsuccessful_is_sent_back_from_the_service(
     self, mocked_post,
 ):
     mocked_response = unittest.mock.Mock(status_code=500, content='ERROR')
     mocked_response.raise_for_status.side_effect = HTTPError(response=mocked_response)
     mocked_post.return_value = mocked_response
     client = Client('id-123456789', 'secret-123456789')
     with pytest.raises(TransportError):
         client.item.list()
Beispiel #4
0
    def test_can_delete_an_item(self, mocked_delete):
        mocked_response = unittest.mock.Mock(status_code=200, content='{}')
        mocked_response.json.return_value = {}
        mocked_delete.return_value = mocked_response

        client = Client('id-123456789',
                        'secret-123456789',
                        access_token='accesstoken-123456789')
        result = client.item.delete(42)

        assert result == {}
        assert mocked_delete.call_args[0][
            0] == 'https://sync.bankin.com/v2/items/42'
Beispiel #5
0
    def test_can_send_mfa(self, mocked_post):
        mocked_response = unittest.mock.Mock(status_code=200, content='{}')
        mocked_response.json.return_value = {}
        mocked_post.return_value = mocked_response

        client = Client('id-123456789',
                        'secret-123456789',
                        access_token='accesstoken-123456789')
        result = client.item.send_mfa(42, 'otp')

        assert result == {}
        assert mocked_post.call_args[0][
            0] == 'https://sync.bankin.com/v2/items/42/mfa'
Beispiel #6
0
 def test_can_set_authentication_with_an_access_token(self):
     client = Client('id-123456789', 'secret-123456789')
     client.set_access_token('accesstoken-123456789')
     assert client.auth
     r = unittest.mock.MagicMock()
     r.headers = {}
     client.auth(r)
     assert r.headers['Authorization'] == 'Bearer accesstoken-123456789'
Beispiel #7
0
    def test_can_return_lists_of_items(self, mocked_get):
        mocked_response = unittest.mock.Mock(status_code=200, content='{}')
        mocked_response.json.return_value = {
            'results': [],
        }
        mocked_get.return_value = mocked_response

        client = Client('id-123456789',
                        'secret-123456789',
                        access_token='accesstoken-123456789')
        result = client.item.list()

        assert result == {'results': []}
        assert mocked_get.call_args[0][0] == 'https://sync.bankin.com/v2/items'
Beispiel #8
0
    def test_can_return_the_refresh_status_of_a_single_item(self, mocked_get):
        mocked_response = unittest.mock.Mock(status_code=200, content='{}')
        mocked_response.json.return_value = {
            'id': '42',
        }
        mocked_get.return_value = mocked_response

        client = Client('id-123456789',
                        'secret-123456789',
                        access_token='accesstoken-123456789')
        result = client.item.get_refresh_status(42)

        assert result == {'id': '42'}
        assert mocked_get.call_args[0][
            0] == 'https://sync.bankin.com/v2/items/42/refresh/status'
Beispiel #9
0
    def test_can_return_a_new_add_url(self, mocked_get):
        mocked_response = unittest.mock.Mock(status_code=200, content='{}')
        mocked_response.json.return_value = {
            'redirect_url': 'https://example.com',
        }
        mocked_get.return_value = mocked_response

        client = Client('id-123456789',
                        'secret-123456789',
                        access_token='accesstoken-123456789')
        result = client.item.add_url()

        assert result == {'redirect_url': 'https://example.com'}
        assert mocked_get.call_args[0][
            0] == 'https://sync.bankin.com/v2/items/add/url'
Beispiel #10
0
    def test_can_return_a_url_to_validate_pro_items(self, mocked_get):
        mocked_response = unittest.mock.Mock(status_code=200, content='{}')
        mocked_response.json.return_value = {
            'redirect_url': 'https://example.com'
        }
        mocked_get.return_value = mocked_response

        client = Client('id-123456789',
                        'secret-123456789',
                        access_token='accesstoken-123456789')
        result = client.item.validate_pro()

        assert result == {'redirect_url': 'https://example.com'}
        assert (
            mocked_get.call_args[0][0] ==
            'https://sync.bankin.com/v2/connect/items/pro/confirmation/url')
Beispiel #11
0
 def test_can_remove_configured_authentication(self):
     client = Client('id-123456789', 'secret-123456789')
     client.set_access_token('accesstoken-123456789')
     client.remove_auth()
     assert not client.auth