Exemple #1
0
def Can_list_starting_after_an_id__test():
    answer = list( poemtube.listpoems( FakeDb(), since_id="id2" ) )
    # We don't know what order they will come back in, but even
    # if id2 is first, we'll get one less
    assert_true( len( answer ) < 3 )
    print answer
    assert_true( "id2" not in answer )
Exemple #2
0
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] )
Exemple #3
0
def Can_list_all_poems__test():
    answer = poemtube.listpoems( FakeDb() )
    assert_equal(
        set( ( "id1", "id2", "id3" ) ),
        set( answer )
    )
Exemple #4
0
def Listing_asking_for_negative_is_an_error__test():
    poemtube.listpoems( FakeDb(), count=-1 )
Exemple #5
0
def Listing_asking_for_too_many_returns_all__test():
    answer = poemtube.listpoems( FakeDb(), count=200 )
    assert_equal( 3, len( list( answer ) ) )
Exemple #6
0
def Can_list_a_specified_number_of_poems__test():
    answer = poemtube.listpoems( FakeDb(), count=2 )
    assert_equal( 2, len( list( answer ) ) )

    answer = poemtube.listpoems( FakeDb(), count=1 )
    assert_equal( 1, len( list( answer ) ) )
Exemple #7
0
        count_str = queryparams["count"]
        try:
            count = int(count_str)
        except ValueError, e:
            raise JsonInvalidRequest(
                InvalidRequest(
                    '"%s" is an invalid value for count.' % count_str, 400))
    else:
        count = None

    if "search" in queryparams:
        search = queryparams["search"]
    else:
        search = None

    return list(listpoems(db, count=count, search=search))


def my_replacepoem(db, id, title, author, text, user):
    replacepoem(db, id=id, title=title, author=author, text=text, user=user)
    return ""


def my_deletepoem(db, id, user):
    deletepoem(db, id, user)
    return ""


def my_amendpoem(db, id, newprops, user):
    amendpoem(db, id, newprops, user)
    return ""
Exemple #8
0
            count = int( count_str )
        except ValueError, e:
            raise JsonInvalidRequest(
                InvalidRequest(
                    '"%s" is an invalid value for count.' % count_str, 400
                )
            )
    else:
        count = None

    if "search" in queryparams:
        search = queryparams["search"]
    else:
        search = None

    return list( listpoems( db, count=count, search=search ) )


def my_replacepoem( db, id, title, author, text, user ):
    replacepoem( db, id=id, title=title, author=author, text=text, user=user )
    return ""


def my_deletepoem( db, id, user ):
    deletepoem( db, id, user )
    return ""


def my_amendpoem( db, id, newprops, user ):
    amendpoem( db, id, newprops, user )
    return ""