Beispiel #1
0
def test_add_add_update_get_get(client):
    doc_one_data_initial = example_data_basic.copy()
    doc_one_data_update = example_data_update.copy()
    doc_two_data = example_data_basic.copy()
    doc_two_data['tenant'] = "big-corp"
    doc_two_data['integration_type'] = "something-else"
    doc_one_keys = {
        'tenant': doc_one_data_initial['tenant'],
        'integration_type': doc_one_data_initial['integration_type']
    }
    doc_two_keys = {
        'tenant': doc_two_data['tenant'],
        'integration_type': doc_two_data['integration_type']
    }

    request_one = post(client, doc_one_data_initial)
    assert 200 == request_one.status_code
    assert 'added' in request_one.get_json()['message']

    request_two = post(client, doc_one_data_update)
    assert 200 == request_two.status_code
    assert 'updated' in request_two.get_json()['message']

    request_three = post(client, doc_two_data)
    assert 200 == request_three.status_code
    assert 'added' in request_three.get_json()['message']

    request_four = get(client, doc_two_keys)
    assert 200 == request_four.status_code
    assert doc_two_data == request_four.get_json()

    request_five = get(client, doc_one_keys)
    assert 200 == request_five.status_code
    assert example_data_merged == request_five.get_json()
Beispiel #2
0
def test_post_update(client):
    test_data_one = example_data_basic.copy()
    test_data_two = example_data_update.copy()
    with MongoClient() as mongo:
        # write the initial data to the database
        db = mongo.challenge
        db.integrations.insert_one(test_data_one)
        # test the method
        response = post(client, test_data_two)
        # check the status code is correct
        assert 200 == response.status_code
        # check that it's a valid json and that it's correct
        assert response.is_json
        assert {'message': 'data successfully updated'} == response.get_json()
        # get the object from the database
        data_object = db.integrations.find_one({
            'tenant':
            test_data_one['tenant'],
            'integration_type':
            test_data_one['integration_type']
        })
        # check that there is one
        assert data_object is not None
        # check that the ids are the same
        assert test_data_one['_id'] == data_object['_id']
        data_object.pop('_id')
        # check that the data is correct
        assert data_object == example_data_merged
Beispiel #3
0
def test_post_fail_id_included(client):
    test_data = example_data_basic.copy()
    test_data['_id'] = "CompleteRubbish"
    response = post(client, test_data)
    with MongoClient() as mongo:
        db = mongo.challenge
        assert db.integrations.find_one(test_data) is None
        assert 400 == response.status_code
        assert response.is_json
        assert {
            "error": 400,
            'message': 'illegal variable(s) were found'
        } == response.get_json()
Beispiel #4
0
def test_post_fail_no_integration_type(client):
    test_data = example_data_basic.copy()
    test_data.pop('integration_type')
    response = post(client, test_data)
    with MongoClient() as mongo:
        db = mongo.challenge
        assert db.integrations.find_one(test_data) is None
        assert 400 == response.status_code
        assert response.is_json
        assert {
            "error": 400,
            'message': 'required variable(s) are missing'
        } == response.get_json()
Beispiel #5
0
def test_add_get(client):
    test_data = example_data_basic.copy()
    response_one = post(client, test_data)
    assert 200 == response_one.status_code
    assert 'added' in response_one.get_json()['message']
    get_vars = {
        'tenant': test_data['tenant'],
        'integration_type': test_data['integration_type']
    }

    response_two = get(client, get_vars)
    assert 200 == response_two.status_code
    assert response_two.is_json
    assert test_data == response_two.get_json()
Beispiel #6
0
def test_add_update_get(client):
    initial_test_data = example_data_basic.copy()
    update_test_data = example_data_update.copy()
    response_one = post(client, initial_test_data)
    assert 200 == response_one.status_code
    assert 'added' in response_one.get_json()['message']
    get_vars = {
        'tenant': initial_test_data['tenant'],
        'integration_type': initial_test_data['integration_type']
    }

    response_two = post(client, update_test_data)
    assert 200 == response_two.status_code
    assert 'updated' in response_two.get_json()['message']

    response_three = get(client, get_vars)
    assert 200 == response_three.status_code
    assert response_three.get_json() == example_data_merged
Beispiel #7
0
def test_post_add(client):
    test_data = example_data_basic.copy()
    response = post(client, test_data)
    # check that it returned the correct status code
    assert 200 == response.status_code
    # check that the response is correct
    assert response.is_json
    assert {'message': 'data successfully added'} == response.get_json()
    with MongoClient() as mongo:
        db = mongo.challenge
        # find the data in the database
        data_object = db.integrations.find_one({
            'tenant':
            test_data['tenant'],
            'integration_type':
            test_data['integration_type']
        })
        # check that there's something there
        assert data_object is not None
        data_object.pop('_id')
        # check that the data is correct.
        assert data_object == example_data_basic
Beispiel #8
0
def test_post_two_adds_same_tenant(client):
    test_data_one = example_data_basic.copy()
    test_data_two = example_data_update.copy()
    test_data_two['integration_type'] = 'pilot-scheduling-system'
    assert test_data_one['tenant'] == test_data_two['tenant']
    assert test_data_one['integration_type'] != test_data_two[
        'integration_type']

    response_one = post(client, test_data_one)
    assert 200 == response_one.status_code
    assert response_one.is_json
    assert {'message': 'data successfully added'} == response_one.get_json()

    response_two = post(client, test_data_two)
    assert 200 == response_two.status_code
    assert response_two.is_json
    assert {'message': 'data successfully added'} == response_two.get_json()

    with MongoClient() as mongo:
        db = mongo.challenge
        assert db.integrations.count_documents(
            {'tenant': test_data_one['tenant']}) == 2
Beispiel #9
0
def test_post_add_then_update(client):
    test_data_one = example_data_basic.copy()
    test_data_two = example_data_update.copy()
    # check that they have the same tenant and integration type
    assert test_data_one['tenant'] == test_data_two['tenant']
    assert test_data_one['integration_type'] == test_data_two[
        'integration_type']
    search_data = {
        'tenant': test_data_one['tenant'],
        'integration_type': test_data_one['integration_type']
    }
    with MongoClient() as mongo:
        db = mongo.challenge

        # test the first response
        response_one = post(client, test_data_one)
        assert 200 == response_one.status_code
        assert response_one.is_json
        assert {
            'message': 'data successfully added'
        } == response_one.get_json()
        result_data_one = db.integrations.find_one(search_data)
        id_one = result_data_one.pop('_id')
        assert result_data_one == example_data_basic

        # test the second
        response_two = post(client, test_data_two)
        assert 200 == response_two.status_code
        assert response_two.is_json
        assert {
            'message': 'data successfully updated'
        } == response_two.get_json()
        result_data_two = db.integrations.find_one(search_data)
        id_two = result_data_two.pop("_id")
        assert result_data_two == example_data_merged

        # make sure that they have the same object_id
        assert id_one == id_two