Exemple #1
0
    def search():
        search = request.args.get('search')
        search_lowecased = search.strip().lower()
        user_login = user()
        number_of_ads = db.all_ads_count_search(db.open_db(db_url),
                                                search_lowecased)
        numb = number_of_ads['count_ads']
        number_of_pages = math.ceil(numb / ADDS_PER_PAGE)

        search_result = db.search_pets(db.open_db(db_url),
                                       search_lowecased,
                                       ADDS_PER_PAGE,
                                       pages_offset=0)

        if 'pages_offset' in request.args.keys():
            pages_offset = request.args.get('pages_offset')
            search = request.args.get('search')
            search_result = db.search_pets(db.open_db(db_url),
                                           search_lowecased, ADDS_PER_PAGE,
                                           pages_offset)

        return render_template('index.html',
                               pets=search_result,
                               search=search,
                               active_index='search',
                               user_login=user_login,
                               number_of_pages=number_of_pages,
                               limit=ADDS_PER_PAGE)
Exemple #2
0
def test_all_ads_count_search_by_name():
    expected = 1
    search = 'Хома'
    actual_1 = db.all_ads_count_search(open_db(db_url), search)
    actual = actual_1['count_ads']
    assert expected == actual
Exemple #3
0
def test_all_ads_count_search_by_category():
    expected = 2
    search = 'Кошка'
    actual_1 = db.all_ads_count_search(open_db(db_url), search)
    actual = actual_1['count_ads']
    assert expected == actual
Exemple #4
0
def test_all_ads_count_search_by_breed():
    expected = 2
    search = 'Овчарка'
    actual_1 = db.all_ads_count_search(open_db(db_url), search)
    actual = actual_1['count_ads']
    assert expected == actual