Exemplo n.º 1
0
def test_https_request_basic(get_patch):
    res_patch = mock.Mock(spec=requests.Response)
    res_patch.status_code = 200
    get_patch.return_value = res_patch
    api = API()
    api._set_auth("account_id", "username", "password")
    res = api.https_request("a real url", "get", {"test": 1})
Exemplo n.º 2
0
def test_session_with_headers():
    api = API()
    api._set_auth("account_id", "username", "password")
    session = api._session_with_headers()
    assert session.auth == ("username", "password")
    assert session.headers.get("Content-Type") == "application/json"
    assert session.headers.get("Accept") == "application/json"
Exemplo n.º 3
0
def test_https_request_too_many(get_patch):
    res_patch = mock.Mock(spec=requests.Response)
    res_patch.status_code = 429
    res_patch.content = "{'message': 'testing'}"
    get_patch.return_value = res_patch
    api = API()
    api._set_auth("account_id", "username", "password")
    res = api.https_request("a real url", "get", {"test": 1})
def test_https_request(request_mock):
    boomi = API()._set_auth("account_id", "username", "password")

    class MockResponse(object):
        def __init__(self, content=None):
            self.content = content

    request_mock.return_value = MockResponse(content='{"id": 123}')

    class TestType(Resource):
        _id_attr = "id"
        _attributes = ("id", )
        _name = "TestType"
        _uri = None
        _api = boomi
        supported = {"get": True, "query": False}

    newthing = TestType(id="hello")

    newthing.get("123")
    assert request_mock.called

    newthing.query()
Exemplo n.º 5
0
def test_init():
    api = API()
    api._set_auth("account_id", "username", "password")
    assert api.account_id == "account_id"
    assert api.username == "username"
    assert api.password == "password"
Exemplo n.º 6
0
def test_init_with_no_password():
    api = API()
    api._set_auth("account_id", "username", None)
Exemplo n.º 7
0
def test_init_with_no_username():
    api = API()
    api._set_auth("account_id", None, "password")
Exemplo n.º 8
0
def test_base_url_partner():
    api = API()
    api.account_id = "test"
    expected = "%s/test" % PARTNER_BASE_URL
    assert api.base_url(partner=True) == expected
Exemplo n.º 9
0
def test_base_url_no_partner():
    api = API()
    api._set_auth("account_id", "username", "password")
    api.account_id = "test"
    expected = "%s/test" % BASE_URL
    assert api.base_url() == expected