def test_minimal_renumbering(self): """Test basic renumbering. Also serves as regression for Bug 215, which is caused when the renumber function tries to renumber a task to an exact task_order that is already in use, e.g., 0.5. The fix for that bug is to suspend uniqueness during renumbering. IntegrityError: duplicate key value violates unique constraint "whatnext_task_user_id_7def82383af900e6_uniq" # noqa DETAIL: Key (user_id, task_order)=(3, 0.50000000000000000000) already exists. """ user = self.user first_task_order = Decimal('0.1') first_name = 'FirstTestTaskName' + random_unicode_string() second_task_order = Decimal('0.2') second_name = 'SecondTestTaskName' + random_unicode_string() third_task_order = Decimal('0.3') third_name = 'ThirdTestTaskName' + random_unicode_string() Task.objects.create( name=first_name, user=user, task_order=first_task_order) second_task = Task.objects.create( name=second_name, user=user, task_order=second_task_order) Task.objects.create( name=third_name, user=user, task_order=third_task_order) Task.renumber(user) refreshed_second_task = Task.objects.get(pk=second_task.pk) self.assertEqual(refreshed_second_task.task_order, Decimal(0.5))
def test_happy_unicode_tag_CRUD(self): selenium_Tag_CRUD( self, self.wd, self.live_server_url, self.username, self.password, 'TestTagName' + random_unicode_string(), 'NewTestTagName' + random_unicode_string())
def test_happy_minimal_unicode_task_CRUD(self): selenium_Task_minimal_CRUD( self, self.wd, self.live_server_url, self.username, self.password, 'TestTaskName' + random_unicode_string(), 'TestEstimate' + random_unicode_string(), 'NewTestTaskName' + random_unicode_string())
def test_today_list_happy_path(self): # Log in and navigate driver = self.wd login(driver, self.live_server_url, self.username, self.password) name = 'Bug249TaskName{0}'.format(random_unicode_string()) escaped_name = format_html(name) self.assertIn('Name', driver.page_source) driver.find_element_by_id('new_task').click() # make a new task driver.find_element_by_id('id_name').clear() driver.find_element_by_id('id_name').send_keys(name) driver.find_element_by_id('save').click() # mark the task done # find the hyperlink which has class=mark_done within # the entity which is the grandparent of the entity with # class=taskname and content of task name xpath_search = '//*[contains(concat(" ", normalize-space(@class), " "), " taskname ")][contains(., "{0}")]/../..//a[contains(concat(" ", normalize-space(@class), " "), " mark_done ")]'.format(name) # noqa driver.find_element_by_xpath(xpath_search).click() # go to the tasks completed today page and expect to find the task driver.find_element_by_id('task_done_since').click() self.assertTrue( driver.find_element_by_xpath( '//*[contains(text(),"{0}")]'. format(escaped_name)) )
def test_unicode_full_CRUD(self): selenium_Task_full_CRUD( self, self.wd, self.live_server_url, self.username, self.password, 'TestTaskName' + random_unicode_string(), 'TestEstimate' + random_unicode_string(), 'NewTestTaskName' + random_unicode_string(), random.randrange(0, 1000000), 'last tuesday', 'TestResolution' + random_unicode_string(), 'TestnotesDuration' + random_unicode_string(size=100), )
def test_create_many_tasks(self): """200 items is enough to force a renumber. That this test runs without being interrupted by an error is enough.""" user = self.user for _ in range(200): name = 'TestTaskName' + random_unicode_string() task_order = get_task_order(user, None, None, None, 'top') Task.objects.create(name=name, user=user, task_order=task_order)
def test_task_with_tag_and_delete(self): # Log in and navigate normal_task_name = 'NormalTask{0}'.format(random_unicode_string()) closed_task_name = 'ClosedTask{0}'.format(random_unicode_string()) snoozed_task_name = 'SnoozedTask{0}'.format(random_unicode_string()) snooze_time = 'tomorrow' driver = self.wd login(driver, self.live_server_url, self.username, self.password) self.assertIn('Name', driver.page_source) # make the first task create_simple_task(driver, self, normal_task_name) create_simple_task(driver, self, closed_task_name) create_simple_task(driver, self, snoozed_task_name) # close a task # find the hyperlink which has class=mark_done within # the entity which is the grandparent of the entity with # class=taskname and content of task name xpath_close = '//*[contains(concat(" ", normalize-space(@class), " "), " taskname ")][contains(., "{0}")]/../..//a[contains(concat(" ", normalize-space(@class), " "), " mark_done ")]'.format(closed_task_name) # noqa driver.find_element_by_xpath(xpath_close).click() # closed task should be gone and normal task should still be there with self.assertRaises(NoSuchElementException): driver.find_element_by_xpath( '//*[contains(text(),"{0}")]'. format(closed_task_name) ) self.assertTrue( driver.find_element_by_xpath( '//*[contains(text(),"{0}")]'. format(snoozed_task_name)) ) self.assertTrue( driver.find_element_by_xpath( '//*[contains(text(),"{0}")]'. format(normal_task_name)) ) # snooze a task # find the hyperlink which has class=taskname # and content of task name xpath_snoozed_name = '//*[contains(concat(" ", normalize-space(@class), " "), " taskname ")][contains(., "{0}")]'.format(snoozed_task_name) # noqa driver.find_element_by_xpath(xpath_snoozed_name).click() driver.find_element_by_id('id_wait_until').clear() driver.find_element_by_id('id_wait_until').send_keys(snooze_time) driver.find_element_by_id('save').click() driver.find_element_by_id('back to task list').click() # snoozed task and closed task should be gone and normal task # should still be there with self.assertRaises(NoSuchElementException): driver.find_element_by_xpath( '//*[contains(text(),"{0}")]'. format(closed_task_name) ) with self.assertRaises(NoSuchElementException): driver.find_element_by_xpath( '//*[contains(text(),"{0}")]'. format(snoozed_task_name) ) self.assertTrue( driver.find_element_by_xpath( '//*[contains(text(),"{0}")]'. format(normal_task_name)) ) # turn on show closed tasks and see the closed task (but not # the snoozed one) driver.find_element_by_id('id_show_closed').click() driver.find_element_by_id('filter').click() self.assertTrue( driver.find_element_by_xpath( '//*[contains(text(),"{0}")]'. format(closed_task_name)) ) with self.assertRaises(NoSuchElementException): driver.find_element_by_xpath( '//*[contains(text(),"{0}")]'. format(snoozed_task_name) ) self.assertTrue( driver.find_element_by_xpath( '//*[contains(text(),"{0}")]'. format(normal_task_name)) ) # reset filters, see only normal task driver.find_element_by_id('reset filters').click() with self.assertRaises(NoSuchElementException): driver.find_element_by_xpath( '//*[contains(text(),"{0}")]'. format(closed_task_name) ) with self.assertRaises(NoSuchElementException): driver.find_element_by_xpath( '//*[contains(text(),"{0}")]'. format(snoozed_task_name) ) self.assertTrue( driver.find_element_by_xpath( '//*[contains(text(),"{0}")]'. format(normal_task_name)) ) # turn on show snoozed tasks and see the closed task (but not # the snoozed one) driver.find_element_by_id('id_show_snoozed').click() driver.find_element_by_id('filter').click() with self.assertRaises(NoSuchElementException): driver.find_element_by_xpath( '//*[contains(text(),"{0}")]'. format(closed_task_name) ) self.assertTrue( driver.find_element_by_xpath( '//*[contains(text(),"{0}")]'. format(snoozed_task_name)) ) self.assertTrue( driver.find_element_by_xpath( '//*[contains(text(),"{0}")]'. format(normal_task_name)) ) # Helpful debugging: debug_dump = open('index.html', 'w') debug_dump.write(driver.page_source) debug_dump.close()
def test_moving_nextline(self): """Move a nextline and verify that the relative order of tasks in the nextline is preserved """ user = self.user first_task_order = Decimal('0.1') first_name = 'FirstTestTaskName' + random_string() second_task_order = Decimal('0.2') second_name = 'SecondTestTaskName' + random_string() third_task_order = Decimal('0.3') third_name = 'ThirdTestTaskName' + random_string() nextline_name = 'NextLine' + random_unicode_string() # create three tasks and a nextline. Assign bottom two tasks # to nextline first_task = Task.objects.create( name=first_name, user=user, task_order=first_task_order) second_task = Task.objects.create( name=second_name, user=user, task_order=second_task_order) third_task = Task.objects.create( name=third_name, user=user, task_order=third_task_order) nextline = NextLine.objects.create( name=nextline_name, user=user,) second_task.nextline = nextline second_task.save() third_task.nextline = nextline third_task.save() # Move NextLine to top driver = self.wd login(driver, self.live_server_url, self.username, self.password) self.assertIn('Name', driver.page_source) # find the hyperlink which has class="move_nextline_to_top" inside a P # containing the nextline's name move_xpath = '//*[contains(text(),"{0}")]/../a[contains(concat(" ", normalize-space(@class), " "), " move_nextline_to_top ")]'.format(nextline_name) # noqa driver.find_element_by_xpath(move_xpath).click() # verify that task order is now second, third, first # TODO: fix the false negative here - probably caused by # transactions or something keeping these from getting updated order_first = Task.objects.get(id=first_task.id).task_order order_second = Task.objects.get(id=second_task.id).task_order order_third = Task.objects.get(id=third_task.id).task_order self.assertTrue(order_first > order_third) self.assertTrue(order_third > order_second) debug_dump = open('index.html', 'w') debug_dump.write(driver.page_source) debug_dump.close()
def test_task_with_tag_and_delete(self): # Log in and navigate first_task_name = 'Bug224FirstTaskName{0}'.format(random_unicode_string()) second_task_name = 'Bug224SecondTaskName{0}'.format(random_unicode_string()) tag_name = 'Bug224TagName{0}'.format(random_unicode_string()) driver = self.wd login(driver, self.live_server_url, self.username, self.password) self.assertIn('Name', driver.page_source) # make the first task driver.find_element_by_id('top_name').clear() driver.find_element_by_id('top_name').send_keys(first_task_name) driver.find_element_by_id('submitTaskTop').click() # find the task name on the page self.assertTrue( driver.find_element_by_xpath( '//*[contains(text(),"{0}")]'. format(first_task_name)) ) # delete the first task # find the input which has class=delete within # the entity which is the grandparent of the entity with # class=taskname and content of task name delete_xpath = '//*[contains(concat(" ", normalize-space(@class), " "), " taskname ")][contains(., "{0}")]/../..//input[contains(concat(" ", normalize-space(@class), " "), " delete ")]'.format(first_task_name) # noqa driver.find_element_by_xpath(delete_xpath).click() # make sure the first task is gone with self.assertRaises(NoSuchElementException): driver.find_element_by_xpath( '//*[contains(text(),"{0}")]'. format(first_task_name) ) # navigate to new tag page driver.find_element_by_id('tag_list').click() self.assertIn('Name', driver.page_source) driver.find_element_by_id('new tag').click() # make a new tag driver.find_element_by_id('id_name').clear() driver.find_element_by_id('id_name').send_keys(tag_name) driver.find_element_by_id('save').click() # find the tag name on the page self.assertTrue( driver.find_element_by_xpath( '//a[contains(.,"{0}")]'. format(tag_name)) ) # Navigate to the task list and filter by the tag driver.find_element_by_id('all tasks').click() # find the include_tag input just before the filter_tag_name # label that contains the tag name driver.find_element_by_xpath( '//label[@class="filter_tag_name"][contains(text(),"{0}")]//preceding-sibling::input[@class="include_tag"]'. # noqa format(tag_name) ).click() driver.find_element_by_id('filter').click() # make the second new task driver.find_element_by_id('top_name').clear() driver.find_element_by_id('top_name').send_keys(second_task_name) driver.find_element_by_id('submitTaskTop').click() self.assertTrue( driver.find_element_by_xpath( '//*[contains(text(),"{0}")]'. format(second_task_name)) )