Пример #1
0
def test_execute_get_success_with_multiple_pages():
    """ Test Multiple pages of response coming back """
    response_queue = queue.Queue()
    message = FakeMessage()
    message.raw_payload = json.dumps(TestData.JOB_TEMPLATE_PAYLOAD_ALL_PAGES)
    headers = {"Content-Type": "application/json"}

    with aioresponses() as mocked:
        mocked.get(
            TestData.JOB_TEMPLATES_LIST_URL,
            status=200,
            body=json.dumps(TestData.JOB_TEMPLATES_PAGE1_RESPONSE),
            headers=headers,
        )
        mocked.get(
            TestData.JOB_TEMPLATES_LIST_URL_PAGE_2,
            status=200,
            body=json.dumps(TestData.JOB_TEMPLATES_PAGE2_RESPONSE),
            headers=headers,
        )
        worker.execute(message, TestData.RECEPTOR_CONFIG, response_queue)

    validate_get_response(
        response_queue.get(),
        200,
        TestData.JOB_TEMPLATE_COUNT,
        [TestData.JOB_TEMPLATE_1, TestData.JOB_TEMPLATE_2],
    )
    validate_get_response(
        response_queue.get(),
        200,
        TestData.JOB_TEMPLATE_COUNT,
        [TestData.JOB_TEMPLATE_3],
    )
Пример #2
0
def test_execute_with_invalid_config_get_exception():
    """ When we have bad config raise an exception """
    message = FakeMessage()
    message.raw_payload = json.dumps(
        TestData.JOB_TEMPLATE_PAYLOAD_SINGLE_PAGE_GZIPPED)
    with aioresponses():
        with pytest.raises(Exception) as excinfo:
            worker.execute(message, TestData.RECEPTOR_CONFIG_INVALID,
                           queue.Queue())
        assert "token or username and password" in str(excinfo.value)
Пример #3
0
def test_execute_post_exception():
    """ HTTP POST Test with Exception """
    message = FakeMessage()
    message.raw_payload = json.dumps(TestData.JOB_TEMPLATE_POST_PAYLOAD)
    with aioresponses() as mocked:
        mocked.post(TestData.JOB_TEMPLATE_POST_URL,
                    status=400,
                    body="Bad Request in Post Call")
        with pytest.raises(Exception) as excinfo:
            worker.execute(message, TestData.RECEPTOR_CONFIG, queue.Queue())
        assert "Bad Request in Post Call" in str(excinfo.value)
Пример #4
0
def test_execute_get_exception():
    """ When we get a bad data from the server, raise an exception """
    message = FakeMessage()
    message.raw_payload = json.dumps(
        TestData.JOB_TEMPLATE_PAYLOAD_SINGLE_PAGE_GZIPPED)
    with aioresponses() as mocked:
        mocked.get(TestData.JOB_TEMPLATES_LIST_URL,
                   status=400,
                   body="Bad Request in Get Call")
        with pytest.raises(Exception) as excinfo:
            worker.execute(message, TestData.RECEPTOR_CONFIG, queue.Queue())
        assert "Bad Request in Get Call" in str(excinfo.value)
Пример #5
0
def test_execute_post_exception_invalid_filter():
    """ HTTP POST Test with an invalid JMESPath filter """
    message = FakeMessage()
    message.raw_payload = json.dumps(
        TestData.JOB_TEMPLATE_POST_BAD_FILTERED_PAYLOAD_GZIPPED)
    headers = {"Content-Type": "application/json"}
    with aioresponses() as mocked:
        mocked.post(
            TestData.JOB_TEMPLATE_POST_URL,
            status=200,
            body=json.dumps(TestData.JOB_TEMPLATE_POST_RESPONSE),
            headers=headers,
        )
        with pytest.raises(Exception):
            worker.execute(message, TestData.RECEPTOR_CONFIG, queue.Queue())
Пример #6
0
def run_get(config, payload, response):
    """ Run a HTTP GET Command """
    message = FakeMessage()
    message.raw_payload = payload
    response_queue = queue.Queue()
    headers = {"Content-Type": "application/json"}
    with aioresponses() as mocked:
        mocked.get(
            TestData.JOB_TEMPLATES_LIST_URL,
            status=200,
            body=json.dumps(response),
            headers=headers,
        )
        worker.execute(message, config, response_queue)

    return response_queue
Пример #7
0
def run_post(payload, response):
    """ Helper method to send a HTTP POST """
    message = FakeMessage()
    message.raw_payload = payload
    response_queue = queue.Queue()
    headers = {"Content-Type": "application/json"}
    with aioresponses() as mocked:
        mocked.post(
            TestData.JOB_TEMPLATE_POST_URL,
            status=200,
            body=json.dumps(response),
            headers=headers,
        )
        worker.execute(message, TestData.RECEPTOR_CONFIG, response_queue)

    return response_queue
Пример #8
0
def test_execute_get_with_bad_payload():
    """ GET Request where JSON decoding fails """
    message = FakeMessage()
    message.raw_payload = "fail string"
    with pytest.raises(json.JSONDecodeError):
        worker.execute(message, TestData.RECEPTOR_CONFIG, queue.Queue())