def test_mood_template_get_all_succeeds(db_session, test_mood_templates):
    test_template1, test_template2 = test_mood_templates
    mood_template1 = create_mood_template(db_session, test_template1)
    mood_template2 = create_mood_template(db_session, test_template2)

    response = client.get("/mood_templates/")
    json_response = response.json()

    assert response.status_code == 200
    assert any(item["public_id"] == mood_template1.public_id
               for item in json_response)
    assert any(item["public_id"] == mood_template2.public_id
               for item in json_response)
def test_mood_template_get_succeeds(db_session, test_mood_templates):
    test_template, _ = test_mood_templates
    mood_template = create_mood_template(db_session, test_template)
    response = client.get(f"/mood_templates/{mood_template.public_id}")
    json_response = response.json()

    assert response.status_code == 200
    assert json_response["name"] == mood_template.name
    assert json_response["public_id"] == mood_template.public_id
Пример #3
0
def default_moods(db_session):
    """
    Test fixture for creating the default template and moods
    """
    default_template = MoodTemplateCreate(name="Default Mood Template")
    mood_template = create_mood_template(db_session, default_template)

    awful = create_mood(
        db_session,
        MoodCreate(name="Awful",
                   colour="#e05f4e",
                   template_id=mood_template.public_id),
    )
    poor = create_mood(
        db_session,
        MoodCreate(name="Poor",
                   colour="#e28f53",
                   template_id=mood_template.public_id),
    )
    okay = create_mood(
        db_session,
        MoodCreate(name="Okay",
                   colour="#ede357",
                   template_id=mood_template.public_id),
    )
    great = create_mood(
        db_session,
        MoodCreate(name="Great",
                   colour="#5e95ed",
                   template_id=mood_template.public_id),
    )
    amazing = create_mood(
        db_session,
        MoodCreate(name="Amazing",
                   colour="#53d192",
                   template_id=mood_template.public_id),
    )
    return awful, poor, okay, great, amazing
Пример #4
0
def test_mood_templates(db_session):
    test_template1 = MoodTemplateCreate(name="test_mood_template")
    test_template2 = MoodTemplateCreate(name="test_mood_template2")
    mood_template1 = create_mood_template(db_session, test_template1)
    mood_template2 = create_mood_template(db_session, test_template2)
    return mood_template1, mood_template2
Пример #5
0
async def create_mood_template(template: schema.MoodTemplateCreate,
                               db: Session = Depends(get_db)):
    mood_template = crud.get_mood_template_by_name(db, template.name)
    if mood_template:
        raise DuplicateResourceError(resource="mood_template", value="name")
    return crud.create_mood_template(db, template)