Exemplo n.º 1
0
def test_get_mural_exists_returns_the_mural(fake_environment, murals_table):
    expected = {
        "id": "test-1",
        "artist_name_en": "artist-1",
        "attribute-1": "attribute-1",
    }
    murals_table.put_item(Item=expected)
    murals_table.put_item(
        Item={
            "id": "test-1",
            "artist_name_en": "artist-2",
            "attribute-2": "attribute-2",
        })

    event = {
        "requestContext": {
            "httpMethod": "GET"
        },
        "pathParameters": {
            "mural_id": expected["id"],
            "artist_name_en": expected["artist_name_en"],
        },
    }

    context = Mock()

    actual = lambda_handler(event, context)

    assert actual["statusCode"] == HTTPStatus.OK
    assert json.loads(actual["body"]) == expected
Exemplo n.º 2
0
def test_update_mural_when_exists_updates_mural(fake_environment, murals_table):
    murals_table.put_item(
        Item={
            "id": "test-1",
            "artist_name_en": "artist-2",
            "attribute-2": "attribute-2",
        }
    )
    expected = {
        "id": "test-1",
        "artist_name_en": "artist-1",
        "attribute-1": "attribute-1",
    }
    event = {
        "requestContext": {"httpMethod": "PUT"},
        "pathParameters": {
            "mural_id": "test-1",
            "artist_name_en": "artist-2",
        },
        "body": json.dumps(expected),
    }
    context = Mock()

    actual = lambda_handler(event, context)
    assert actual["statusCode"] == HTTPStatus.NO_CONTENT
    scan_result = murals_table.scan()
    assert scan_result["Count"] == 1
    actual_mural = scan_result["Items"][0]
    assert actual_mural == expected
def test_delete_mural_when_exists_deletes_mural(fake_environment,
                                                murals_table):
    murals_table.put_item(
        Item={
            "id": "test-id",
            "artist_name_en": "some-artist",
            "attribute-2": "attribute-2",
        })
    event = {
        "requestContext": {
            "httpMethod": "DELETE"
        },
        "pathParameters": {
            "mural_id": "test-id",
            "artist_name_en": "some-artist",
        },
    }
    context = Mock()

    scan_result = murals_table.scan()
    assert scan_result["Count"] == 1
    actual = lambda_handler(event, context)

    assert actual["statusCode"] == HTTPStatus.OK
    scan_result = murals_table.scan()
    assert scan_result["Count"] == 0
Exemplo n.º 4
0
def test_get_all_murals_when_empty_table_returns_empty_list(
        fake_environment, murals_table):
    event = {"requestContext": {"httpMethod": "GET"}, "pathParameters": None}

    context = Mock()

    actual = lambda_handler(event, context)
    assert actual["statusCode"] == HTTPStatus.OK
    assert len(json.loads(actual["body"])["items"]) == 0
Exemplo n.º 5
0
def test_post_request_existing_mural_returns_conflict(fake_environment, murals_table):
    event = {
        "requestContext": {"httpMethod": "POST"},
        "body": json.dumps(
            {
                "id": "test-id",
                "artist_name_en": "some artist",
                "another_attribute": "some attribute",
            }
        ),
    }
    context = Mock()

    actual = lambda_handler(event, context)
    assert actual["statusCode"] == HTTPStatus.CREATED

    actual = lambda_handler(event, context)
    assert actual["statusCode"] == HTTPStatus.CONFLICT
Exemplo n.º 6
0
def test_get_mural_does_not_exist_returns_not_found(fake_environment,
                                                    murals_table):
    event = {
        "requestContext": {
            "httpMethod": "GET"
        },
        "pathParameters": {
            "mural_id": "test-id",
            "artist_name_en": "some artist",
        },
    }
    context = Mock()

    actual = lambda_handler(event, context)

    assert actual["statusCode"] == HTTPStatus.NOT_FOUND
Exemplo n.º 7
0
def test_post_request_new_mural_without_artist_name_creates_mural(
    fake_environment, murals_table
):
    event = {
        "requestContext": {"httpMethod": "POST"},
        "body": json.dumps({"id": "test-id", "another_attribute": "some attribute"}),
    }
    context = Mock()
    actual = lambda_handler(event, context)

    assert actual["statusCode"] == HTTPStatus.CREATED

    response = murals_table.get_item(Key={"id": "test-id", "artist_name_en": "unknown"})
    assert response["Item"]["id"] == "test-id"
    assert response["Item"]["artist_name_en"] == "unknown"
    assert response["Item"]["another_attribute"] == "some attribute"
Exemplo n.º 8
0
def test_update_mural_when_does_not_exist_returns_not_found(
    fake_environment, murals_table
):
    event = {
        "requestContext": {"httpMethod": "PUT"},
        "pathParameters": {
            "mural_id": "test-id",
            "artist_name_en": "some artist",
        },
        "body": json.dumps(
            {
                "id": "test-id",
                "artist_name_en": "some artist",
                "another_attribute": "some attribute",
            }
        ),
    }
    context = Mock()

    actual = lambda_handler(event, context)
    assert actual["statusCode"] == HTTPStatus.NOT_FOUND
Exemplo n.º 9
0
def test_get_all_murals_when_table_has_murals_result_contains_only_specified_fields(
        fake_environment, murals_table):
    item = {
        "id": "test-1",
        "artist_name_en": "artist-1",
        "attribute-1": "attribute-1",
        "attribute-2": "attribute-2",
        "geo_position": {
            "latitude": 1,
            "longitude": 1
        },
        "thumbnail": "dickpic",
        "mural_status": "active",
    }
    expected = {
        "id": "test-1",
        "artist_name_en": "artist-1",
        "geo_position": {
            "latitude": 1,
            "longitude": 1
        },
        "thumbnail": "dickpic",
        "mural_status": "active",
    }
    murals_table.put_item(Item=item)

    event = {
        "requestContext": {
            "httpMethod": "GET"
        },
    }

    context = Mock()

    actual = lambda_handler(event, context)
    assert actual["statusCode"] == HTTPStatus.OK
    actual_items = json.loads(actual["body"])["items"]
    assert len(actual_items) == 1
    assert actual_items[0] == expected
Exemplo n.º 10
0
def test_get_all_murals_when_table_has_murals_returns_list_with_all_murals(
        fake_environment, murals_table):
    num_murals = 200
    for i in range(num_murals):
        item = {
            "id": f"test-{i}",
            "artist_name_en": f"artist-{i}",
            "attribute-1": "attribute-1",
        }
        murals_table.put_item(Item=item)

    event = {
        "requestContext": {
            "httpMethod": "GET"
        },
    }

    context = Mock()

    actual = lambda_handler(event, context)
    assert actual["statusCode"] == HTTPStatus.OK
    assert len(json.loads(actual["body"])["items"]) == num_murals