Beispiel #1
0
def test_read_link(client: TestClient, db: Session,
                   superuser_headers: Dict[str, str]) -> None:
    link = create_random_link(db)
    response = client.get(f"/links/{link.id}", headers=superuser_headers)
    assert response.status_code == 200
    json = response.json()
    assert json["title"] == link.title
    assert json["url"] == link.url
    assert json["liked"] == link.liked
    assert json["archived"] == link.archived
Beispiel #2
0
def test_update_link(client: TestClient, db: Session,
                     superuser_headers: Dict[str, str]) -> None:
    link = create_random_link(db)
    new_title = link.title + " updated"
    new_url = link.url + ".edu"
    data = {
        "title": new_title,
        "url": new_url,
        "liked": not link.liked,
        "archived": not link.archived,
    }
    response = client.post(f"/links/{link.id}",
                           headers=superuser_headers,
                           json=data)
    assert response.status_code == 200
    link2 = response.json()
    assert link2["title"] == data["title"]
    assert link2["url"] == data["url"]
    assert link2["liked"] == data["liked"]
    assert link2["archived"] == data["archived"]
Beispiel #3
0
def test_update_link(db: Session) -> None:
    link = create_random_link(db)
    new_title = random_lower_string()
    new_url = "https://example.org"
    tag_name = random_lower_string()
    link_update = LinkUpdate(
        title=new_title,
        url=new_url,
        tags=[TagCreate(name=tag_name)],
        liked=not link.liked,
        archived=not link.archived,
    )
    new_link = crud.link.update(db, object_db=link, object_update=link_update)
    assert new_link
    assert new_link.title == link_update.title
    assert new_link.url == link_update.url
    assert new_link.liked == link_update.liked
    assert new_link.archived == link_update.archived
    new_tags = list(new_link.tags)
    assert len(new_tags) == 1
    assert new_tags[0].name == tag_name
Beispiel #4
0
def test_delete_link(db: Session) -> None:
    link = create_random_link(db)
    crud.link.delete(db, id=link.id)
    link2 = crud.link.get(db, link.id)
    assert link2 is None
Beispiel #5
0
def test_get_link(db: Session) -> None:
    link = create_random_link(db)
    link2 = crud.link.get(db, link.id)
    assert link2
    assert jsonable_encoder(link2) == jsonable_encoder(link)