def test_patch_should_not_inactivate_all_feature_in_all_environment_because_missing_token(
        http_client, jwt_token, feature_name):
    # ARRANGE
    response = http_client.get("/v1/applications/netflix/features/",
                               headers=prepare_headers(jwt_token))
    assert response.status_code == status.HTTP_200_OK
    initial_features = response.json()
    assert len(initial_features) > 0
    # ACT
    response = http_client.patch(
        "/v1/applications/netflix/features/inactivate-all",
        headers=prepare_headers())
    # ASSERT
    assert response.status_code == status.HTTP_200_OK
    json = response.json()
    assert "Not authenticated" in json["errors"]
Пример #2
0
def test_get_should_return_applications_of_user_logged(http_client, jwt_token):
    # ARRANGE & ACT
    response = http_client.get("/v1/applications", headers=prepare_headers(jwt_token))
    # ASSERT
    assert response.status_code == status.HTTP_200_OK
    json = response.json()
    assert len(json) >= 3
Пример #3
0
def test_get_by_name_should_not_return_applications_because_application_not_exists(http_client, jwt_token, application):
    # ARRANGE & ACT
    response = http_client.get(f"/v1/applications/{application}", headers=prepare_headers(jwt_token))
    # ASSERT
    assert response.status_code == status.HTTP_200_OK
    json = response.json()
    assert f"Not found or Not permission access application {application}" in json["errors"]
Пример #4
0
def test_remove_should_remove_user(http_client, jwt_token):
    # ARRANGE
    response = http_client.patch("/v1/applications/netflix/users/",
                                 headers=prepare_headers(),
                                 json={"user_id": 3})
    assert response.status_code == status.HTTP_200_OK
    response = http_client.get("/v1/applications/netflix/users",
                               headers=prepare_headers(jwt_token))
    assert response.status_code == status.HTTP_200_OK
    users = response.json()
    # ACT
    response = http_client.delete("/v1/applications/netflix/users/3",
                                  headers=prepare_headers(jwt_token))
    assert response.status_code == status.HTTP_200_OK
    json = response.json()
    assert len(users) != len(json)
def test_delete_should_not_feature_application_because_missing_token(
        http_client, jwt_token, feature_name):
    # ARRANGE & ACT
    response = http_client.get("/v1/applications/netflix/features/",
                               headers=prepare_headers(jwt_token))
    assert response.status_code == status.HTTP_200_OK
    initial_features = response.json()
    assert len(initial_features) > 0
    # ACT
    response = http_client.delete(
        f"/v1/applications/netflix/features/{feature_name}",
        headers=prepare_headers())
    # ASSERT
    assert response.status_code == status.HTTP_200_OK
    json = response.json()
    assert "Not authenticated" in json["errors"]
Пример #6
0
def test_get_by_name_should_not_return_applications_because_missing_token(http_client, jwt_token, application):
    # ARRANGE & ACT
    response = http_client.get(f"/v1/applications/{application}", headers=prepare_headers())
    # ASSERT
    assert response.status_code == status.HTTP_200_OK
    json = response.json()
    assert "Not authenticated" in json["errors"]
def test_delete_should_feature_application(http_client, jwt_token,
                                           feature_name):
    # ARRANGE & ACT
    response = http_client.get("/v1/applications/netflix/features/",
                               headers=prepare_headers(jwt_token))
    assert response.status_code == status.HTTP_200_OK
    initial_features = response.json()
    assert len(initial_features) > 0
    # ACT
    response = http_client.delete(
        f"/v1/applications/netflix/features/{feature_name}",
        headers=prepare_headers(jwt_token))
    # ASSERT
    assert response.status_code == status.HTTP_200_OK
    json = response.json()
    assert len(initial_features) != len(json)
Пример #8
0
def test_patch_should_not_create_user_because_field_is_invalid(
        http_client, jwt_token):
    # ARRANGE & ACT
    response = http_client.patch("/v1/applications/netflix/users/",
                                 headers=prepare_headers(jwt_token),
                                 json={"x": "x"})
    # ASSERT
    assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY
