Exemple #1
0
def test_delete_one_book():
    """This test check API delete method"""

    """Create a book"""
    new_book = add_book({'title': 'Deleted book', 'author': 'Deleted author'})
    book_id = new_book['id']

    """Get list of books"""
    all_books = get_all_books()
    list_number = len(all_books)

    """Check if created book was added to book list correctly.If it wasn't print error exception"""
    if new_book in all_books:
        # Delete created book
        delete_book(book_id)
        all_books = get_all_books()
        updated_list_number = len(all_books)

        assert new_book not in all_books, "The book wasn't deleted.Incorrect work of DELETE method!"
        assert (list_number - 1) == updated_list_number
        # Get book info by book id.
        book_info = get_book(new_book)
        assert len(book_info) == 0, "Book info wasn't deleted.Incorrect work of DELETE method!"

    else:
        assert 1 == 0, "The book wasn't created correctly. Check add_book method!!!"
Exemple #2
0
def test_get_book_invalid_id(book_id):
    """This test checks API behavior after get_book request by invalid id  """

    info = get_book(book_id)
    status_code = get_book_status_code(book_id)

    assert len(info) == 0
    assert status_code == 200
Exemple #3
0
def test_book_info():
    """In this test we get existing book and check all parameters of book info"""

    """Create new book"""
    new_book = add_book({'title': 'New book', 'author': 'New author'})
    book_id = new_book['id']

    """Get book info"""

    book_info = get_book(book_id)

    assert book_info['title'] == 'New book', "Error! get_book function works incorrect"
    assert book_info['author'] == 'New author', "Error! get_book function works incorrect"
Exemple #4
0
def test_update_same_title():
    """This test check API behavior if we'll try to rename 2 books and give them the same title/author """

    """Create 2 new books"""
    book1 = add_book({'title': '', 'author': ''})
    book1_id = book1['id']
    book2 = add_book({'title': '', 'author': ''})
    book2_id = book2['id']


    """Update created books and give them identical titles and author"""
    update_book(book1_id, {'title': 'Test title', 'author': 'test author'})
    update_book(book2_id, {'title': 'Test title', 'author': 'test author'})

    """ Get info about this book: """
    book1_info = get_book(book1_id)
    book2_info = get_book(book2_id)

    """ Verify that changes were applied correctly: """

    assert book1_info['title'] == book2_info['title'] == 'Test title', "Error in update function!"
    assert book1_info['author'] == book2_info['author'] == 'test author', "Error in update function!"
def run():
    book = ut.get_book()
    asks = book[0]
    bids = book[1]

    total_ask = 0
    for ask in asks:
        total_ask += ask[1]
    total_bid = 0
    for bid in bids:
        total_bid += bid[1]
    print "asks:" + str(total_ask)
    print "Bids: " + str(total_bid)
Exemple #6
0
def test_update_book(title, author):
    # Create new book:
    new_book = add_book({'title': '', 'author': ''})
    book_id = new_book['id']

    # Update book attributes:
    update_book(book_id, {'title': title, 'author': author})

    # Get info about this book:
    book = get_book(book_id)

    # Verify that changes were applied correctly:
    assert book['title'] == title
    assert book['author'] == author
Exemple #7
0
def test_book_info_different_options(title, author):
    """This test checks get_book request with different book info parameters"""

    """Create new book"""
    new_book = add_book({'title': title, 'author': author})
    book_id = new_book['id']

    """Get created book info and verify request status code"""
    book_info = get_book(book_id)
    status_code = get_book_status_code(book_id)

    assert book_info['title'] == title, "Incorrect work of get_book function !"
    assert book_info['author'] == author, "Incorrect work of get_book function !"
    assert status_code == 200, "Wrong get_book request status code!"
Exemple #8
0
def test_books_with_similar_author():
    """This test check API behavior after creating more than one book with identical author """

    """Create some books with identical author"""
    first_book = add_book({'title': 'Title 1', 'author': 'The same author'})
    first_book_id = first_book['id']
    second_book = add_book({'title': 'Title 2', 'author': 'The same author'})
    second_book_id = second_book['id']

    """Get list of books"""
    all_books = get_all_books()

    assert first_book in all_books
    assert second_book in all_books

    """Get info of created books"""
    first_book_info = get_book(first_book_id)
    second_book_info = get_book(second_book_id)

    assert first_book_info != second_book_info
    assert first_book_id != second_book_id
    assert first_book['title'] == 'Title 1'
    assert second_book['title'] == 'Title 2'
Exemple #9
0
def test_delete_one_of_two_books():
    """In this test we create two books with the same title and author.After that  delete one of them and
    will check that delete method work correctly"""

    """Create some books with identical authors and titles"""
    first_book = add_book({'title': 'Foundation', 'author': 'Isaac Asimov'})
    first_book_id = first_book['id']
    second_book = add_book({'title': 'Foundation', 'author': 'Isaac Asimov'})
    second_book_id = second_book['id']

    """Get list of books"""
    all_books = get_all_books()

    """Check if created books were added to book list correctly.If they weren't print error exception"""
    if first_book and second_book in all_books:
        # Delete first created book
        delete_book(first_book_id)
        all_books = get_all_books()

        #Check that was deleted only one book of two that were created.
        assert first_book not in all_books, "The book wasn't deleted.Incorrect work of DELETE method!"
        assert second_book in all_books, "Two books were deleted instead of one!Incorrect work of DELETE method! "

        # Get book info by book id.
        first_book_info = get_book(first_book_id)
        second_book_info = get_book(second_book_id)

        #Check that info of first book was deleted and info of second one wasn't spoiled
        assert len(first_book_info) == 0, "Book info wasn't deleted.Incorrect work of DELETE method!"
        assert len(second_book_info) > 0, "Two books were deleted instead of one!Incorrect work of DELETE method! "
        assert second_book['author'] == 'Isaac Asimov'
        assert second_book['title'] == 'Foundation'
        assert second_book['id'].count('-') == 4

    else:
        assert 1 == 0, "The books weren't created correctly. Check add_book method!!!"
