Example #1
0
def test_update_schedule_set(
        client: TestClient, normal_user_token_headers: (Dict[str, str], User), db: Session
) -> None:
    deck = create_random_deck(db, user=normal_user_token_headers[1])
    data = []
    for idx in range(2):
        fact = create_random_fact_with_deck(db, user=normal_user_token_headers[1], deck=deck)
        data.append(Schedule(fact_id=fact.fact_id,
                             typed=random_lower_string(),
                             response=False,
                             elapsed_milliseconds_text=10,
                             elapsed_milliseconds_answer=10,
                             debug_id=random_lower_string()).dict())
    for idx in range(2):
        fact = create_random_fact_with_deck(db, user=normal_user_token_headers[1], deck=deck)
        data.append(Schedule(fact_id=fact.fact_id,
                             typed=fact.answer,
                             response=True,
                             elapsed_milliseconds_text=10,
                             elapsed_milliseconds_answer=10,
                             debug_id=random_lower_string()).dict())
    r = client.put(
        f"{settings.API_V1_STR}/study/", headers=normal_user_token_headers[0], json=data,
    )
    assert_success(response=r)
Example #2
0
def test_get_study_set_with_deck(
        client: TestClient, normal_user_token_headers: (Dict[str, str], User), db: Session
) -> None:
    deck = create_random_deck(db, user=normal_user_token_headers[1])
    facts = []
    for idx in range(5):
        facts.append(create_random_fact_with_deck(db, user=normal_user_token_headers[1], deck=deck))
    response = client.get(
        f"{settings.API_V1_STR}/study/?deck_id={deck.id}", headers=normal_user_token_headers[0],
    )
    assert_success(response)
Example #3
0
def test_mark_unowned_fact(client: TestClient,
                           normal_user_token_headers: (Dict[str, str], User),
                           db: Session) -> None:
    other_user = create_random_user(db)
    deck = create_random_deck(db, user=other_user)
    fact = create_random_fact_with_deck(db=db, user=other_user, deck=deck)
    user = normal_user_token_headers[1]
    crud.deck.assign_viewer(db=db, db_obj=deck, user=user)
    assert user is not fact.owner
    response = client.put(f"{settings.API_V1_STR}/facts/mark/{fact.fact_id}",
                          headers=normal_user_token_headers[0])
    content = assert_success(response)
    assert content["text"] == fact.text
    db.refresh(fact)
    assert user in fact.markers
Example #4
0
def create_random_fact(db: Session, user: models.User) -> models.Fact:
    text = random_lower_string()
    identifier = random_lower_string()
    answer = random_lower_string()
    deck = create_random_deck(db=db, user=user)
    deck_id = deck.id
    answer_lines = [answer]
    extra = {"type": "Noodles"}

    fact_in = FactCreate(text=text,
                         answer=answer,
                         deck_id=deck_id,
                         answer_lines=answer_lines,
                         identifier=identifier,
                         extra=extra)
    return crud.fact.create_with_owner(db=db, obj_in=fact_in, user=user)
Example #5
0
def test_update_unowned_fact_when_deck_viewer(client: TestClient,
                                              normal_user_token_headers: (
                                                  Dict[str, str], User),
                                              db: Session) -> None:
    other_user = create_random_user(db)
    deck = create_random_deck(db, user=other_user)
    fact = create_random_fact_with_deck(db=db, user=other_user, deck=deck)
    user = normal_user_token_headers[1]
    crud.deck.assign_viewer(db=db, db_obj=deck, user=user)
    assert user is not fact.owner
    new_text = random_lower_string()
    data = {"text": new_text}
    response = client.put(
        f"{settings.API_V1_STR}/facts/{fact.fact_id}",
        headers=normal_user_token_headers[0],
        json=data,
    )
    assert response.status_code == 401
Example #6
0
def test_report_unowned_fact(client: TestClient,
                             normal_user_token_headers: (Dict[str, str], User),
                             db: Session) -> None:
    other_user = create_random_user(db)
    deck = create_random_deck(db, user=other_user)
    fact = create_random_fact_with_deck(db=db, user=other_user, deck=deck)
    user = normal_user_token_headers[1]
    crud.deck.assign_viewer(db=db, db_obj=deck, user=user)
    assert user is not fact.owner
    suggestion = FactToReport(text="CHICKEN",
                              answer="NOODLES",
                              comment="THIS IS A REPORT").dict()
    response = client.put(f"{settings.API_V1_STR}/facts/report/{fact.fact_id}",
                          headers=normal_user_token_headers[0],
                          json=suggestion)
    content = assert_success(response)
    assert content["text"] == fact.text
    db.refresh(fact)
    assert user in fact.reporters
Example #7
0
def test_evaluate_answer(
        client: TestClient, normal_user_token_headers: (Dict[str, str], User), db: Session
) -> None:
    deck = create_random_deck(db, user=normal_user_token_headers[1])
    fact = create_random_fact_with_deck(db, user=normal_user_token_headers[1], deck=deck)
    typed = "Avada Kedavra"
    response = client.get(
        f"{settings.API_V1_STR}/study/evaluate?fact_id={fact.fact_id}&typed={typed}",
        headers=normal_user_token_headers[0],
    )
    evaluation = assert_success(response=response)
    assert not evaluation
    typed2 = fact.answer
    response2 = client.get(
        f"{settings.API_V1_STR}/study/evaluate?fact_id={fact.fact_id}&typed={typed2}",
        headers=normal_user_token_headers[0],
    )
    evaluation2 = assert_success(response=response2)
    assert evaluation2
Example #8
0
def test_update_unowned_fact_when_deck_owner(client: TestClient,
                                             normal_user_token_headers: (
                                                 Dict[str, str], User),
                                             db: Session) -> None:
    other_user = create_random_user(db)
    deck = create_random_deck(db, user=other_user)
    fact = create_random_fact_with_deck(db=db, user=other_user, deck=deck)
    user = normal_user_token_headers[1]
    crud.deck.assign_owner(db=db, db_obj=deck, user=user)
    assert user is not fact.owner
    old_text = fact.text
    new_text = random_lower_string()
    data = {"text": new_text}
    response = client.put(
        f"{settings.API_V1_STR}/facts/{fact.fact_id}",
        headers=normal_user_token_headers[0],
        json=data,
    )
    content = assert_success(response)
    db.refresh(fact)
    assert old_text != content["text"]
    assert new_text == content["text"]
    assert content["text"] == fact.text