def Searching_for_an_author_returns_their_poems__test(): db = FakeDb() id1 = poemtube.addpoem( db, title="t1", author="fred 1", text="t1", user="******" ) id2 = poemtube.addpoem( db, title="t2", author="fred 2", text="t2", user="******" ) id3 = poemtube.addpoem( db, title="t3", author="fred 1", text="t3", user="******" ) id4 = poemtube.addpoem( db, title="t4", author="fred 3", text="t4", user="******" ) id5 = poemtube.addpoem( db, title="t5", author="fred 1", text="t5", user="******" ) # This is what we are testing answer = poemtube.listpoems( db, search="fred 1" ) # Take the first 3 - theoretically there might be others first_3 = list( answer )[:3] # We got back the 3 poems by this author assert_equal( id1, first_3[0] ) assert_equal( id3, first_3[1] ) assert_equal( id5, first_3[2] )
def Can_add_a_new_poem__test(): db = FakeDb() id = poemtube.addpoem( db, title="title X", author="author X", text="text X", user="******" ) assert_equal( "title-x", id ) newentry = db.poems.data[id] assert_equal( "title X", newentry["title"] ) assert_equal( "author X", newentry["author"] ) assert_equal( "text X", newentry["text"] )
def Adding_a_poem_not_logged_in_is_an_error__test(): db = FakeDb() poemtube.addpoem( db, "X", "X", "X", user=None )