def test_webhook_form_url_length(self):
        form = WebHookForm(
            {
                'url':
                'https://foobar.com',
                'payload':
                '{}',
                'events':
                [WebHookEvent.objects.get(name=WebHookEvent.BUILD_FAILED).id],
            },
            project=self.project,
        )
        self.assertTrue(form.is_valid())

        form = WebHookForm(
            {
                'url':
                'foo' * 500,
                'payload':
                '{}',
                'events':
                [WebHookEvent.objects.get(name=WebHookEvent.BUILD_FAILED).id],
            },
            project=self.project,
        )
        self.assertFalse(form.is_valid())
        self.assertEqual(
            form.errors,
            {
                'url': [
                    'Enter a valid URL.',
                    'Ensure this value has at most 600 characters (it has 1507).',
                ],
            },
        )
Example #2
0
    def test_webhook_form_url_length(self):
        form = WebHookForm(
            {
                'url': 'https://foobar.com',
            },
            project=self.project,
        )
        self.assertTrue(form.is_valid())

        form = WebHookForm(
            {
                'url': 'foo' * 500,
            },
            project=self.project,
        )
        self.assertFalse(form.is_valid())
        self.assertEqual(
            form.errors,
            {
                'url':
                   [
                       'Enter a valid URL.',
                       'Ensure this value has at most 600 characters (it has 1507).',
                   ],
                },
        )
Example #3
0
    def test_webhookform(self):
        self.assertEqual(self.project.webhook_notifications.all().count(), 0)

        data = {
            'url':
            'http://www.example.com/',
            'payload':
            '{}',
            'events':
            [WebHookEvent.objects.get(name=WebHookEvent.BUILD_FAILED).id],
        }
        form = WebHookForm(data=data, project=self.project)
        self.assertTrue(form.is_valid())
        form.save()
        self.assertEqual(self.project.webhook_notifications.all().count(), 1)

        data = {
            'url':
            'https://www.example.com/',
            'payload':
            '{}',
            'events':
            [WebHookEvent.objects.get(name=WebHookEvent.BUILD_PASSED).id],
        }
        form = WebHookForm(data=data, project=self.project)
        self.assertTrue(form.is_valid())
        form.save()
        self.assertEqual(self.project.webhook_notifications.all().count(), 2)
Example #4
0
    def test_wrong_inputs_in_webhookform(self):
        self.assertEqual(self.project.webhook_notifications.all().count(), 0)

        data = {
            'url':
            '',
            'payload':
            '{}',
            'events':
            [WebHookEvent.objects.get(name=WebHookEvent.BUILD_FAILED).id],
        }
        form = WebHookForm(data=data, project=self.project)
        self.assertFalse(form.is_valid())
        self.assertDictEqual(form.errors, {'url': ['This field is required.']})
        self.assertEqual(self.project.webhook_notifications.all().count(), 0)

        data = {
            'url':
            'wrong-url',
            'payload':
            '{}',
            'events':
            [WebHookEvent.objects.get(name=WebHookEvent.BUILD_FAILED).id],
        }
        form = WebHookForm(data=data, project=self.project)
        self.assertFalse(form.is_valid())
        self.assertDictEqual(form.errors, {'url': ['Enter a valid URL.']})
        self.assertEqual(self.project.webhook_notifications.all().count(), 0)

        data = {
            'url':
            'https://example.com/webhook/',
            'payload':
            '{wrong json object}',
            'events':
            [WebHookEvent.objects.get(name=WebHookEvent.BUILD_FAILED).id],
        }
        form = WebHookForm(data=data, project=self.project)
        self.assertFalse(form.is_valid())
        self.assertDictEqual(
            form.errors,
            {'payload': ['The payload must be a valid JSON object.']})
        self.assertEqual(self.project.webhook_notifications.all().count(), 0)

        data = {
            'url': 'https://example.com/webhook/',
            'payload': '{}',
            'events': [],
        }
        form = WebHookForm(data=data, project=self.project)
        self.assertFalse(form.is_valid())
        self.assertDictEqual(form.errors,
                             {'events': ['This field is required.']})
        self.assertEqual(self.project.webhook_notifications.all().count(), 0)
    def test_wrong_inputs_in_webhookform(self):
        self.assertEqual(self.project.webhook_notifications.all().count(), 0)

        data = {'url': ''}
        form = WebHookForm(data=data, project=self.project)
        self.assertFalse(form.is_valid())
        self.assertDictEqual(form.errors, {'url': ['This field is required.']})
        self.assertEqual(self.project.webhook_notifications.all().count(), 0)

        data = {'url': 'wrong-url'}
        form = WebHookForm(data=data, project=self.project)
        self.assertFalse(form.is_valid())
        self.assertDictEqual(form.errors, {'url': ['Enter a valid URL.']})
        self.assertEqual(self.project.webhook_notifications.all().count(), 0)
