Beispiel #1
0
    def test_add_job_redirects_when_authenticated(self):
        request = self.factory.post('/pull/save_widget', HTTP_X_REQUESTED_WITH='XMLHttpRequest')
        request.user = self.user
        request.user.is_authenticated = Mock(return_value=True)

        response = views.save_widget(request)

        self.assertEqual(response.status_code, 302)
Beispiel #2
0
    def test_add_job_redirects_when_authenticated(self):
        request = self.factory.post('/pull/save_widget',
                                    HTTP_X_REQUESTED_WITH='XMLHttpRequest')
        request.user = self.user
        request.user.is_authenticated = Mock(return_value=True)

        response = views.save_widget(request)

        self.assertEqual(response.status_code, 302)
Beispiel #3
0
    def test_save_widget_returns_401_when_unauthorized(self):
        request = self.factory.post('/pull/save_widget', HTTP_X_REQUESTED_WITH='XMLHttpRequest')
        request.user = self.user
        request.user.is_authenticated = Mock(return_value=False)

        request.POST['widget_id'] = False
        response = views.save_widget(request)

        self.assertEqual(response.status_code,401)
Beispiel #4
0
    def test_save_widget_returns_401_when_unauthorized(self):
        request = self.factory.post('/pull/save_widget',
                                    HTTP_X_REQUESTED_WITH='XMLHttpRequest')
        request.user = self.user
        request.user.is_authenticated = Mock(return_value=False)

        request.POST['widget_id'] = False
        response = views.save_widget(request)

        self.assertEqual(response.status_code, 401)
Beispiel #5
0
    def test_save_widget_makes_active_when_post_data_defined(self):
        request = self.factory.post('/pull/save_widget', HTTP_X_REQUESTED_WITH='XMLHttpRequest')
        request.user = self.user
        request.user.is_authenticated = Mock(return_value=True)

        request.POST['widget_id'] = self.job1.pk
        request.POST['entity_active'] = '1'

        response = views.save_widget(request)

        widget = models.UserCiJob.objects.get(pk=self.job1.pk)

        self.assertTrue(widget.entity_active)
Beispiel #6
0
    def test_save_widget_makes_active_when_post_data_defined(self):
        request = self.factory.post('/pull/save_widget',
                                    HTTP_X_REQUESTED_WITH='XMLHttpRequest')
        request.user = self.user
        request.user.is_authenticated = Mock(return_value=True)

        request.POST['widget_id'] = self.job1.pk
        request.POST['entity_active'] = '1'

        response = views.save_widget(request)

        widget = models.UserCiJob.objects.get(pk=self.job1.pk)

        self.assertTrue(widget.entity_active)
Beispiel #7
0
    def test_save_widget_creates_and_updates_ci_server_when_new_server_provided(self):
        request = self.factory.post('/pull/save_widget', HTTP_X_REQUESTED_WITH='XMLHttpRequest')
        request.user = self.user
        request.user.is_authenticated = Mock(return_value=True)

        newhostname = "http://reallynewciserver:8080"

        request.POST['new_ci_server'] = newhostname
        request.POST['widget_id'] = self.job1.pk

        response = views.save_widget(request)

        widget = models.UserCiJob.objects.get(pk=self.job1.pk)

        self.assertEqual(widget.ci_server.hostname, newhostname)
Beispiel #8
0
    def test_save_widget_makes_inactive_when_post_data_undefined(self):
        request = self.factory.post('/pull/save_widget', HTTP_X_REQUESTED_WITH='XMLHttpRequest')
        request.user = self.user
        request.user.is_authenticated = Mock(return_value=True)

        request.POST['widget_id'] = self.job1.pk
        # request.POST['entity_active'] = '1'
        # (commented out for verbosity)
        # since 'entity_active' won't be in the POST dict, the widget will be set to inactive

        response = views.save_widget(request)

        widget = models.UserCiJob.objects.get(pk=self.job1.pk)

        self.assertFalse(widget.entity_active)
Beispiel #9
0
    def test_save_widget_updates_fields_when_provided(self):
        request = self.factory.post('/pull/save_widget', HTTP_X_REQUESTED_WITH='XMLHttpRequest')
        request.user = self.user
        request.user.is_authenticated = Mock(return_value=True)

        request.POST['displayname'] = "new-italiandisplay"
        request.POST['jobname'] = "new-italianjob"
        request.POST['widget_id'] = self.job1.pk

        response = views.save_widget(request)

        widget = models.UserCiJob.objects.get(pk=self.job1.pk)

        self.assertEqual(widget.displayname, "new-italiandisplay")
        self.assertEqual(widget.jobname, "new-italianjob")
Beispiel #10
0
    def test_save_widget_makes_inactive_when_post_data_undefined(self):
        request = self.factory.post('/pull/save_widget',
                                    HTTP_X_REQUESTED_WITH='XMLHttpRequest')
        request.user = self.user
        request.user.is_authenticated = Mock(return_value=True)

        request.POST['widget_id'] = self.job1.pk
        # request.POST['entity_active'] = '1'
        # (commented out for verbosity)
        # since 'entity_active' won't be in the POST dict, the widget will be set to inactive

        response = views.save_widget(request)

        widget = models.UserCiJob.objects.get(pk=self.job1.pk)

        self.assertFalse(widget.entity_active)
Beispiel #11
0
    def test_save_widget_updates_fields_when_provided(self):
        request = self.factory.post('/pull/save_widget',
                                    HTTP_X_REQUESTED_WITH='XMLHttpRequest')
        request.user = self.user
        request.user.is_authenticated = Mock(return_value=True)

        request.POST['displayname'] = "new-italiandisplay"
        request.POST['jobname'] = "new-italianjob"
        request.POST['widget_id'] = self.job1.pk

        response = views.save_widget(request)

        widget = models.UserCiJob.objects.get(pk=self.job1.pk)

        self.assertEqual(widget.displayname, "new-italiandisplay")
        self.assertEqual(widget.jobname, "new-italianjob")
Beispiel #12
0
    def test_save_widget_creates_and_updates_ci_server_when_new_server_provided(
            self):
        request = self.factory.post('/pull/save_widget',
                                    HTTP_X_REQUESTED_WITH='XMLHttpRequest')
        request.user = self.user
        request.user.is_authenticated = Mock(return_value=True)

        newhostname = "http://reallynewciserver:8080"

        request.POST['new_ci_server'] = newhostname
        request.POST['widget_id'] = self.job1.pk

        response = views.save_widget(request)

        widget = models.UserCiJob.objects.get(pk=self.job1.pk)

        self.assertEqual(widget.ci_server.hostname, newhostname)