Esempio n. 1
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))
Esempio n. 2
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)
    )
Esempio n. 3
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,
        },
    )
Esempio n. 4
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)
    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)
    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)
Esempio n. 7
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),
    )