def test_get_single_sample_item_valid(test_app, test_database):
    item = db_service.create(SampleItem, name="item1")
    client = test_app.test_client()
    resp = client.get(f"/sample_items/{item.id}")
    data = json.loads(resp.data.decode())
    assert resp.status_code == 200
    assert data["name"] == item.name
def test_delete_user_valid(test_app, test_database):
    item = db_service.create(SampleItem, name="item1")
    client = test_app.test_client()
    resp = client.delete(f"/sample_items/{item.id}")
    data = json.loads(resp.data.decode())
    assert resp.status_code == 200
    assert f"Deleted Sample Item #{item.id}" in data["message"]
def test_update_sample_item_valid(test_app, test_database):
    item = db_service.create(SampleItem, name="item1")
    client = test_app.test_client()
    resp = client.put(
        f"/sample_items/{item.id}",
        data=json.dumps({"name": "coolvalue"}),
        content_type="application/json",
    )
    data = json.loads(resp.data.decode())
    assert resp.status_code == 200
    assert "coolvalue" in data["name"]
def test_get_all_sample_items_valid(test_app, test_database):
    items = [
        db_service.create(SampleItem, name=name)
        for name in ["item1", "item2", "item3"]
    ]
    client = test_app.test_client()
    resp = client.get("/sample_items")
    data = json.loads(resp.data.decode())
    assert resp.status_code == 200
    assert len(data) == len(items)
    assert data[0]["name"] == items[0].name
    assert data[1]["name"] == items[1].name
    assert data[2]["name"] == items[2].name
Example #5
0
def test_update(test_app, test_database):
    cooldummy = db_service.create(Dummy, name="cooldummy")
    updated = db_service.update(cooldummy, name="supercooldummy")
    assert updated.name == "supercooldummy"
    persisted_update = db_service.find_by(Dummy, name="supercooldummy")
    assert cooldummy.id == persisted_update.id
Example #6
0
def test_create(test_app, test_database):
    cooldummy = db_service.create(Dummy, name="cooldummy")
    assert cooldummy.id == 1
    assert cooldummy.name == "cooldummy"
    assert len(db_service.all(Dummy)) == 1
def test_valid_sample_item(test_app, test_database):
    item = db_service.create(SampleItem, name="new item")
    assert item.id == 1
    assert item.name == "new item"
def test_name_required(test_app, test_database):
    with pytest.raises(IntegrityError):
        db_service.create(SampleItem, name=None)