Пример #9
0
def test_get_by_name_should_return_applications_of_user_logged(http_client, jwt_token, application):
    # ARRANGE & ACT
    response = http_client.get(f"/v1/applications/{application}", headers=prepare_headers(jwt_token))
    # ASSERT
    assert response.status_code == status.HTTP_200_OK
    json = response.json()
    assert "name" in json.keys()
    assert json["name"] == application
Пример #10
0
def test_get_should_not_paginate_users_because_missing_token(http_client):
    # ARRANGE & ACT
    response = http_client.get("/v1/users/paginate/1/10",
                               headers=prepare_headers())
    # ASSERT
    assert response.status_code == status.HTTP_200_OK
    json = response.json()
    assert "Not authenticated" in json["errors"]
def test_patch_should_inactivate_all_feature_in_all_environment(
        http_client, jwt_token, feature_name):
    # ARRANGE
    response = http_client.get("/v1/applications/netflix/features/",
                               headers=prepare_headers(jwt_token))
    assert response.status_code == status.HTTP_200_OK
    initial_features = response.json()
    assert len(initial_features) > 0
    # ACT
    response = http_client.patch(
        "/v1/applications/netflix/features/inactivate-all",
        headers=prepare_headers(jwt_token))
    # ASSERT
    assert response.status_code == status.HTTP_200_OK
    json = response.json()
    for feature in json:
        assert not feature["enable"]
Пример #12
0
def test_remove_should_not_remove_user_because_missing_token(
        http_client, user_id):
    # ARRANGE
    response = http_client.delete("/v1/applications/netflix/users/{user_id}",
                                  headers=prepare_headers())
    # ASSERT
    assert response.status_code == status.HTTP_200_OK
    json = response.json()
    assert "Not authenticated" in json["errors"]
Пример #13
0
def test_patch_should_create_user_in_application(http_client, jwt_token):
    # ARRANGE & ACT
    response = http_client.patch("/v1/applications/netflix/users/",
                                 headers=prepare_headers(jwt_token),
                                 json={"user_id": 3})
    # ASSERT
    assert response.status_code == status.HTTP_200_OK
    json = response.json()
    assert len(json) > 1
Пример #14
0
def test_get_by_email_should_return_user(http_client, jwt_token, email):
    # ARRANGE & ACT
    response = http_client.get(f"/v1/users/{email}",
                               headers=prepare_headers(jwt_token))
    # ASSERT
    assert response.status_code == status.HTTP_200_OK
    json = response.json()
    assert "email" in json.keys()
    assert json["email"] == email
Пример #15
0
def test_get_should_not_return_because_user_doesnt_have_permission(
        http_client, jwt_token):
    # ARRANGE & ACT
    response = http_client.get("/v1/applications/botica/users",
                               headers=prepare_headers(jwt_token))
    # ASSERT
    assert response.status_code == status.HTTP_200_OK
    json = response.json()
    assert json == []
Пример #16
0
def test_post_should_not_execute_because_missing_field_description(http_client, jwt_token):
    # ARRANGE & ACT
    application = {
        "real_name": "Python",
        "model": 3,
        "details": "https://python.org"
    }
    response = http_client.post("/v1/applications/", headers=prepare_headers(jwt_token), json=application)
    # ASSERT
    assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY
Пример #17
0
def test_get_by_email_should_not_return_user_because_doesnt_exists(
        http_client, jwt_token, email):
    # ARRANGE & ACT
    response = http_client.get(f"/v1/users/{email}",
                               headers=prepare_headers(jwt_token))
    # ASSERT
    assert response.status_code == status.HTTP_200_OK
    json = response.json()
    assert "errors" in json.keys()
    assert f"{email} doesn't exists" in json["errors"]
Пример #18
0
def test_patch_should_not_create_user_because_missing_token(
        http_client, jwt_token):
    # ARRANGE & ACT
    response = http_client.patch("/v1/applications/netflix/users/",
                                 headers=prepare_headers(),
                                 json={"user_id": 3})
    # ASSERT
    assert response.status_code == status.HTTP_200_OK
    json = response.json()
    assert "Not authenticated" in json["errors"]
Пример #19
0
def test_post_should_not_execute_because_missing_field_real_name(http_client, jwt_token):
    # ARRANGE & ACT
    application = {
        "model": 3,
        "description": "Sending and receive videos, messages, gifs, documents...",
        "details": "https://slack.com.br"
    }
    response = http_client.post("/v1/applications/", headers=prepare_headers(jwt_token), json=application)
    # ASSERT
    assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY
