예제 #1
0
def test_search_with_whoosh_no_match(db_with_books):

    data = {'year': '2021', 'text': 'cook'}
    form = SearchForm(data=data)

    retval = filter_description(form)
    assert retval.count() == 0
예제 #2
0
def test_search_by_payment_mode(db_with_expenses):

    data = {'year': '2021', 'payment_modes': [1, 2]}
    form = SearchForm(data=data)

    retval = filter_payment_modes(form)

    assert retval.count() == 15
예제 #3
0
def test_search_by_exact_date(db_with_expenses):

    data = {'year': '2021', 'exact_date': datetime.date(2021, 1, 15)}
    form = SearchForm(data=data)
    retval = filter_exact_date(form)

    assert retval.count() == 1
    assert retval.first().description == 'Item 15'
예제 #4
0
def test_search_by_tags(db_with_expense_tags):

    data = {'year': '2021', 'tags': [1, 3]}
    form = SearchForm(data=data)

    retval = filter_tags(form)
    expenses = retval.all()
    assert len(expenses) == 1
    assert expenses[0].description == 'Item 3'
예제 #5
0
def test_search_by_amount_cond(db_with_expense_amounts):

    data = {'year': '2021', 'amt_cond': '>', 'amount': '300'}
    form = SearchForm(data=data)

    retval = filter_amount(form)

    assert retval.count() == 2
    for i, exp in enumerate(retval):
        assert exp.description == f'Item {i+4}'
예제 #6
0
def test_search_by_amount_limits(db_with_expense_amounts):

    data = {'year': '2021', 'amt_min': '200', 'amt_max': '375'}
    form = SearchForm(data=data)

    retval = filter_amt_min_max(form)

    assert retval.count() == 3
    for i, exp in enumerate(retval):
        assert exp.description == f'Item {i+2}'
예제 #7
0
def test_fuzzy_search_with_whoosh(db_with_books):

    data = {'year': '2021', 'text': 'boek'}
    form = SearchForm(data=data)

    retval = filter_description(form)
    assert retval.count() == 1

    book = retval.first()
    assert book.comments == 'Book on Rest api.'
예제 #8
0
def test_search_description_without_whoosh(db_with_books):

    data = {'year': '2021', 'text': 'book', 'simple_search': True}
    form = SearchForm(data=data)

    retval = filter_description(form)
    assert retval.count() == 2

    books = retval.all()
    assert books[0].description == 'Rest api'
    assert books[1].description == 'Flask cookbook'
예제 #9
0
def test_search_by_month(db_with_months_data):

    data = {'year': '2021', 'month': [1, 3]}
    form = SearchForm(data=data)
    retval = filter_month(form)

    assert retval.count() == 10
    for i, exp in enumerate(retval):
        if i < 5:
            assert exp.description == f'Item {i+1}'
        else:
            assert exp.description == f'Item {i+6}'
예제 #10
0
def index():

    curr_year = datetime.utcnow().year
    tags = Tag.query.filter_by(user_id=current_user.id).all()
    tag_choices = [(t.id, t.tagname) for t in tags]

    modes = PaymentMode.query.filter_by(user_id=current_user.id).all()
    mode_choices = [(m.id, m.mode) for m in modes]

    form = SearchForm(year=curr_year)
    form.tags.choices = tag_choices
    form.payment_modes.choices = mode_choices

    if form.validate_on_submit():
        to_session(form)
        return redirect(url_for('search.search_results'))

    if form.errors:
        flash('Form has errors.', 'danger')

    return render_template('search/index.html', form=form, title='Search')
예제 #11
0
def test_search_by_date_limits(db_with_expenses):

    data = {
        'year': '2021',
        'from_date': datetime.date(2021, 1, 6),
        'to_date': datetime.date(2021, 1, 10)
    }
    form = SearchForm(data=data)
    retval = filter_from_to_dates(form)

    assert retval.count() == 5
    for i, exp in enumerate(retval):
        assert exp.description == f'Item {i+6}'
예제 #12
0
파일: search.py 프로젝트: deb17/moneycare
    def post(self, search_data, pagination_parameters):
        '''Get all expenses of the user in the current year.'''

        page = pagination_parameters.page
        page_size = pagination_parameters.page_size
        user_id = get_jwt_identity()
        user = User.query.get(user_id)

        expense.current_user = user
        utils.current_user = user

        form = SearchForm(data=search_data)
        result, _ = search_main(form, page, page_size)
        pagination_parameters.item_count = result.total
        if result.total == 0:
            abort(404, message='No search results')

        return result.items
예제 #13
0
def search_results():

    page = request.args.get('page', 1, type=int)

    form_data = from_session()
    form = SearchForm(data=form_data)

    expenses, total = search_main(form, page)
    if form.text.data and not form.simple_search.data:
        whoosh = True
    else:
        whoosh = False

    return render_template('search/search_results.html',
                           title='Search results',
                           expenses=expenses,
                           total=total,
                           whoosh=whoosh)
예제 #14
0
def test_search_no_year(db_with_expenses):

    form = SearchForm()
    retval = filter_year(form)

    assert retval.count() == 15