示例#1
0
def test_upsert_existing_card():
    db = TestingSessionLocal()
    card = crud.create_card(
        db=db,
        card=CardCreate(
            display_name="Compersion",
            name="compersion",
            type="need",
            level=1,
            definition="<3",
            definition_source="<3.com",
        ),
    )
    crud.upsert_card(
        db=db,
        card=CardCreate(
            display_name="Compersion!",
            name="compersion",
            type="feeling",
            level=2,
            definition="<33",
            definition_source="<33.com",
        ),
    )
    card = crud.get_card(db, 'compersion')
    assert card.display_name == 'Compersion!'
    assert card.type == 'feeling'
    assert card.level == 2
    assert card.definition == '<33'
    assert card.definition_source == '<33.com'
示例#2
0
def test_get_card():
    db = TestingSessionLocal()
    crud.create_card(
        db=db,
        card=CardCreate(
            display_name="Compersion",
            name="compersion",
            type="feeling",
            level=1,
            definition="<3",
            definition_source="<3.com",
        ),
    )
    response = test_client.get("/api/cards/compersion")
    assert response.status_code == 200
    json = response.json()
    assert len(list(json.keys())) == 8
    assert json["id"] == 1
    assert json["displayName"] == "Compersion"
    assert json["name"] == "compersion"
    assert json["type"] == "feeling"
    assert json["level"] == 1
    assert json["image"] == {
        "og": "/static/og/compersion.jpg",
        "md": "/static/md/compersion.jpg",
        "lg": "/static/lg/compersion.jpg",
    }
示例#3
0
def test_create_and_get_comment():
    db = TestingSessionLocal()
    card = crud.create_card(
        db=db,
        card=CardCreate(
            display_name="Compersion",
            name="compersion",
            type="feeling",
            level=1,
            definition="<3",
            definition_source="<3.com",
        ),
    )
    post_response = test_client.post(f"/api/cards/{card.name}/comments",
                                     json={
                                         "cardId": card.id,
                                         "type": "NEED_MET",
                                         "data": "princess.wiggles"
                                     })
    assert post_response.status_code == 201
    comment_response = test_client.get(f"/api/cards/{card.name}/comments", )
    assert comment_response.status_code == 200
    json = comment_response.json()
    assert len(json) == 1
    comment = json[0]
    assert len(list(comment.keys())) == 5
    assert comment["id"]
    assert comment["type"] == "NEED_MET"
    assert comment["data"] == "princess.wiggles"
    assert comment["createdAt"]
示例#4
0
def upsert_card(display_name, name, type, level, definition,
                definition_source):
    return crud.upsert_card(db=db,
                            card=CardCreate(
                                display_name=display_name,
                                name=name,
                                type=type,
                                level=level,
                                definition=definition,
                                definition_source=definition_source))
示例#5
0
def test_invalid_comment():
    db = TestingSessionLocal()
    card = crud.create_card(
        db=db,
        card=CardCreate(
            display_name="Compersion",
            name="compersion",
            type="feeling",
            level=1,
            definition="<3",
            definition_source="<3.com",
        ),
    )
    with pytest.raises(ValueError):
        post_response = test_client.post(f"/api/cards/{card.name}/comments",
                                         json={
                                             "cardId": card.id,
                                             "type": "NEED_MET",
                                             "data": "",
                                         })
示例#6
0
def test_full_story():
    db = TestingSessionLocal()
    scared = crud.upsert_card(
        db=db,
        card=CardCreate(
            display_name="Scared",
            name="scared",
            type="feeling",
            level=4,
            definition=":,(",
            definition_source="",
        ),
    )
    hopeful = crud.upsert_card(
        db=db,
        card=CardCreate(
            display_name="Hopeful",
            name="hopeful",
            type="feeling",
            level=4,
            definition=":o !",
            definition_source="",
        ),
    )
    harmony = crud.upsert_card(
        db=db,
        card=CardCreate(
            display_name="Harmony",
            name="harmony",
            type="need",
            level=4,
            definition=":<3",
            definition_source="",
        ),
    )
    ease = crud.upsert_card(
        db=db,
        card=CardCreate(
            display_name="Ease",
            name="ease",
            type="need",
            level=4,
            definition="<3",
            definition_source="",
        ),
    )
    story = upsert_story(
        db=db,
        display_name='The Itsy Bitsy Spider',
        scenes=[{
            'description':
            ' '.join([
                'The Itsy Bisty Spider went up the water spout.',
                'Down came the ran and washed the spider out.',
            ]),
            'noun':
            'the spider',
            'feeling_id':
            scared.id,
            'need_id':
            harmony.id
        }, {
            'description':
            ' '.join([
                'Up came the sun and dried up all the rain.',
                'So the Itsy Bitsy Spider went up the spout again.',
            ]),
            'noun':
            'the spider',
            'feeling_id':
            hopeful.id,
            'need_id':
            harmony.id
        }])
    scenes = crud.get_scenes(db=db, story_id=story.id)
    # New Guess
    response = test_client.post(
        f"/api/stories/{story.id}/scenes/{scenes[0].id}/guesses/{ease.id}")
    assert response.status_code == 201

    # Test Story
    response = test_client.get(f"/api/stories/{story.id}")
    assert response.status_code == 200
    res_story = response.json()
    assert res_story["displayName"] == "The Itsy Bitsy Spider"

    # Test Scene
    response = test_client.get(
        f"/api/stories/{story.id}/scenes/{scenes[0].id}")
    res_scene = response.json()
    assert len(res_scene["cardGuesses"]) == 3
    response = test_client.get(
        f"/api/stories/{story.id}/scenes/{scenes[1].id}")
    res_scene = response.json()
    assert len(res_scene["cardGuesses"]) == 2