def test_search_single_field(client): reset_database() soup = make_soup(client.get("/?title=sort").data) card = soup.find(class_="card-body") assert card is not None assert "Merge sort algorithm" in card.text assert soup.find(string=re.compile("Poista rajaukset")) is not None
def test_missing_mandatory_field_movie(client): resp = client.post("/tips/add-movie", data={ "director": "test director" }) soup = make_soup(resp.data) title = soup.find(attrs={"id": "title"}).parent assert "This field is required" in title.text assert Movie.query.filter_by(title="test title").count() == 0
def test_missing_field(client): db.session().add(Book( title="test title", author="test author", )) soup = make_soup(client.get("/").data) test_book = soup.find(string=re.compile("test title")).parent assert "ISBN" not in test_book.text
def test_missing_mandatory_field_audiobook(client): resp = client.post("/tips/add-audiobook", data={ "title": "test title" }) soup = make_soup(resp.data) author = soup.find(attrs={"id": "author"}).parent assert "This field is required" in author.text assert Audiobook.query.filter_by(title="test title").count() == 0
def test_missing_mandatory_field_video(client): resp = client.post("/tips/add-video", data={ "title": "test title", }) soup = make_soup(resp.data) source = soup.find(attrs={"id": "source"}).parent assert "This field is required" in source.text assert Video.query.filter_by(title="test title").count() == 0
def movie_edit_form_is_right(context): page = make_soup(context.response.data) assert "Otsikko" in page.text assert "Ohjaaja" in page.text assert "Julkaisuvuosi" in page.text assert "Pituus" in page.text assert "Tunnisteet" in page.text assert "Oma kommentti" in page.text
def test_missing_mandatory_field_book(client): resp = client.post("/tips/add-book", data={ "title": "new book", "publication_year": 2020, }) soup = make_soup(resp.data) author = soup.find(attrs={"id": "author"}).parent assert "This field is required" in author.text assert Book.query.filter_by(title="new book").count() == 0
def form_is_right(context): page = make_soup(context.response.data) assert 6 == len(page.find_all('input')) assert 1 == len(page.find_all('textarea')) assert "Otsikko" in page.text assert "Kirjailija" in page.text assert "Julkaisuvuosi" in page.text assert "ISBN" in page.text assert "Sivuja" in page.text assert "Oma kommentti" in page.text
def movie_form_is_right(context): page = make_soup(context.response.data) assert 6 == len(page.find_all('input')) assert 1 == len(page.find_all('textarea')) assert "Otsikko" in page.text assert "Ohjaaja" in page.text assert "Julkaisuvuosi" in page.text assert "Pituus" in page.text assert "Tunnisteet" in page.text assert "Oma kommentti" in page.text
def form_is_right(context): page = make_soup(context.response.data) assert 5 == len(page.find_all('input')) assert 1 == len(page.find_all('textarea')) assert "Otsikko" in page.text assert "Ladattu" in page.text assert "URL" in page.text assert "Liittyvät kurssit" in page.text assert "Tunnisteet" in page.text assert "Oma kommentti" in page.text
def test_tips_render_video(client): db.session().add(Video( title="test video", source="test source", comment="test comment", tags="Ohjelmointi, algoritmit" )) soup = make_soup(client.get("/").data) assert "test video" in soup.text assert "test source" in soup.text assert "test comment" in soup.text assert "Ohjelmointi, algoritmit" in soup.text
def audiobook_form_is_right(context): page = make_soup(context.response.data) assert 8 == len(page.find_all('input')) assert 1 == len(page.find_all('textarea')) assert "Otsikko" in page.text assert "Kirjailija" in page.text assert "Lukija" in page.text assert "Julkaisuvuosi" in page.text assert "ISBN" in page.text assert "Pituus" in page.text assert "Liittyvät kurssit" in page.text assert "Tunnisteet" in page.text assert "Oma kommentti" in page.text
def user_sees_that_tip_is_read(context): resp = context.client.get("/") soup = make_soup(resp.data) tip = soup.find(id=context.id) assert "Ei" in soup.text
def user_sees_list(context): soup = make_soup(context.response.data) assert "Clean Code: A Handbook of Agile Software Craftsmanship" in soup.text assert "Merge sort algorithm" in soup.text
def test_empty_search(client): reset_database() soup = make_soup(client.get("/").data) assert len(soup.find_all(class_="card-body")) == 4 assert soup.find(string=re.compile("Poista rajaukset")) is None
def step_impl(context, text): page = make_soup(context.response.data) cards = page.findAll(class_="card-body") assert len(cards) == 1 assert text in cards[0].text
def test_search_invalid_field(client): reset_database() soup = make_soup(client.get("/?asdasd=asd").data) assert soup.find(class_="card-body") is None
def test_empty_db(client): db.session().query(Tip).delete() soup = make_soup(client.get("/").data) assert soup.find(class_="card mb-3") == None
def test_search_duplicate_fields(client): resp = client.get("/?title=handbook&title=sort") soup = make_soup(resp.data) assert resp.status_code == 403 assert "Samaa kenttää ei voi hakea useaan kertaan" in soup.text
def test_search_multiple_fields(client): reset_database() soup = make_soup(client.get( "/?related_courses=tuotanto&author=martin").data) assert len(soup.find_all(class_="card-body")) == 1 assert "Clean Code: A Handbook of Agile Software Craftsmanship" in soup.text
def step_impl(context): page = make_soup(context.response.data) assert len(page.find_all(class_="card-body")) == 4
def test_initial_data(client): reset_database() soup = make_soup(client.get("/").data) assert "Clean Code: A Handbook of Agile Software Craftsmanship" in soup.text