Пример #1
0
def test_sign_in_200():
    """
    Тест проверяет фунцию входа в аккаунт пользователя.
    """
    sign_up_response = requests.post(f"{HOST}/accounts/sign-up",
                                     json=create_valid_account_info())

    assert sign_up_response.status_code == 200, sign_up_response.text

    account = create_valid_account_info()
    del account["Name"]

    sign_in_response = requests.post(f"{HOST}/accounts/sign-in", json=account)

    assert sign_in_response.status_code == 200, sign_in_response.text
Пример #2
0
def test_sign_in_400_wrong_password():
    """
    Тест проверяет фунцию входа в аккаунт пользователя с вводом неверного пароля.
    """
    sign_up_response = requests.post(f"{HOST}/accounts/sign-up",
                                     json=create_valid_account_info())

    assert sign_up_response.status_code == 200, sign_up_response.text

    account = create_valid_account_info()
    account["Password"] += "test"

    sign_in_response = requests.post(f"{HOST}/accounts/sign-in", json=account)

    assert sign_in_response.status_code == 400, sign_in_response.text
    assert sign_in_response.json()["Error"]["Code"] == "PH101"
Пример #3
0
def test_sign_up_200():
    """
    Тест проверяет фунцию регистрации аккаунта пользователя.
    """
    r = requests.post(f"{HOST}/accounts/sign-up",
                      json=create_valid_account_info())

    assert r.status_code == 200, r.text
Пример #4
0
def test_sign_in_400_account_does_not_exist():
    """
    Запрещено осуществлять вход в систему, не зарегистрировавшись.
    """

    r = requests.post(f"{HOST}/accounts/sign-in",
                      json=create_valid_account_info())
    assert r.status_code == 400, r.text
    assert r.json()["Error"]["Code"] == "PH100"
Пример #5
0
def test_sign_up_400_email_is_empty():
    """
    Тест проверяет фунцию регистрации аккаунта без ввода e-mail пользователя.
    """
    account = create_valid_account_info()
    account["Email"] = ""

    r = requests.post(f"{HOST}/accounts/sign-up", json=account)

    assert r.status_code == 400, r.text
    assert r.json()["Error"]["Code"] == "PH204"
Пример #6
0
def test_sign_up_400_password_length_check_fails():
    """
    Тест проверяет фунцию регистрации аккаунта с нарушением минимальной длины пароля.
    """
    account = create_valid_account_info()
    account["Password"] = ""

    r = requests.post(f"{HOST}/accounts/sign-up", json=account)

    assert r.status_code == 400, r.text
    assert r.json()["Error"]["Code"] == "PH201"
Пример #7
0
def test_account_info_200():
    sign_up_response = requests.post(f"{HOST}/accounts/sign-up",
                                     json=create_valid_account_info())

    assert sign_up_response.status_code == 200, sign_up_response.text

    account_id = sign_up_response.json()["Account"]["ID"]
    x_auth_token = {"X-Auth-Token": sign_up_response.json()["Token"]}

    info_response = requests.get(f"{HOST}/accounts/{account_id}",
                                 headers=x_auth_token)

    assert info_response.status_code == 200, info_response.text
Пример #8
0
def test_sign_up_400_account_already_exists():
    """
    Тест проверяет фунцию регистрации аккаунта с уже существующими данными пользователя.
    """
    account = create_valid_account_info()

    r = requests.post(f"{HOST}/accounts/sign-up", json=account)

    assert r.status_code == 200, r.text

    r = requests.post(f"{HOST}/accounts/sign-up", json=account)

    assert r.status_code == 400, r.text
    assert r.json()["Error"]["Code"] == "PH202"
Пример #9
0
def test_repeated_create_offer_400():
    """
    По бизнес-логике запрещено создавать два оффера c одного аккаунта на один ивент.
    """

    sign_up_response = sign_up()

    assert sign_up_response.status_code == 200, sign_up_response.text

    account_token = {"X-Auth-Token": sign_up_response.json()["Token"]}

    create_events_response = requests.post(
        f"{HOST}/events",
        headers=account_token,
        json=create_valid_account_info()
    )

    assert create_events_response.status_code == 200, create_events_response.text

    event_id = create_events_response.json()["ID"]

    sign_up_response_2 = sign_up()

    assert sign_up_response_2.status_code == 200, sign_up_response_2.text

    account_id_2 = sign_up_response_2.json()["Account"]["ID"]
    account_2_token = {"X-Auth-Token": sign_up_response_2.json()["Token"]}

    create_offer_response_1 = requests.post(
        f"{HOST}/offers",
        headers=account_2_token,
        json={
            "AccountID": account_id_2,
            "EventID": event_id
        }
    )

    assert create_offer_response_1.status_code == 200, create_offer_response_1.text

    create_offer_response_2 = requests.post(
        f"{HOST}/offers",
        headers=account_2_token,
        json={
            "AccountID": account_id_2,
            "EventID": event_id
        }
    )
    assert create_offer_response_2.status_code == 400, create_offer_response_2.text
    assert "fails" in create_offer_response_2.text
Пример #10
0
def test_sign_out_204():
    """
    Тест проверяет фунцию выхода из аккаунта пользователя.
    """
    sign_up_response = requests.post(f"{HOST}/accounts/sign-up",
                                     json=create_valid_account_info())

    assert sign_up_response.status_code == 200, sign_up_response.text

    x_auth_token = {"X-Auth-Token": sign_up_response.json()["Token"]}

    sign_out_response = requests.delete(f"{HOST}/accounts/sign-out",
                                        headers=x_auth_token)

    assert sign_out_response.status_code == 204, sign_out_response.text
Пример #11
0
def test_sign_in_400_deleted_account():
    """
    Вход в удаленный аккаунт запрещен.
    """
    sign_up_response = requests.post(f"{HOST}/accounts/sign-up",
                                     json=create_valid_account_info())

    assert sign_up_response.status_code == 200, sign_up_response.text

    account_id = sign_up_response.json()["Account"]["ID"]
    x_auth_token = {"X-Auth-Token": sign_up_response.json()["Token"]}

    delete_account_response = requests.delete(f"{HOST}/accounts/{account_id}",
                                              headers=x_auth_token)

    assert delete_account_response.status_code == 204, delete_account_response.text

    account = create_valid_account_info()
    del account["Name"]

    sign_in_response = requests.post(f"{HOST}/accounts/sign-in", json=account)

    assert sign_in_response.status_code == 400, sign_in_response.text
    assert sign_in_response.json()["Error"]["Code"] == "PH100"
Пример #12
0
def test_delete_account_204():
    """
    Тест проверяет фунцию удаления аккаунта пользователя.
    """
    sign_up_response = requests.post(f"{HOST}/accounts/sign-up",
                                     json=create_valid_account_info())

    assert sign_up_response.status_code == 200, sign_up_response.text

    account_id = sign_up_response.json()["Account"]["ID"]
    x_auth_token = {"X-Auth-Token": sign_up_response.json()["Token"]}

    delete_account_response = requests.delete(f"{HOST}/accounts/{account_id}",
                                              headers=x_auth_token)

    assert delete_account_response.status_code == 204, delete_account_response.text