Created
June 8, 2011 20:08
-
-
Save kezabelle/1015274 to your computer and use it in GitHub Desktop.
Terrible attempt at a test case for django-cms
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# the method itself, bundled onto AdminTests | |
def test_changelist_tree_ordering(self): | |
# make sure we're only getting the pages we care about. | |
with SettingsOverride(CMS_MODERATOR=False, CMS_PERMISSION=False): | |
# create some pages, deleting one that pops up in setUp() | |
kwargs = { 'published': True, 'in_navigation': True, 'language': 'en', | |
'template': 'nav_playground.html'} | |
Page.objects.get(pk=1).delete() | |
page1 = create_page(title="page 1", parent=None, soft_root=True, **kwargs) | |
page2 = create_page(title="page 2", **kwargs) | |
page3 = create_page(title="page 3", **kwargs) | |
page4 = create_page(title="page 4", **kwargs) | |
page5 = create_page(title="page 5", parent=page3, **kwargs) | |
page6 = create_page(title="page 6", parent=page3, **kwargs) | |
page7 = create_page(title="page 7", parent=page5, **kwargs) | |
page8 = create_page(title="page 8", parent=page5, **kwargs) | |
page9 = create_page(title="page 9", parent=page5, **kwargs) | |
page10 = create_page(title="page 10", parent=page8, **kwargs) | |
page11 = create_page(title="page 11", parent=page8, **kwargs) | |
# output from 2.1.3 | |
expected_output = ['page 1', 'page 2', 'page 3', 'page 6', 'page 5', | |
'page 9', 'page 8', 'page 11', 'page 10', 'page 7', 'page 4'] | |
with self.login_user_context(self.get_superuser()): | |
response = self.client.get(reverse('admin:cms_page_changelist')) | |
change_list_output = [] | |
# go over every line, simplest way I can think of. | |
for line in response.content.split('\n'): | |
search_string = 'class="title" title="edit this page">' | |
# look for the above string, and modify the proceeding text | |
# until just the title (from the create_page() calls above) | |
# is returned | |
if search_string in line: | |
real_start_pos = line.find(search_string) + len(search_string) | |
outstring = line[real_start_pos:].strip().replace('</a>', '') | |
change_list_output.append(outstring) | |
self.assertNotEqual([], change_list_output) | |
self.assertEqual(expected_output, change_list_output) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment