Exemplo n.º 1
0
def test_create_user(app, uuid):
    from captaina.models import User, create_user
    new_user = User()
    assert not new_user.is_valid()
    new_user = create_user(uuid, "pass")
    assert new_user.is_valid()
    new_user.save()
    with pytest.raises(pymongo.errors.DuplicateKeyError):
        new_user.save(force_insert=True)
    with pytest.raises(ValueError):
        other_user = create_user(uuid, "hunter1")
Exemplo n.º 2
0
def test_login(client, uuid):
    from captaina.models import create_user
    create_user(uuid, 'password')
    response = login(client, uuid, 'password')
    assert b'You were logged in' in response.data
    logout(client)

    response = login(client, uuid, 'hunter2')
    assert b'Invalid password' in response.data

    response = login(client, 'unknown', 'pass')
    assert b'Invalid username' in response.data
Exemplo n.º 3
0
def test_lesson_record_cookie_exchange(app, uuid_generator):
    from captaina.models import create_user, AudioRecord, Prompt,\
            create_lesson_with_safe_url_id, ensure_and_get_incomplete_lesson_record,\
            cookie_from_lesson_record, lesson_record_from_cookie
    #Copied lengthy setup above:
    lesson = create_lesson_with_safe_url_id(uuid_generator())
    first_prompt = Prompt(text="Karviaismarjakausi ei ole ohi",
                          graph_id=uuid_generator()).save()
    second_prompt = Prompt(text="Pelkkää makkaraa ei kannata pitää ravintona",
                           graph_id=uuid_generator()).save()
    lesson.prompts = [first_prompt, second_prompt]
    lesson.save()
    user = create_user(uuid_generator(), "pass")
    lesson_record = ensure_and_get_incomplete_lesson_record(user, lesson)
    #Now the test:
    secret_key = uuid_generator()
    cookie = cookie_from_lesson_record(lesson_record, secret_key)
    recovered_record = lesson_record_from_cookie(cookie, secret_key)
    assert lesson_record == recovered_record
Exemplo n.º 4
0
def test_create_lesson_records(app, uuid_generator):
    from captaina.models import create_user, AudioRecord, Prompt,\
            create_lesson_with_safe_url_id, ensure_and_get_incomplete_lesson_record
    #Lengthy setup:
    lesson = create_lesson_with_safe_url_id(uuid_generator())
    first_prompt = Prompt(text="Karviaismarjakausi ei ole ohi",
                          graph_id=uuid_generator()).save()
    second_prompt = Prompt(text="Pelkkää makkaraa ei kannata pitää ravintona",
                           graph_id=uuid_generator()).save()
    lesson.prompts = [first_prompt, second_prompt]
    lesson.save()
    user = create_user(uuid_generator(), "pass")
    #Now the test portion:
    lesson_record = ensure_and_get_incomplete_lesson_record(user, lesson)
    other_lesson_record = ensure_and_get_incomplete_lesson_record(user, lesson)
    assert lesson_record == other_lesson_record
    first_audio_record = AudioRecord(user=user,
                                     prompt=first_prompt,
                                     filekey=uuid_generator(),
                                     alignkey=uuid_generator(),
                                     passed_validation=True).save()
    lesson_record.audio_records.append(first_audio_record)
    lesson_record.save()
    assert not lesson_record.is_complete()
    second_audio_record = AudioRecord(user=user,
                                      prompt=second_prompt,
                                      filekey=uuid_generator(),
                                      alignkey=uuid_generator(),
                                      passed_validation=False).save()
    lesson_record.audio_records.append(second_audio_record)
    lesson_record.save()
    assert not lesson_record.is_complete()
    third_audio_record = AudioRecord(user=user,
                                     prompt=second_prompt,
                                     filekey=uuid_generator(),
                                     alignkey=uuid_generator(),
                                     passed_validation=True).save()
    lesson_record.audio_records.append(third_audio_record)
    lesson_record.save()
    assert lesson_record.is_complete()
    still_another_lesson_record = ensure_and_get_incomplete_lesson_record(
        user, lesson)
    assert lesson_record != still_another_lesson_record
Exemplo n.º 5
0
def test_verify_cookie(app, client, uuid_generator):
    from captaina.models import create_user, AudioRecord, Prompt,\
            create_lesson_with_safe_url_id, ensure_and_get_incomplete_lesson_record,\
            cookie_from_lesson_record, lesson_record_from_cookie
    #Copied lengthy setup above:
    lesson = create_lesson_with_safe_url_id(uuid_generator())
    first_prompt = Prompt(text="Karviaismarjakausi ei ole ohi",
                          graph_id=uuid_generator()).save()
    second_prompt = Prompt(text="Pelkkää makkaraa ei kannata pitää ravintona",
                           graph_id=uuid_generator()).save()
    lesson.prompts = [first_prompt, second_prompt]
    lesson.save()
    user = create_user(uuid_generator(), "pass")
    lesson_record = ensure_and_get_incomplete_lesson_record(user, lesson)
    #Now the test:
    cookie = cookie_from_lesson_record(lesson_record, app.config["SECRET_KEY"])
    print(cookie)
    response = client.post("/api/verify-record-cookie",
                           json={"record-cookie": cookie})
    assert response.data == b"OK"