def test_index_filters_results(pyramid_request, factories, query, expected_groups): factories.Group(name='BioPub') factories.Group(name='ChemPub') if query: pyramid_request.GET['q'] = query ctx = admin_groups.groups_index(None, pyramid_request) filtered_group_names = sorted([g.name for g in ctx['results']]) assert filtered_group_names == expected_groups
def test_index_lists_groups_sorted_by_created_desc(pyramid_request, routes, factories, authority): groups = [factories.Group(created=datetime.datetime(2017, 8, 2)), factories.Group(created=datetime.datetime(2015, 2, 1)), factories.Group(), factories.Group(created=datetime.datetime(2013, 2, 1))] ctx = admin_groups.groups_index(None, pyramid_request) # We can't avoid getting the Public group back, which is created outside of # these tests' sphere of influence. Remove it as it is not feasible to # assert where it will appear in creation order. filtered_groups = list(filter(lambda group: group.pubid != '__world__', ctx['results'])) expected_groups = [groups[2], groups[0], groups[1], groups[3]] assert filtered_groups == expected_groups
def test_index_lists_groups_sorted_by_created_desc(pyramid_request, routes, factories, authority): groups = [ factories.Group(created=datetime.datetime(2017, 8, 2)), factories.Group(created=datetime.datetime(2015, 2, 1)), factories.Group(), factories.Group(created=datetime.datetime(2013, 2, 1)) ] ctx = admin_groups.groups_index(None, pyramid_request) # We can't avoid getting the Public group back, which is created outside of # these tests' sphere of influence. Remove it as it is not feasible to # assert where it will appear in creation order. filtered_groups = list( filter(lambda group: group.pubid != '__world__', ctx['results'])) expected_groups = [groups[2], groups[0], groups[1], groups[3]] assert filtered_groups == expected_groups
def test_index_paginates_results(pyramid_request, routes, paginate): admin_groups.groups_index(None, pyramid_request) paginate.assert_called_once_with(pyramid_request, mock.ANY, mock.ANY)