def test_patch_should_create_new_feature(http_client, jwt_token, feature_name):
    # ARRANGE
    response = http_client.get("/v1/applications/netflix/features/",
                               headers=prepare_headers(jwt_token))
    assert response.status_code == status.HTTP_200_OK
    initial_features = response.json()
    assert len(initial_features) > 0
    new_feature = {
        "environment_id": 4,
        "name": feature_name,
        "enable": True,
    }
    # ACT
    response = http_client.patch("/v1/applications/netflix/features/",
                                 headers=prepare_headers(jwt_token),
                                 json=new_feature)
    # ASSERT
    assert response.status_code == status.HTTP_200_OK
    json = response.json()
    assert len(initial_features) != len(json)
Пример #21
0
def test_patch_should_not_create_user_because_user_not_exists(
        http_client, jwt_token):
    # ARRANGE & ACT
    response = http_client.patch("/v1/applications/netflix/users/",
                                 headers=prepare_headers(jwt_token),
                                 json={"user_id": 999999999})
    # ASSERT
    assert response.status_code == status.HTTP_200_OK
    json = response.json()
    assert "The user(999999999) cannot possible to add in application netflix" in json[
        "errors"]
Пример #22
0
def test_post_should_not_execute_because_field_real_name_is_invalid(http_client, jwt_token, real_name):
    # ARRANGE & ACT
    application = {
        "real_name": real_name,
        "model": 3,
        "description": get_bigger_text(),
        "details": "https://slack.com.br"
    }
    response = http_client.post("/v1/applications/", headers=prepare_headers(jwt_token), json=application)
    # ASSERT
    assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY
def test_patch_should_not_create_new_feature_because_missing_token(
        http_client, jwt_token):
    # ARRANGE
    response = http_client.get("/v1/applications/netflix/features/",
                               headers=prepare_headers(jwt_token))
    assert response.status_code == status.HTTP_200_OK
    initial_features = response.json()
    assert len(initial_features) > 0
    new_feature = {
        "environment_id": 4,
        "name": "test",
        "enable": True,
    }
    # ACT
    response = http_client.patch("/v1/applications/netflix/features/",
                                 headers=prepare_headers(),
                                 json=new_feature)
    # ASSERT
    assert response.status_code == status.HTTP_200_OK
    json = response.json()
    assert "Not authenticated" in json["errors"]
Пример #24
0
def test_post_should_not_execute_because_missing_token(http_client):
    # ARRANGE & ACT
    application = {
        "real_name": "Office365",
        "model": 3,
        "description": "Microsoft utilities",
        "details": "https://office365.com"
    }
    response = http_client.post("/v1/applications/", headers=prepare_headers(), json=application)
    # ASSERT
    assert response.status_code == status.HTTP_200_OK
    json = response.json()
    assert "Not authenticated" in json["errors"]
Пример #25
0
def test_post_should_execute_success(http_client, jwt_token):
    # ARRANGE & ACT
    application = {
        "real_name": "Slack",
        "model": 3,
        "description": "Sending and receive videos, messages, gifs, documents...",
        "details": "https://slack.com.br"
    }
    response = http_client.post("/v1/applications/", headers=prepare_headers(jwt_token), json=application)
    # ASSERT
    assert response.status_code == status.HTTP_201_CREATED
    json = response.json()
    assert "name" in json.keys()
    assert json["name"] == "slack"
Пример #26
0
def test_get_should_return_correct_paginate_users(http_client, jwt_token):
    # ARRANGE & ACT
    response_page_1 = http_client.get("/v1/users/paginate/1/5",
                                      headers=prepare_headers(jwt_token))
    response_page_2 = http_client.get("/v1/users/paginate/1/10",
                                      headers={
                                          "Content-Type": "application/json",
                                          "Authorization":
                                          f"Bearer {jwt_token}"
                                      })
    # ASSERT
    assert response_page_1.status_code == status.HTTP_200_OK
    assert response_page_2.status_code == status.HTTP_200_OK
    json_1 = response_page_1.json()
    json_2 = response_page_2.json()
    assert len(json_1) == 5
    assert len(json_2) == 10