Example #6
0
    def test_webhookform(self):
        self.assertEqual(self.project.webhook_notifications.all().count(), 0)

        data = {'url': 'http://www.example.com/'}
        form = WebHookForm(data=data, project=self.project)
        self.assertTrue(form.is_valid())
        form.save()
        self.assertEqual(self.project.webhook_notifications.all().count(), 1)

        data = {'url': 'https://www.example.com/'}
        form = WebHookForm(data=data, project=self.project)
        self.assertTrue(form.is_valid())
        form.save()
        self.assertEqual(self.project.webhook_notifications.all().count(), 2)
Example #7
0
def project_notifications(request, project_slug):
    """Project notification view and form view"""
    project = get_object_or_404(Project.objects.for_admin_user(request.user),
                                slug=project_slug)

    email_form = EmailHookForm(data=request.POST or None, project=project)
    webhook_form = WebHookForm(data=request.POST or None, project=project)

    if request.method == 'POST':
        if email_form.is_valid():
            email_form.save()
        if webhook_form.is_valid():
            webhook_form.save()
        project_dashboard = reverse('projects_notifications',
                                    args=[project.slug])
        return HttpResponseRedirect(project_dashboard)

    emails = project.emailhook_notifications.all()
    urls = project.webhook_notifications.all()

    return render_to_response('projects/project_notifications.html', {
        'email_form': email_form,
        'webhook_form': webhook_form,
        'project': project,
        'emails': emails,
        'urls': urls,
    },
                              context_instance=RequestContext(request))
Example #8
0
def project_notifications(request, project_slug):
    """Project notification view and form view"""
    project = get_object_or_404(Project.objects.for_admin_user(request.user),
                                slug=project_slug)

    email_form = EmailHookForm(data=request.POST or None, project=project)
    webhook_form = WebHookForm(data=request.POST or None, project=project)

    if request.method == 'POST':
        if email_form.is_valid():
            email_form.save()
        if webhook_form.is_valid():
            webhook_form.save()
        project_dashboard = reverse('projects_notifications',
                                    args=[project.slug])
        return HttpResponseRedirect(project_dashboard)

    emails = project.emailhook_notifications.all()
    urls = project.webhook_notifications.all()

    return render_to_response(
        'projects/project_notifications.html',
        {
            'email_form': email_form,
            'webhook_form': webhook_form,
            'project': project,
            'emails': emails,
            'urls': urls,
        },
        context_instance=RequestContext(request)
    )
Example #9
0
def project_notifications(request, project_slug):
    """Project notification view and form view."""
    project = get_object_or_404(
        Project.objects.for_admin_user(request.user),
        slug=project_slug,
    )

    email_form = EmailHookForm(data=None, project=project)
    webhook_form = WebHookForm(data=None, project=project)

    if request.method == 'POST':
        if 'email' in request.POST.keys():
            email_form = EmailHookForm(data=request.POST, project=project)
            if email_form.is_valid():
                email_form.save()
        elif 'url' in request.POST.keys():
            webhook_form = WebHookForm(data=request.POST, project=project)
            if webhook_form.is_valid():
                webhook_form.save()

    emails = project.emailhook_notifications.all()
    urls = project.webhook_notifications.all()

    return render(
        request,
        'projects/project_notifications.html',
        {
            'email_form': email_form,
            'webhook_form': webhook_form,
            'project': project,
            'emails': emails,
            'urls': urls,
        },
    )
    def test_wrong_inputs_in_webhookform(self):
        self.assertEqual(self.project.webhook_notifications.all().count(), 0)

        data = {
            'url': ''
        }
        form = WebHookForm(data=data, project=self.project)
        self.assertFalse(form.is_valid())
        self.assertDictEqual(form.errors, {'url': ['This field is required.']})
        self.assertEqual(self.project.webhook_notifications.all().count(), 0)

        data = {
            'url': 'wrong-url'
        }
        form = WebHookForm(data=data, project=self.project)
        self.assertFalse(form.is_valid())
        self.assertDictEqual(form.errors, {'url': ['Enter a valid URL.']})
        self.assertEqual(self.project.webhook_notifications.all().count(), 0)
    def test_webhookform(self):
        self.assertEqual(self.project.webhook_notifications.all().count(), 0)

        data = {
            'url': 'http://www.example.com/'
        }
        form = WebHookForm(data=data, project=self.project)
        self.assertTrue(form.is_valid())
        form.save()
        self.assertEqual(self.project.webhook_notifications.all().count(), 1)
Example #12
0
def project_notifications(request, project_slug):
    project = get_object_or_404(Project.objects.for_admin_user(request.user), slug=project_slug)

    email_form = EmailHookForm(data=request.POST or None, project=project)
    webhook_form = WebHookForm(data=request.POST or None, project=project)

    if request.method == "POST":
        if email_form.is_valid():
            email_form.save()
        if webhook_form.is_valid():
            webhook_form.save()
        project_dashboard = reverse("projects_notifications", args=[project.slug])
        return HttpResponseRedirect(project_dashboard)

    emails = project.emailhook_notifications.all()
    urls = project.webhook_notifications.all()

    return render_to_response(
        "projects/project_notifications.html",
        {"email_form": email_form, "webhook_form": webhook_form, "project": project, "emails": emails, "urls": urls},
        context_instance=RequestContext(request),
    )