Exemple #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)
    def test_service_dashboard_view_display_services(self):
        service1 = ServiceFactory()
        service2 = ServiceFactory()

        view = setup_view(DashboardView(), self.get_request)
        response = view.get(view.request)

        self.assertContains(response, service1.repo_name)
        self.assertContains(response, service2.repo_name)
    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])
Exemple #4
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)
    def test_service_dashboard_view_POST_request_return_filtered_services(
            self):
        service1 = ServiceFactory(repo_name='repo_name1')
        service2 = ServiceFactory(repo_name='repo_name2')

        post_request = RequestFactory().post('/request',
                                             {'services': service1.pk})
        view = setup_view(DashboardView(), post_request)
        response = view.post(view.request)
        self.assertContains(response, service1.repo_name)
        self.assertNotContains(response, service2.repo_name)

        post_request = RequestFactory().post('/request',
                                             {'services': service2.pk})
        view = setup_view(DashboardView(), post_request)
        response = view.post(view.request)
        self.assertContains(response, service2.repo_name)
        self.assertNotContains(response, service1.repo_name)
    def setUp(self):

        self.client = Client()
        self.payload = LoadPayload()
        self.service_bb = ServiceFactory()
        self.service_gh = ServiceFactory(repo_source='gh')

        self.service_ftp_bb = ServiceFactory(
            ftp_host=settings.FTP_TEST_SETTINGS['host'],
            ftp_username=settings.FTP_TEST_SETTINGS['username'],
            ftp_password=settings.FTP_TEST_SETTINGS['password'],
            ftp_path=settings.FTP_TEST_SETTINGS['path']
        )
        self.service_ftp_gh = ServiceFactory(
            ftp_host=settings.FTP_TEST_SETTINGS['host'],
            ftp_username=settings.FTP_TEST_SETTINGS['username'],
            ftp_password=settings.FTP_TEST_SETTINGS['password'],
            ftp_path=settings.FTP_TEST_SETTINGS['path'],
            repo_source='gh'
        )
Exemple #7
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()
Exemple #8
0
 def setUp(self):
     self.service = ServiceFactory()
 def setUp(self):
     self.service = ServiceFactory()
     self.get_request = RequestFactory().get('/request')
 def setUp(self):
     self.service_bb = ServiceFactory()
     self.service_gh = ServiceFactory(repo_source='gh')
     self.get_request = RequestFactory().get('/request')
     self.post_request = RequestFactory().post('/request',
                                               {'payload': True})
 def setUp(self):
     self.service = ServiceFactory()
     service = Service.objects.filter(pk=self.service.pk).values()
     self.get_request = RequestFactory().get('/request')
     self.post_request = RequestFactory().post('/request', service[0])
 def setUp(self):
     self.client = Client()
     self.service = ServiceFactory()
 def setUp(self):
     self.client = Client()
     self.payload = LoadPayload()
     self.service_bb = ServiceFactory()
     self.service_gh = ServiceFactory(repo_source='gh')
Exemple #14
0
 def setUp(self):
     self.service_bb = ServiceFactory()
     self.service_gh = ServiceFactory(repo_source='gh')
    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 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)