Exemple #10
0
def test_deleted_book_info():
    """This test checks API behavior after requesting deleted book info"""
    pass

    """Create new book"""
    new_book = add_book({'title': 'Pytest tutorial', 'author': 'QA'})
    book_id = new_book['id']

    """Delete created book"""
    delete_book(book_id)

    """Get book info"""
    info = get_book(book_id)
    status_code = get_book_status_code(book_id)


    assert len(info) == 0
    assert status_code == 200, "Wrong request status code in getting deleted book info"
def put(*args):
    team_addr, flag_id, flag = args[:3]
    login = generate_login()
    s = Session()

    r = make_request(s.post, SIGN_UP, team_addr, {"login": login})

    session = r.cookies.get('session', None)
    if not session:
        close(MUMBLE, "Invalid cookie", "No cookie. {}".format(team_addr))
    password = hex(decode_cookie(session).get('priv_key'))[2:]

    book = get_book(CUR_DIR)
    r = make_request(s.post, ADD_BOOK, team_addr, book)

    book_id = r.url.split('/')[-1]
    make_request(s.post, ADD_TAG, team_addr, {"bookId": book_id, "tag": flag})

    close(OK, ":".join((login, password, book_id)))
Exemple #12
0
def requestItem():
    if request.cookies.get('TOKEN') is None:
        return redirect('/register')
    decoded = jwt.decode(request.cookies.get('TOKEN'),
                         'secret',
                         algorithms=['HS256'])
    if decoded is None:
        resp = make_response(redirect('/register'))
        resp.set_cookie('TOKEN', '', expires=0)
        return resp

    isbn = request.args.get("isbn_service")
    owner = request.args.get("owner")
    if isbn is None or owner is None:
        return redirect('/')

    events.event_request(register_user.get_user_id(decoded['email']),
                         utils.get_book(isbn)['_id'])

    return redirect('/pending')
Exemple #13
0
def add_dp():
    book = ut.get_book()
    asks = book[0]
    bids = book[1]

    total_ask = 0
    for ask in asks:
        total_ask += ask[1]
    total_bid = 0
    for bid in bids:
        total_bid += bid[1]
    #print "asks:" + str(total_ask)
    #print "Bids: "+ str(total_bid)
    row = [str(datetime.now())]
    row.append(ut.get_price()['last'])
    row.append(total_ask)
    row.append(total_bid)
    fd = open(OUT_FILE, 'a')
    fd.write(row)
    fd.close()
    return row
Exemple #14
0
def book_index(request):
    from account.models import get_follow_list
    from utils import get_book
    user = request.user
    result = {}
    i = 0
    if request.method == "POST":
        from sell.utils import get_book_info
        from account.models import follow, unfollow
        action = request.POST.get("book_action", "")
        isbn = request.POST.get("target_isbn", "0")
        isbn = convert_to_13(isbn=isbn)
        if validate_isbn(isbn):
            if action == "follow":
                follow_isbns = get_follow_list(user=user)
                for follow_isbn in follow_isbns:
                    if follow_isbn != isbn:
                        i = i + 1
                if i == len(follow_isbns):
                    follow(user=user, isbn=isbn)
            elif action == "unfollow":
                unfollow(user=user, isbn=isbn)
            else:
                return render(request, 'error_page.html')
    else:
        isbn = request.GET.get("isbn", "0")
        isbn = convert_to_13(isbn=isbn)

    if validate_isbn(isbn=isbn):
        result = get_book(isbn=isbn)
        follow_isbns = get_follow_list(user=user)
        for follow_isbn in follow_isbns:
            if follow_isbn:
                if follow_isbn == isbn:
                    result["is_follow"] = "true"
        return render(request, 'book_index.html', result)

    return render(request, 'error_page.html')
Exemple #15
0
def book_index(request):
    from account.models import get_follow_list
    from utils import get_book
    user = request.user
    result = {}
    i = 0 
    if request.method == "POST":
        from sell.utils import get_book_info    
        from account.models import follow, unfollow
        action = request.POST.get("book_action","")
        isbn = request.POST.get("target_isbn", "0")
        isbn = convert_to_13(isbn=isbn)
        if validate_isbn(isbn):
            if action == "follow":
                follow_isbns = get_follow_list(user=user) 
                for follow_isbn in follow_isbns:                   
                    if follow_isbn != isbn:
                        i = i + 1
                if i == len(follow_isbns):
                    follow(user=user, isbn=isbn)
            elif action == "unfollow":
                unfollow(user=user, isbn=isbn) 
            else:
                return render(request, 'error_page.html')
    else:
        isbn = request.GET.get("isbn","0")
        isbn = convert_to_13(isbn=isbn)

    if validate_isbn(isbn=isbn): 
        result = get_book(isbn=isbn)
        follow_isbns = get_follow_list(user=user)  
        for follow_isbn in follow_isbns:
            if follow_isbn:
                if follow_isbn == isbn:
                    result["is_follow"] = "true" 
        return render(request, 'book_index.html', result)      

    return render(request, 'error_page.html')