def test_qs_paging(self): pg = PeopleGrid() pg.apply_qs_args() eq_(pg.on_page, 2) eq_(pg.per_page, 1) # make sure the corret values get applied to the query assert 'LIMIT 1 OFFSET 1' in query_to_str(pg.build_query())
def test_qs_paging_doesnt_get_page_count_before_filters_are_handled(self): pg = PeopleGrid() pg.apply_qs_args() # this ensures that the filtering in apply_qs_args() takes place before # the paging. Since the paging section uses .page_count, we have to # make sure the filters get processed first. Otherwise an incorrect # page count gets cached. eq_(pg.record_count, 2)
def test_qs_onpage_too_high(self): pg = PeopleGrid() pg.apply_qs_args() eq_(pg.on_page, 3) eq_(pg.per_page, 1) eq_(len(pg.user_warnings), 0) # the records should be the same as if we were on the last page eq_(len(pg.records), 1)
def test_qs_blank_operator(self): pg = PeopleGrid() pg.apply_qs_args() assert pg.columns[0].filter.op is None assert pg.columns[0].filter.value1 is None assert pg.columns[0].filter.value2 is None assert pg.columns[4].filter.op is None assert pg.columns[4].filter.value1 is None assert pg.columns[4].filter.value2 is None
def test_qs_default_session(self): pg = PeopleGrid() pg.apply_qs_args() flask.request.args = MultiDict() pg2 = PeopleGrid() pg2.apply_qs_args() eq_(pg2.column('firstname').filter.op, 'eq') assert '_PeopleGrid' in flask.session['dgsessions'] assert pg.session_key in flask.session['dgsessions'] assert pg2.session_key in flask.session['dgsessions']
def test_qs_filtering(self): pg = PeopleGrid() pg.apply_qs_args() eq_(pg.columns[0].filter.op, 'eq') eq_(pg.columns[0].filter.value1, 'fn001') assert pg.columns[0].filter.value2 is None eq_(pg.columns[4].filter.op, 'is') eq_(pg.columns[4].filter.value1, [1, 2]) assert pg.columns[4].filter.value2 is None
def test_qs_apply_prevents_session_load(self): pg = PeopleGrid() pg.apply_qs_args() flask.request.args = MultiDict([ ('session_key', pg.session_key), ('apply', None), ]) pg2 = PeopleGrid() pg2.apply_qs_args() assert not pg2.column('firstname').filter.op assert not pg2.column('firstname').filter.value1
def test_qs_keyed_session_without_override(self): pg = PeopleGrid() pg.apply_qs_args() flask.request.args = MultiDict([ ('session_key', pg.session_key), ('op(createdts)', '!eq'), ('v1(createdts)', '2017-05-06'), ]) pg2 = PeopleGrid() pg2.apply_qs_args() assert not pg2.column('firstname').filter.op assert not pg2.column('firstname').filter.value1 eq_(pg2.column('createdts').filter.op, '!eq') eq_(pg2.column('createdts').filter.value1, datetime(2017, 5, 6))
def test_qs_keyed_session(self): pg = PeopleGrid() pg.apply_qs_args() flask.request.args['op(firstname)'] = '!eq' pg2 = PeopleGrid() pg2.apply_qs_args() eq_(pg2.column('firstname').filter.op, '!eq') flask.request.args = MultiDict([('session_key', pg.session_key)]) pg = PeopleGrid() pg.apply_qs_args() eq_(pg.column('firstname').filter.op, 'eq')
def test_export_to_xlsx(self): g = PeopleGrid() g.apply_qs_args() eq_(g.export_to, 'xlsx')
def test_qs_no_session(self): pg = PeopleGrid() pg.apply_qs_args() assert pg.column('firstname').filter.op is None
def test_qs_perpage_invalid(self): pg = PeopleGrid() pg.apply_qs_args() eq_(pg.on_page, 2) eq_(pg.per_page, 1) eq_(pg.user_warnings[0], '"perpage" grid argument invalid, ignoring')
def test_qs_sorting_not_allowed(self): pg = PeopleGrid() pg.apply_qs_args() eq_(pg.order_by, [('firstname', False), ('status', True)]) eq_(pg.user_warnings[0], 'can\'t sort on invalid key "fullname"')
def test_qs_perpage_negative(self): pg = PeopleGrid() pg.apply_qs_args() eq_(pg.on_page, 2) eq_(pg.per_page, 1) eq_(len(pg.user_warnings), 0)
def test_qs_sorting_ignores_emptystring(self): pg = PeopleGrid() pg.apply_qs_args() eq_(pg.order_by, []) eq_(len(pg.user_warnings), 0)
def test_qs_prefix(self): pg = PeopleGrid(qs_prefix='dg_') pg.apply_qs_args() eq_(pg.on_page, 2) eq_(pg.per_page, 1)
def test_qs_search_disabled(self): g = PeopleGrid() g.enable_search = False g.apply_qs_args() assert g.search_value is None
def test_export_to_unrecognized(self): g = PeopleGrid() g.apply_qs_args() eq_(g.export_to, None)
def test_qs_search(self): g = PeopleGrid() g.enable_search = True g.apply_qs_args() eq_(g.search_value, 'bar')