def test_check_headers(): for headers in [{}, None, [], (), 0, '']: res, msg = client.check_headers(headers) assert not res assert "empty headers" in msg.lower() for headers in [['content-type'], ('content-type'), 1, 'content-type']: res, msg = client.check_headers(headers) assert not res assert "headers should be a dictionnary" in msg.lower() d1 = { 'content-type': '', } d2 = { 'x-mailerlite-apikey': '', } for headers in [d1, d2]: res, msg = client.check_headers(headers) assert not res assert "'content-type' and 'x-mailerlite-apikey'" in msg.lower() headers = { 'content-type': "application/json", 'x-mailerlite-apikey': API_KEY_TEST } res, msg = client.check_headers(headers) assert res assert not msg
def __init__(self, headers): """Initialize Campaigns object. Parameters ---------- headers : dict request header containing your mailerlite api_key. More information : https://developers.mailerlite.com/docs/request """ valid_headers, error_msg = client.check_headers(headers) if not valid_headers: raise ValueError(error_msg) self.headers = headers