[extensions-web] Fix error reports, add tests
- From: Jasper St. Pierre <jstpierre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [extensions-web] Fix error reports, add tests
- Date: Thu, 1 Dec 2011 02:27:06 +0000 (UTC)
commit 8a4c210745999a4b6797ccac574f3344e4530ed0
Author: Jasper St. Pierre <jstpierre mecheye net>
Date: Wed Nov 30 21:26:48 2011 -0500
Fix error reports, add tests
sweettooth/errorreports/admin.py | 8 +---
sweettooth/errorreports/forms.py | 17 ++++---
.../templates/errorreports/report.html | 2 +-
sweettooth/errorreports/tests.py | 51 ++++++++++++++++++++
sweettooth/errorreports/views.py | 2 +-
sweettooth/urls.py | 2 +-
6 files changed, 65 insertions(+), 17 deletions(-)
---
diff --git a/sweettooth/errorreports/admin.py b/sweettooth/errorreports/admin.py
index 66035b6..ae03391 100644
--- a/sweettooth/errorreports/admin.py
+++ b/sweettooth/errorreports/admin.py
@@ -4,13 +4,7 @@ from django.contrib import admin
from errorreports.models import ErrorReport
class ErrorReportAdmin(admin.ModelAdmin):
- list_display = 'extension', 'version_num'
+ list_display = 'extension', 'user'
list_display_links = list_display
- def version_num(self, report):
- return report.version.version
-
- def extension(self, report):
- return report.version.extension
-
admin.site.register(ErrorReport, ErrorReportAdmin)
diff --git a/sweettooth/errorreports/forms.py b/sweettooth/errorreports/forms.py
index 83fbd05..cbf1b58 100644
--- a/sweettooth/errorreports/forms.py
+++ b/sweettooth/errorreports/forms.py
@@ -5,20 +5,23 @@ from errorreports.models import ErrorReport
class ErrorReportForm(forms.ModelForm):
- comments = forms.CharField(widget=forms.Textarea())
- can_contact = forms.BooleanField(label="I wish to provide the extension author with my email address")
+ comment = forms.CharField(widget=forms.Textarea())
+ can_contact = forms.BooleanField(label="I wish to provide the extension author with my email address", required=False)
class Meta:
model = ErrorReport
- fields = ('comments', 'can_contact')
+ fields = ('comment', 'can_contact')
- def clean_comments(self):
- return self.cleaned_data['comments'].strip()
+ def clean_comment(self):
+ return self.cleaned_data['comment'].strip()
- def save(self, request, version, commit=True):
+ def clean_can_contact(self):
+ return self.cleaned_data.get('can_contact', False)
+
+ def save(self, request, extension, commit=True):
report = super(ErrorReportForm, self).save(commit=False)
report.user = request.user
- report.version = version
+ report.extension = extension
if commit:
report.save()
return report
diff --git a/sweettooth/errorreports/templates/errorreports/report.html b/sweettooth/errorreports/templates/errorreports/report.html
index 24ea2a2..1f18b9d 100644
--- a/sweettooth/errorreports/templates/errorreports/report.html
+++ b/sweettooth/errorreports/templates/errorreports/report.html
@@ -8,7 +8,7 @@
{% csrf_token %}
<h3> Comments for the author </h3>
- {{ form.comments }}
+ {{ form.comment }}
<p>GNOME Shell Extensions will not provide the extension author with any contact information by default. If you wish to be contacted by the extension author, please check the box below.</p>
diff --git a/sweettooth/errorreports/tests.py b/sweettooth/errorreports/tests.py
new file mode 100644
index 0000000..75e463a
--- /dev/null
+++ b/sweettooth/errorreports/tests.py
@@ -0,0 +1,51 @@
+
+from django.core import mail
+from django.core.urlresolvers import reverse
+from django.contrib.auth.models import User
+from django.test import TestCase
+
+from extensions.models import Extension, ExtensionVersion, STATUS_ACTIVE
+from errorreports import models
+
+class SubmitErrorReportTestCase(TestCase):
+ def setUp(self):
+ super(SubmitErrorReportTestCase, self).setUp()
+ self.username = 'TestUser1'
+ self.email = 'non-existant non-existant tld'
+ self.password = 'a random password'
+ self.user = User.objects.create_user(self.username, self.email, self.password)
+
+ self.client.login(username=self.username, password=self.password)
+
+ self.extension = Extension.objects.create(creator=self.user,
+ name="Testing One",
+ uuid="testing-one aa",
+ description="AAA",
+ url="hey ya")
+ self.version = ExtensionVersion.objects.create(extension=self.extension,
+ source="",
+ status=STATUS_ACTIVE)
+ self.extension.save()
+ self.version.save()
+
+ def test_no_contact_information(self):
+ comment = "No contact information"
+
+ response = self.client.post(reverse('errorreports-report', kwargs=dict(pk=self.extension.pk)),
+ dict(can_contact=False,
+ comment=comment), follow=True)
+
+ self.assertEqual(len(mail.outbox), 1)
+ error_report = models.ErrorReport.objects.get(comment=comment)
+ self.assertEqual(error_report.can_contact, False)
+
+ def test_with_contact_information(self):
+ comment = "With contact information"
+
+ self.client.post(reverse('errorreports-report', kwargs=dict(pk=self.extension.pk)),
+ dict(can_contact=True,
+ comment=comment), follow=True)
+
+ self.assertEqual(len(mail.outbox), 1)
+ error_report = models.ErrorReport.objects.get(comment=comment)
+ self.assertEqual(error_report.can_contact, True)
diff --git a/sweettooth/errorreports/views.py b/sweettooth/errorreports/views.py
index 21c87b4..877e903 100644
--- a/sweettooth/errorreports/views.py
+++ b/sweettooth/errorreports/views.py
@@ -30,7 +30,7 @@ def report_error_view(request, extension):
messages.info(request, "Thank you for your error report!")
return redirect('extensions-detail',
- ext_pk=extension.pk,
+ pk=extension.pk,
slug=extension.slug)
else:
diff --git a/sweettooth/urls.py b/sweettooth/urls.py
index 98682c1..1f71946 100644
--- a/sweettooth/urls.py
+++ b/sweettooth/urls.py
@@ -1,7 +1,7 @@
import os.path
-from django.conf.urls.defaults import patterns, include, url
+from django.conf.urls.defaults import patterns, include, url, handler404, handler500
from django.conf import settings
from django.contrib import admin
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]