Example #1
0
    def test_log_page_POST_request_return_filtered_logs(self):
        service1 = ServiceFactory(repo_name='service_1')
        service2 = ServiceFactory(repo_name='service_2')
        service3 = ServiceFactory(repo_name='service_3')
        log1 = LogFactory(service=service1)
        log2 = LogFactory(service=service2)
        log3 = LogFactory(service=service3, status=False)

        post_request = RequestFactory().post('/request', {
            'services': 0,
            'status': 0
        })
        view = setup_view(LogView(), post_request)
        response = view.post(view.request)
        self.assertContains(response, 'No Results')

        post_request = RequestFactory().post('/request', {
            'services': service1.pk,
            'status': 1
        })
        view = setup_view(LogView(), post_request)
        response = view.post(view.request)
        self.assertContains(response, log1.service)
        self.assertNotContains(response, log3.service)

        post_request = RequestFactory().post('/request', {
            'services': service3.pk,
            'status': 0
        })
        view = setup_view(LogView(), post_request)
        response = view.post(view.request)

        self.assertContains(response, log3.service)
        self.assertNotContains(response, log1.service)
        self.assertNotContains(response, log2.service)
Example #2
0
    def test_service_fail_deploys_method(self):
        """"service fail_deploy method return number of related logs with status False"""
        log = LogFactory(service=self.service)
        self.assertEqual(self.service.fail_deploys(), 0)
        log.status = False
        log.save()

        self.assertEqual(self.service.fail_deploys(), 1)
Example #3
0
    def test_log_display_logs_entries(self):
        log1 = LogFactory()
        log2 = LogFactory()
        view = setup_view(LogView(), self.get_request)
        response = view.get(view.request)

        self.assertContains(response, log1.service)
        self.assertContains(response, log2.service)
Example #4
0
    def test_service_check_log_return_number_of_fail_logs_assign_to_service(
            self):
        log1 = LogFactory(service=self.service, status=False)
        log2 = LogFactory(service=self.service, status=False)
        log3 = LogFactory(service=self.service, status=True)

        check_log = service_check(self.service)
        check_log.check_log()

        self.assertEqual(check_log.message, ['<b>Log</b>: Deploy Fails(2)'])
        self.assertTrue(check_log.fails[0])
Example #5
0
    def test_service_deploy_method(self):
        """service deploy method return number of related logs"""
        self.assertEqual(self.service.deploys(), 0)
        log = LogFactory(service=self.service)

        self.assertEqual(self.service.deploys(), 1)

        log.status = False
        log.save()

        self.assertEqual(self.service.deploys(), 0)
Example #6
0
    def test_commits_info_method(self):
        """log commits_info method return commits information in format [[message,username,raw_node],]"""
        log = LogFactory(service=self.service)

        self.assertEqual(log.commits_info(),
                         [[
                             u'test message commit 2', u'username',
                             u'57baa5c89daef238c2043c7e866c2e997d681876'
                         ],
                          [
                              u'test message commit 1', u'username',
                              u'57baa5c89daef238c2043c7e866c2e997d681871'
                          ]])
    def test_service_dashboard_view_set_services_in_appropriate_order(self):
        service1 = ServiceFactory()
        service2 = ServiceFactory(status=False)
        service3 = ServiceFactory()

        log1 = LogFactory(service=service1)
        log2 = LogFactory(service=service2)
        log3 = LogFactory(service=service3)

        view = setup_view(DashboardView(), self.get_request)
        response = view.get(view.request)
        object_list = list(response.context_data['object_list'])

        self.assertListEqual(object_list, [service2, service3, service1])
Example #8
0
    def setUp(self):
        self.service = ServiceFactory()

        log = LogFactory(service=self.service)
        payload = json.loads(log.payload)
        self.data = commits_parser(payload['commits'],
                                   self.service.repo_source)
Example #9
0
    def test_log_skip_deploy_view_POST_request_return_json_response(self):
        log1 = LogFactory()
        view = setup_view(LogSkipDeployView(), self.post_request, pk=log1.pk)
        response = view.post(view.request)

        response = json.loads(response.content.decode('utf-8'))
        self.assertEqual(response['status'], 'success')
