Skip to content

Commit

Permalink
Added test
Browse files Browse the repository at this point in the history
  • Loading branch information
viktordick committed Oct 2, 2018
1 parent 387bfed commit bb4dbb4
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/OFS/ObjectManager.py
Expand Up @@ -877,7 +877,7 @@ def manage_get_sortedObjects(self, sortkey, revkey):
is the ID of the object as known by the parent and 'obj' is the child
object.
'''
if sortkey not in ['id', 'title', 'meta_type', 'get_size', '_p_mtime']:
if sortkey not in ['title', 'meta_type', 'get_size', '_p_mtime']:
sortkey = 'id'

items = []
Expand Down
47 changes: 47 additions & 0 deletions src/OFS/tests/testSorting.py
@@ -0,0 +1,47 @@
# -*- coding: utf-8 -*-
import codecs
import Testing.ZopeTestCase
import Testing.testbrowser
import Zope2.App

class SortingTests(Testing.ZopeTestCase.FunctionalTestCase):
"""Browser testing ..Image.File"""

def setUp(self):
super(SortingTests, self).setUp()

Zope2.App.zcml.load_site(force=True)

uf = self.app.acl_users
uf.userFolderAddUser('manager', 'manager_pass', ['Manager'], [])
self.app.manage_addFolder('sortingTest')
self.app.sortingTest.manage_addFile('File1')
self.app.sortingTest.manage_addFile('File2')
self.app.sortingTest.File1.update_data(u'hällo'.encode('utf-8'))

self.browser = Testing.testbrowser.Browser()
self.browser.addHeader(
'Authorization',
'basic {}'.format(codecs.encode(
b'manager:manager_pass', 'base64').decode()))

def test_sortby(self):
base_url = 'http://localhost/sortingTest/manage_main?skey=%s&rkey=%s'

def do_assert(one_before_two):
one_before_two_found = (
self.browser.contents.find('File2') > self.browser.contents.find('File1')
)
self.assertTrue(one_before_two == one_before_two_found)

self.browser.open(base_url % ('id', 'asc'))
do_assert(one_before_two = True)

self.browser.open(base_url % ('id', 'desc'))
do_assert(one_before_two = False)

self.browser.open(base_url % ('get_size', 'asc'))
do_assert(one_before_two = False)

self.browser.open(base_url % ('get_size', 'desc'))
do_assert(one_before_two = True)

0 comments on commit bb4dbb4

Please sign in to comment.