Пример #1
0
    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())
Пример #2
0
 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)
Пример #3
0
 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)
Пример #4
0
    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())
Пример #5
0
    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)
Пример #6
0
    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)
Пример #7
0
    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
Пример #8
0
 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']
Пример #9
0
    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
Пример #10
0
    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
Пример #11
0
 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']
Пример #12
0
    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
Пример #13
0
 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
Пример #14
0
 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))
Пример #15
0
 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))
Пример #16
0
 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')
Пример #17
0
 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')
Пример #18
0
 def test_export_to_xlsx(self):
     g = PeopleGrid()
     g.apply_qs_args()
     eq_(g.export_to, 'xlsx')
Пример #19
0
 def test_qs_no_session(self):
     pg = PeopleGrid()
     pg.apply_qs_args()
     assert pg.column('firstname').filter.op is None
Пример #20
0
 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')
Пример #21
0
 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"')
Пример #22
0
 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)
Пример #23
0
 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"')
Пример #24
0
 def test_qs_sorting_ignores_emptystring(self):
     pg = PeopleGrid()
     pg.apply_qs_args()
     eq_(pg.order_by, [])
     eq_(len(pg.user_warnings), 0)
Пример #25
0
 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')
Пример #26
0
 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)
Пример #27
0
 def test_qs_sorting_ignores_emptystring(self):
     pg = PeopleGrid()
     pg.apply_qs_args()
     eq_(pg.order_by, [])
     eq_(len(pg.user_warnings), 0)
Пример #28
0
 def test_qs_no_session(self):
     pg = PeopleGrid()
     pg.apply_qs_args()
     assert pg.column('firstname').filter.op is None
Пример #29
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)
Пример #30
0
 def test_qs_search_disabled(self):
     g = PeopleGrid()
     g.enable_search = False
     g.apply_qs_args()
     assert g.search_value is None
Пример #31
0
 def test_export_to_xlsx(self):
     g = PeopleGrid()
     g.apply_qs_args()
     eq_(g.export_to, 'xlsx')
Пример #32
0
 def test_export_to_unrecognized(self):
     g = PeopleGrid()
     g.apply_qs_args()
     eq_(g.export_to, None)
Пример #33
0
 def test_qs_search(self):
     g = PeopleGrid()
     g.enable_search = True
     g.apply_qs_args()
     eq_(g.search_value, 'bar')
Пример #34
0
 def test_export_to_unrecognized(self):
     g = PeopleGrid()
     g.apply_qs_args()
     eq_(g.export_to, None)
Пример #35
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)