Example #10
0
    def test_log_skip_deploy_view_POST_request_set_skip_flag(self):
        log1 = LogFactory()
        view = setup_view(LogSkipDeployView(), self.post_request)
        view.get_object = lambda: log1
        response = view.post(view.request)
        log = Log.objects.get(pk=log1.pk)

        self.assertTrue(log.skip)
    def test_service_restore_view_gh_context(self):
        log1 = LogFactory(service=self.service_gh, status=False)
        log2 = LogFactory(service=self.service_gh, status=False)

        view = setup_view(ServiceRestoreView(),
                          self.get_request,
                          pk=self.service_gh.pk)
        view.object = self.service_gh
        context = view.get_context_data()

        self.assertEqual(context['files_added'], [u'example/file2.txt'])
        self.assertEqual(context['files_modified'], [u'example/file1.txt'])
        self.assertEqual(context['files_removed'], [u'example/file3.txt'])
        self.assertEqual(context['service'], self.service_gh)
        self.assertEqual(context['commits_info'],
                         [[
                             u'test message commit 2', u'Author',
                             u'2fa93a45f6c4f9fe30e54036fe0cf764fae0b2a2'
                         ],
                          [
                              u'test message commit 1', u'Author',
                              u'2fa93a45f6c4f9fe30e54036fe0cf764fae0b2a1'
                          ],
                          [
                              u'test message commit 2', u'Author',
                              u'2fa93a45f6c4f9fe30e54036fe0cf764fae0b2a2'
                          ],
                          [
                              u'test message commit 1', u'Author',
                              u'2fa93a45f6c4f9fe30e54036fe0cf764fae0b2a1'
                          ]])

        payload = json.loads(context['payload'])
        self.assertEqual(payload['pusher']['name'], 'Restore')
        self.assertEqual(payload['commits'][0]['message'],
                         'test message commit 1')
        self.assertEqual(payload['commits'][1]['message'],
                         'test message commit 2')
        self.assertEqual(payload['commits'][2]['message'],
                         'test message commit 1')
        self.assertEqual(payload['commits'][3]['message'],
                         'test message commit 2')
    def test_service_restore_view_bb_context(self):
        log1 = LogFactory(service=self.service_bb, status=False)
        log2 = LogFactory(service=self.service_bb, status=False)

        view = setup_view(ServiceRestoreView(),
                          self.get_request,
                          pk=self.service_bb.pk)
        view.object = self.service_bb
        context = view.get_context_data()

        self.assertEqual(context['files_added'], [u'example/file2.txt'])
        self.assertEqual(context['files_modified'], [u'example/file1.txt'])
        self.assertEqual(context['files_removed'], [u'example/file3.txt'])
        self.assertEqual(context['service'], self.service_bb)
        self.assertEqual(context['commits_info'],
                         [[
                             u'test message commit 2', u'username',
                             u'57baa5c89daef238c2043c7e866c2e997d681876'
                         ],
                          [
                              u'test message commit 1', u'username',
                              u'57baa5c89daef238c2043c7e866c2e997d681871'
                          ],
                          [
                              u'test message commit 2', u'username',
                              u'57baa5c89daef238c2043c7e866c2e997d681876'
                          ],
                          [
                              u'test message commit 1', u'username',
                              u'57baa5c89daef238c2043c7e866c2e997d681871'
                          ]])

        payload = json.loads(context['payload'])
        self.assertEqual(payload['user'], 'Restore')
        self.assertEqual(payload['commits'][0]['message'],
                         'test message commit 1')
        self.assertEqual(payload['commits'][1]['message'],
                         'test message commit 2')
        self.assertEqual(payload['commits'][2]['message'],
                         'test message commit 1')
        self.assertEqual(payload['commits'][3]['message'],
                         'test message commit 2')
Example #13
0
    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()
Example #14
0
    def test_service_get_logs_tree_method(self):
        """service get_logs_tree method return logs in proper order and omit skipped"""
        log1 = LogFactory(service=self.service)
        log2 = LogFactory(service=self.service, status=False, skip=True)
        log3 = LogFactory(service=self.service)
        log4 = LogFactory(service=self.service, status=False)
        log5 = LogFactory(service=self.service)
        log6 = LogFactory(service=self.service, status=False, skip=True)
        log7 = LogFactory(service=self.service)

        self.assertListEqual(list(self.service.get_logs_tree()),
                             [log3, log4, log5, log7])
