def test_team_member_mood_get_team_moods_success(db_session,
                                                 test_users_and_teams,
                                                 default_moods):
    test_user1, test_user2, test_team1, test_team2 = test_users_and_teams
    awful, _, _, _, amazing = default_moods

    token = create_access_token(test_user1.id)
    header = {"Authorization": f"Bearer {token}"}

    create_team_member_mood(db=db_session,
                            user=test_user1,
                            team=test_team1,
                            mood=awful)
    create_team_member_mood(db=db_session,
                            user=test_user1,
                            team=test_team1,
                            mood=amazing)
    response = client.get(
        f"/team_member_moods/?team_id={test_team1.public_id}", headers=header)
    json_response = response.json()

    assert response.status_code == 200
    assert any(item["mood"]["public_id"] == awful.public_id
               for item in json_response)
    assert any(item["mood"]["public_id"] == amazing.public_id
               for item in json_response)
def test_team_member_mood_post_single_mood_addition(db_session,
                                                    test_users_and_teams,
                                                    default_moods):
    test_user1, _, test_team1, _ = test_users_and_teams
    awful, _, _, _, _ = default_moods
    token = create_access_token(test_user1.id)
    header = {"Authorization": f"Bearer {token}"}
    member_mood = TeamMemberMoodCreate(team_id=test_team1.public_id,
                                       mood_id=awful.public_id)
    response = client.post("/team_member_moods/",
                           json=member_mood.dict(),
                           headers=header)

    json_response = response.json()

    assert response.status_code == 201
    assert json_response["team"]["public_id"] == test_team1.public_id
    assert json_response["mood"]["public_id"] == awful.public_id

    # The created at time is within the last 30 seconds
    created_at = parse(json_response["mood"]["created_at"])
    delta = created_at - datetime.today()
    assert delta.total_seconds() < 30

    assert "user" not in json_response
    assert "public_id" in json_response
示例#3
0
def default_user_auth_header(request, default_db_user):
    """
    Test fixture for overriding the login_required token
    """
    token = create_access_token(default_db_user.id)
    header = {"Authorization": f"Bearer {token}"}
    return header
示例#4
0
def test_login_required_succeeds(db_session, default_db_user):
    token = create_access_token(default_db_user.id)
    header = {"Authorization": f"Bearer {token}"}
    response = client.get(f"/users/{default_db_user.public_id}",
                          headers=header)

    assert response.status_code == 200
示例#5
0
def test_login_required_fails_with_invalid_users_token(db_fixture, test_db_user):
    user = test_db_user
    token = create_access_token(44)
    header = {"Authorization": f"Bearer {token}"}
    response = client.get(f"/users/{user.id}", headers=header)

    assert response.status_code == 401
    assert "Could not validate credentials" in response.json()["detail"]
示例#6
0
def test_login_required_fails_with_none_token(db_session, default_db_user):
    user = default_db_user
    token = create_access_token(None)
    header = {"Authorization": f"Bearer {token}"}
    response = client.get(f"/users/{user.public_id}", headers=header)

    assert response.status_code == 401
    assert "Could not validate credentials" in response.json()["detail"]
def test_team_member_moods_post_fails_with_invalid_user(
        db_session, test_users_and_teams, default_moods):
    test_user1, _, test_team1, _ = test_users_and_teams
    awful, _, _, _, _ = default_moods

    # Create token for invalid id
    token = create_access_token(44)
    header = {"Authorization": f"Bearer {token}"}
    member_mood = TeamMemberMoodCreate(team_id=test_team1.public_id,
                                       mood_id=awful.public_id)
    response = client.post("/team_member_moods/",
                           json=member_mood.dict(),
                           headers=header)

    assert response.status_code == 401
    assert "Could not validate credentials" in response.json()["detail"]
def test_team_member_moods_post_fails_with_invalid_team(
        db_session, test_users_and_teams, default_moods):
    invalid_id = "invalid-id"
    test_user1, _, _, _ = test_users_and_teams
    awful, _, _, _, _ = default_moods
    token = create_access_token(test_user1.id)
    header = {"Authorization": f"Bearer {token}"}

    member_mood = TeamMemberMoodCreate(team_id=invalid_id, mood_id=invalid_id)

    response = client.post("/team_member_moods/",
                           json=member_mood.dict(),
                           headers=header)
    json_response = response.json()
    assert response.status_code == 404
    assert json_response[
        "detail"] == f"The team with id {invalid_id} does not exist"