def test_notification_view_display_notifications(self): notification1 = NotificationFactory() notification2 = NotificationFactory() view = setup_view(NotificationView(), self.get_request) response = view.get(view.request) self.assertContains(response, notification1.name) self.assertContains(response, notification2.name)
def setUp(self): notification = NotificationFactory( success= '[email protected],[email protected],[email protected]', fail='[email protected],[email protected]', deploy_user=[]) self.service = ServiceFactory(notification=notification) self.log = LogFactory(service=self.service) request_factory = RequestFactory() request = request_factory.get('/example') self.host = absolute_url(request).build()
class NotificationEditViewTest(TestCase): def setUp(self): self.notification = NotificationFactory() self.get_request = RequestFactory().get('/request') def test_notification_edit_view_context_contain_email_list(self): view = setup_view(NotificationEditView(), self.get_request, pk=self.notification.pk) response = view.get(view.request) self.assertEqual(response.context_data['emails'], self.notification.get_email_list()) @patch('ftp_deploy.server.views.notification.messages') def test_notification_edit_view_set_message_after_success_submit(self, mock_messages): view = setup_view(NotificationEditView(), self.get_request) mock_messages.add_message = MagicMock() view.form_class = MagicMock() view.form_valid(view.form_class) self.assertTrue(mock_messages.add_message.called)
def setUp(self): self.notification = NotificationFactory()
class NotificationTest(TestCase): def setUp(self): self.notification = NotificationFactory() def test_notification_get_email_list_method(self): """ notification get_email_list methos return email list in format {{'*****@*****.**': {'success': True}, '*****@*****.**': {'success': True}, '*****@*****.**': {'fail': True}, '*****@*****.**': {'fail': True}}} """ success = self.notification.get_success() fail = self.notification.get_fail() email_list = { success[0]: { 'success': True }, success[1]: { 'success': True }, fail[0]: { 'fail': True }, fail[1]: { 'fail': True } } self.assertEqual(self.notification.get_email_list(), email_list) def test_notification_user_methods(self): """notification user_commits_success and user_deploy_fail... methods return True of False according to settings""" self.assertEqual(self.notification.commit_user_success(), True) self.assertEqual(self.notification.commit_user_fail(), True) self.assertEqual(self.notification.deploy_user_success(), True) self.assertEqual(self.notification.deploy_user_fail(), True) self.notification.commit_user = [u'1'] self.notification.deploy_user = [] self.notification.save() self.assertEqual(self.notification.commit_user_success(), False) self.assertEqual(self.notification.commit_user_fail(), True) self.assertEqual(self.notification.deploy_user_success(), False) self.assertEqual(self.notification.deploy_user_fail(), False)
def test_can_see_service_dashboard_page_and_manage_services(self): self.user_authenticate() # User go to services page by click left menu 'Services' link page = self.browser.find_element_by_id('page') page.find_element_by_link_text("Services").click() self.wait_for_load() page_header = self.browser.find_element_by_class_name('page-header').text # He can see Services Dashboard title self.assertIn('Services Dashboard', page_header) # He is welcome with message and see big 'Add Service' button page = self.browser.find_element_by_id('page') page.find_element_by_class_name('well') add_service_btn = self.browser.find_element_by_class_name('btn-success') self.assertIn('Add Service', add_service_btn.text) # He click Add service button and go do service form page add_service_btn.click() self.wait_for_load() self.assertIn('Service Add', self.browser.find_element_by_class_name('page-header').text) page = self.browser.find_element_by_id('page') page.find_element_by_id('service-form') # Saveing checking is omit intentionaly because of cost of validation process # Service is add programmatically without check process service1 = ServiceFactory(repo_hook=False, status=False) service2 = ServiceFactory(repo_hook=False, status=False) service3 = ServiceFactory(repo_hook=False, status=False) self.browser.get(self.live_server_url + reverse('ftpdeploy_dashboard')) self.wait_for_load() # After he added 3 services, he can see all of them on the list service_list = self.browser.find_element_by_id('service-list') self.assertIn(service1.repo_name, service_list.text) self.assertIn(service2.repo_name, service_list.text) self.assertIn(service3.repo_name, service_list.text) # He use filter and confirm filter works as expected form = self.browser.find_element_by_id('service-filter') options = form.find_elements_by_tag_name('option') for option in options: if option.text == service1.repo_name: option.click() time.sleep(0.1) table_rows = self.browser.find_elements_by_xpath("//tbody[@id='service-list']/tr") self.assertEqual(len(table_rows), 1) table = self.browser.find_element_by_id('service-list') self.assertIn(service1.repo_name, table.text) self.assertNotIn(service2.repo_name, table.text) self.assertNotIn(service3.repo_name, table.text) for option in options: if option.text == service2.repo_name: option.click() time.sleep(0.1) table_rows = self.browser.find_elements_by_xpath("//tbody[@id='service-list']/tr") self.assertEqual(len(table_rows), 1) table = self.browser.find_element_by_id('service-list') self.assertIn(service2.repo_name, table.text) self.assertNotIn(service1.repo_name, table.text) self.assertNotIn(service3.repo_name, table.text) # He noticed he can add new service by the 'Add Service' if service already exist as well # He click it and see add service form again. page = self.browser.find_element_by_id('page') page.find_element_by_link_text('Add Service').click() self.wait_for_load() page = self.browser.find_element_by_id('page') page.find_element_by_id('service-form') self.browser.get(self.live_server_url + reverse('ftpdeploy_dashboard')) self.wait_for_load() # He click 'Edit' link next to the service and go to edit form. He noticed thah form is prepopulated by saved values first_service = self.browser.find_element_by_xpath("//tbody[@id='service-list']/tr[1]") first_service.find_element_by_link_text('Edit').click() self.wait_for_load() form = self.browser.find_element_by_id('service-form') repo_name = self.browser.find_element_by_id('id_repo_name') secret_key = self.browser.find_element_by_id('id_secret_key') self.assertIn(service1.repo_name, repo_name.get_attribute('value')) self.assertIn(service1.secret_key, secret_key.get_attribute('value')) # He notice there is 'Manage' link on page header. He click it and go to Manage Page page_header = self.browser.find_element_by_class_name('page-header') page_header.find_element_by_link_text('Manage').click() self.wait_for_load() page_header = self.browser.find_element_by_class_name('page-header') self.assertIn('%s Manage' % service1.repo_name, page_header.text) self.browser.get(self.live_server_url + reverse('ftpdeploy_dashboard')) self.wait_for_load() # He click 'Manage' link next to the service and go to manage page first_service = self.browser.find_element_by_xpath("//tbody[@id='service-list']/tr[1]") first_service.find_element_by_link_text('Manage').click() self.wait_for_load() # He can see 'Repo_name Manage' header page_header = self.browser.find_element_by_class_name('page-header') self.assertIn('%s Manage' % service1.repo_name, page_header.text) # He notice service status fail because of invalid hook, and see 'Add hook' link page = self.browser.find_element_by_id('page') self.assertIn('Add hook', page.text) # Add hook link test is omit because of time consuming by request # check flag is change programmatically service = Service.objects.get(pk=service1.pk) service.repo_hook = True service.save() self.browser.get(self.live_server_url + reverse('ftpdeploy_service_manage', args=(service.pk,))) self.wait_for_load() # After he click 'Add hook' he noticed that link disappear page = self.browser.find_element_by_id('page') self.assertNotIn('Add hook', page.text) # After few commits he can see Recent deploys table with latests deploys log1 = LogFactory(service=service1) log2 = LogFactory(service=service1) log3 = LogFactory(service=service1, status=False) log4 = LogFactory(service=service1, status=False) self.browser.get(self.live_server_url + reverse('ftpdeploy_service_manage', args=(service.pk,))) self.wait_for_load() # He notice two of deploys fails, and is able to see Fail Deploys table along with 'Restore Deploys' button. fail_deploys = self.browser.find_element_by_id('fail-deploys') fail_deploys.find_element_by_link_text('Restore Deploys') restore_list_rows = self.browser.find_elements_by_xpath("//tbody[@id='restore-list']/tr") self.assertEqual(len(restore_list_rows), 2) # He decided to skip first of failed deploys, and click 'Skip' button, # and then skip entry is not in 'Fail Deploys' table any more first_fail_deploy_row = self.browser.find_element_by_xpath("//tbody[@id='restore-list']/tr[1]") first_fail_deploy_row.find_element_by_link_text('Skip').click() first_fail_deploy_row.find_element_by_link_text('Confirm').click() self.browser.get(self.live_server_url + reverse('ftpdeploy_service_manage', args=(service.pk,))) self.wait_for_load() restore_list_rows = self.browser.find_elements_by_xpath("//tbody[@id='restore-list']/tr") self.assertEqual(len(restore_list_rows), 1) # He cilck 'Restore Deploys' and see popup with 'Restore Tree' title fail_deploys = self.browser.find_element_by_id('fail-deploys') fail_deploys.find_element_by_link_text('Restore Deploys').click() self.wait.until(lambda browser: browser.find_element_by_id('restore-modal')) time.sleep(1) restore_modal = self.browser.find_element_by_id('restore-modal') modal_title = restore_modal.find_element_by_class_name('modal-title') self.assertIn('Restore Tree', restore_modal.text) # He is able to see 'New', 'Modified' and 'Removed' files in restore information # along with commits informations self.assertIn('New', restore_modal.text) self.assertIn('Modified', restore_modal.text) self.assertIn('Removed', restore_modal.text) self.assertIn('commit 1', restore_modal.text) self.assertIn('commit 2', restore_modal.text) # He click close button and close modal window restore_modal.find_element_by_xpath("//button[@data-dismiss='modal']").click() time.sleep(1) body = self.browser.find_element_by_tag_name('body') self.assertNotIn('Restore Tree', body.text) # He decided change notifications for service so he click 'Notification' link notification = NotificationFactory(name='Default') self.browser.find_element_by_id('notification').click() self.wait.until(lambda browser: browser.find_element_by_id('notification-modal')) time.sleep(1) restore_modal = self.browser.find_element_by_id('notification-modal') modal_title = restore_modal.find_element_by_class_name('modal-title') self.assertIn('Notification', restore_modal.text) # In the popup he select 'Default' notification and click save form = self.browser.find_element_by_id('notification-form') options = form.find_elements_by_tag_name('option') for option in options: if option.text == notification.name: option.click() time.sleep(1) form.find_element_by_xpath("//button[@type='submit']").click() self.wait_for_load() # He see save notification success message self.browser.find_element_by_class_name('alert-success') # He see notification name in Statistics section page = self.browser.find_element_by_id('page') self.assertIn('Notifications: Default', page.text) # He noticed status icon is actually a link to refresh service status self.browser.find_element_by_xpath("//a[@id='service-manage-status']") # He click 'Edit' link and see service edit form page_header = self.browser.find_element_by_class_name('page-header') page_header.find_element_by_link_text('Edit').click() self.wait_for_load() form = self.browser.find_element_by_id('service-form') repo_name = self.browser.find_element_by_id('id_repo_name') secret_key = self.browser.find_element_by_id('id_secret_key') self.assertIn(service1.repo_name, repo_name.get_attribute('value')) self.assertIn(service1.secret_key, secret_key.get_attribute('value')) # He decide to delete service and click 'Delete' link, and then confirm delete page_header = self.browser.find_element_by_class_name('page-header') page_header.find_element_by_class_name('dropdown-toggle').click() page_header.find_element_by_link_text('Delete').click() page_header.find_element_by_xpath("//button[@type='submit']").click() self.wait_for_load() self.browser.find_element_by_class_name('alert-success') # He is redirect to service dashboard # see success message and doesn't see removed service on the list any more self.browser.find_element_by_class_name('alert-success') service_list = self.browser.find_element_by_id('service-list') self.assertNotIn(service1.repo_name, service_list.text) self.assertIn(service2.repo_name, service_list.text) self.assertIn(service3.repo_name, service_list.text)
def setUp(self): self.notification = NotificationFactory() self.get_request = RequestFactory().get('/get')