Example #15
0
    def test_service_skipped_deploys_method(self):
        """service skipped_deploys method return number of relatet logs with skiped status True """
        log = LogFactory(service=self.service)

        self.assertEqual(self.service.skipped_deploys(), 0)

        log.status = False
        log.skip = True
        log.save()

        self.assertEqual(self.service.skipped_deploys(), 1)
    def test_can_see_and_use_log_page(self):
        self.user_authenticate()

        # User go to log page by click Log link on top menu
        nav = self.browser.find_element_by_xpath("//div[@role='navigation']")
        nav.find_element_by_link_text("Log").click()
        self.wait_for_load()

        # He noticed Log Dashboard header
        # along with empty log table
        page_header = self.browser.find_element_by_class_name('page-header').text
        self.assertIn('Log', page_header)
        table_first_row = self.browser.find_element_by_xpath("//table/tbody/tr[1]")
        self.assertIn('No Results', table_first_row.text)

        # He create 2 services and perform one deploy each.
        service1 = ServiceFactory()
        service2 = ServiceFactory()
        Log1 = LogFactory(service=service1)
        Log2 = LogFactory(service=service1, status=False)
        Log3 = LogFactory(service=service2)

        self.browser.get(self.live_server_url + reverse('ftpdeploy_log'))
        self.wait_for_load()

        # He noticed there are log entries in table
        # In addition he notices one deploy fail
        table_rows = self.browser.find_elements_by_xpath("//table/tbody/tr")
        self.assertEqual(len(table_rows), 3)

        # He test log filter
        # he tick fail status and see only one row in table

        form = self.browser.find_element_by_id('log-filter')
        form.find_element_by_id('status').click()
        time.sleep(0.1)

        table_rows = self.browser.find_elements_by_xpath("//table/tbody/tr")
        self.assertEqual(len(table_rows), 1)

        table_first_row = self.browser.find_element_by_xpath("//table/tbody/tr[1]")
        self.assertIn(Log2.service.repo_name, table_first_row.text)

        # after he untick fail only checkbox and is able to see all 3 rows again

        form.find_element_by_id('status').click()
        time.sleep(0.1)
        table_rows = self.browser.find_elements_by_xpath("//table/tbody/tr")
        self.assertEqual(len(table_rows), 3)

        # next he select log with first service1 assign to it,
        # and see two rows in table with appropriate service repo name

        form.find_element_by_tag_name('select')
        options = form.find_elements_by_tag_name('option')

        for option in options:
            if option.text == Log1.service.repo_name:
                option.click()

        time.sleep(0.1)
        table_rows = self.browser.find_elements_by_xpath("//table/tbody/tr")
        self.assertEqual(len(table_rows), 2)

        table = self.browser.find_element_by_tag_name('table')
        self.assertIn(Log1.service.repo_name, table.text)

        # afterwords he select log with service2 assign to it
        # and see only one row in table with appropriate service repo name

        form.find_element_by_tag_name('select')
        options = form.find_elements_by_tag_name('option')

        for option in options:
            if option.text == Log3.service.repo_name:
                option.click()

        time.sleep(0.1)
        table_rows = self.browser.find_elements_by_xpath("//table/tbody/tr")
        self.assertEqual(len(table_rows), 1)

        table = self.browser.find_element_by_tag_name('table')
        self.assertIn(Log3.service.repo_name, table.text)
Example #17
0
 def test_service_latest_log_user_method(self):
     """service latest_log_user method return latest related log user"""
     log1 = LogFactory(service=self.service)
     log2 = LogFactory(service=self.service)
     self.assertEqual(self.service.latest_log_user(),
                      self.service.log_set.latest('created').user)
Example #18
0
 def test_service_latest_log_date_method(self):
     """service latest_log_date method return latest related log create date"""
     log1 = LogFactory(service=self.service)
     log2 = LogFactory(service=self.service)
     self.assertEqual(self.service.latest_log_date(),
                      self.service.log_set.latest('created').created)
    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)