diff options
| author | Boulder Sprinters <boulder-sprinters@djangoproject.com> | 2007-05-08 17:46:05 +0000 |
|---|---|---|
| committer | Boulder Sprinters <boulder-sprinters@djangoproject.com> | 2007-05-08 17:46:05 +0000 |
| commit | 7f13278f8619b1155fa51276bb63afa9997610da (patch) | |
| tree | 2df768ea9c6c866926ee7c3c6831a4fe91dfa097 /tests | |
| parent | a275d3da8ed8cea8c2c92fc15151f43fb56b42ce (diff) | |
boulder-oracle-sprint: Merged to [5173]
git-svn-id: http://code.djangoproject.com/svn/django/branches/boulder-oracle-sprint@5174 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/modeltests/generic_relations/models.py | 7 | ||||
| -rw-r--r-- | tests/modeltests/test_client/models.py | 34 | ||||
| -rw-r--r-- | tests/modeltests/test_client/urls.py | 4 | ||||
| -rw-r--r-- | tests/modeltests/test_client/views.py | 26 | ||||
| -rw-r--r-- | tests/regressiontests/cache/tests.py | 5 | ||||
| -rw-r--r-- | tests/regressiontests/serializers_regress/models.py | 5 | ||||
| -rw-r--r-- | tests/regressiontests/templates/tests.py | 13 |
7 files changed, 87 insertions, 7 deletions
diff --git a/tests/modeltests/generic_relations/models.py b/tests/modeltests/generic_relations/models.py index 2b2f64165f..195f67db8f 100644 --- a/tests/modeltests/generic_relations/models.py +++ b/tests/modeltests/generic_relations/models.py @@ -11,6 +11,7 @@ from complete). from django.db import models from django.contrib.contenttypes.models import ContentType +from django.contrib.contenttypes import generic class TaggedItem(models.Model): """A tag on an item.""" @@ -18,7 +19,7 @@ class TaggedItem(models.Model): content_type = models.ForeignKey(ContentType) object_id = models.PositiveIntegerField() - content_object = models.GenericForeignKey() + content_object = generic.GenericForeignKey() class Meta: ordering = ["tag"] @@ -30,7 +31,7 @@ class Animal(models.Model): common_name = models.CharField(maxlength=150) latin_name = models.CharField(maxlength=150) - tags = models.GenericRelation(TaggedItem) + tags = generic.GenericRelation(TaggedItem) def __str__(self): return self.common_name @@ -39,7 +40,7 @@ class Vegetable(models.Model): name = models.CharField(maxlength=150) is_yucky = models.BooleanField(default=True) - tags = models.GenericRelation(TaggedItem) + tags = generic.GenericRelation(TaggedItem) def __str__(self): return self.name diff --git a/tests/modeltests/test_client/models.py b/tests/modeltests/test_client/models.py index cd8dbe37d2..34242ee0d8 100644 --- a/tests/modeltests/test_client/models.py +++ b/tests/modeltests/test_client/models.py @@ -20,6 +20,7 @@ rather than the HTML rendered to the end-user. """ from django.test import Client, TestCase +from django.core import mail class ClientTest(TestCase): fixtures = ['testdata.json'] @@ -232,3 +233,36 @@ class ClientTest(TestCase): self.fail('Should raise an error') except KeyError: pass + + def test_mail_sending(self): + "Test that mail is redirected to a dummy outbox during test setup" + + response = self.client.get('/test_client/mail_sending_view/') + self.assertEqual(response.status_code, 200) + + self.assertEqual(len(mail.outbox), 1) + self.assertEqual(mail.outbox[0].subject, 'Test message') + self.assertEqual(mail.outbox[0].body, 'This is a test email') + self.assertEqual(mail.outbox[0].from_email, 'from@example.com') + self.assertEqual(mail.outbox[0].to[0], 'first@example.com') + self.assertEqual(mail.outbox[0].to[1], 'second@example.com') + + def test_mass_mail_sending(self): + "Test that mass mail is redirected to a dummy outbox during test setup" + + response = self.client.get('/test_client/mass_mail_sending_view/') + self.assertEqual(response.status_code, 200) + + self.assertEqual(len(mail.outbox), 2) + self.assertEqual(mail.outbox[0].subject, 'First Test message') + self.assertEqual(mail.outbox[0].body, 'This is the first test email') + self.assertEqual(mail.outbox[0].from_email, 'from@example.com') + self.assertEqual(mail.outbox[0].to[0], 'first@example.com') + self.assertEqual(mail.outbox[0].to[1], 'second@example.com') + + self.assertEqual(mail.outbox[1].subject, 'Second Test message') + self.assertEqual(mail.outbox[1].body, 'This is the second test email') + self.assertEqual(mail.outbox[1].from_email, 'from@example.com') + self.assertEqual(mail.outbox[1].to[0], 'second@example.com') + self.assertEqual(mail.outbox[1].to[1], 'third@example.com') +
\ No newline at end of file diff --git a/tests/modeltests/test_client/urls.py b/tests/modeltests/test_client/urls.py index f63c486d01..52fc8fe692 100644 --- a/tests/modeltests/test_client/urls.py +++ b/tests/modeltests/test_client/urls.py @@ -11,5 +11,7 @@ urlpatterns = patterns('', (r'^form_view_with_template/$', views.form_view_with_template), (r'^login_protected_view/$', views.login_protected_view), (r'^session_view/$', views.session_view), - (r'^broken_view/$', views.broken_view) + (r'^broken_view/$', views.broken_view), + (r'^mail_sending_view/$', views.mail_sending_view), + (r'^mass_mail_sending_view/$', views.mass_mail_sending_view) ) diff --git a/tests/modeltests/test_client/views.py b/tests/modeltests/test_client/views.py index 3b7a57f4d0..18d6a2dcd9 100644 --- a/tests/modeltests/test_client/views.py +++ b/tests/modeltests/test_client/views.py @@ -1,4 +1,5 @@ from xml.dom.minidom import parseString +from django.core.mail import EmailMessage, SMTPConnection from django.template import Context, Template from django.http import HttpResponse, HttpResponseRedirect from django.contrib.auth.decorators import login_required @@ -124,3 +125,28 @@ def session_view(request): def broken_view(request): """A view which just raises an exception, simulating a broken view.""" raise KeyError("Oops! Looks like you wrote some bad code.") + +def mail_sending_view(request): + EmailMessage( + "Test message", + "This is a test email", + "from@example.com", + ['first@example.com', 'second@example.com']).send() + return HttpResponse("Mail sent") + +def mass_mail_sending_view(request): + m1 = EmailMessage( + 'First Test message', + 'This is the first test email', + 'from@example.com', + ['first@example.com', 'second@example.com']) + m2 = EmailMessage( + 'Second Test message', + 'This is the second test email', + 'from@example.com', + ['second@example.com', 'third@example.com']) + + c = SMTPConnection() + c.send_messages([m1,m2]) + + return HttpResponse("Mail sent") diff --git a/tests/regressiontests/cache/tests.py b/tests/regressiontests/cache/tests.py index cf58ab321a..9dc7161c03 100644 --- a/tests/regressiontests/cache/tests.py +++ b/tests/regressiontests/cache/tests.py @@ -46,6 +46,11 @@ class Cache(unittest.TestCase): self.assertEqual(cache.has_key("hello"), True) self.assertEqual(cache.has_key("goodbye"), False) + def test_in(self): + cache.set("hello", "goodbye") + self.assertEqual("hello" in cache, True) + self.assertEqual("goodbye" in cache, False) + def test_data_types(self): # test data types stuff = { diff --git a/tests/regressiontests/serializers_regress/models.py b/tests/regressiontests/serializers_regress/models.py index d3415ac1b9..c287b6e0d6 100644 --- a/tests/regressiontests/serializers_regress/models.py +++ b/tests/regressiontests/serializers_regress/models.py @@ -6,6 +6,7 @@ This class sets up a model for each model field type """ from django.db import models +from django.contrib.contenttypes import generic from django.contrib.contenttypes.models import ContentType # The following classes are for testing basic data @@ -80,7 +81,7 @@ class Tag(models.Model): content_type = models.ForeignKey(ContentType) object_id = models.PositiveIntegerField() - content_object = models.GenericForeignKey() + content_object = generic.GenericForeignKey() class Meta: ordering = ["data"] @@ -88,7 +89,7 @@ class Tag(models.Model): class GenericData(models.Model): data = models.CharField(maxlength=30) - tags = models.GenericRelation(Tag) + tags = generic.GenericRelation(Tag) # The following test classes are all for validation # of related objects; in particular, forward, backward, diff --git a/tests/regressiontests/templates/tests.py b/tests/regressiontests/templates/tests.py index 9be8f022f6..a5ed2dbf56 100644 --- a/tests/regressiontests/templates/tests.py +++ b/tests/regressiontests/templates/tests.py @@ -586,6 +586,8 @@ class Templates(unittest.TestCase): 'invalidstr03': ('{% for v in var %}({{ v }}){% endfor %}', {}, ''), 'invalidstr04': ('{% if var %}Yes{% else %}No{% endif %}', {}, 'No'), 'invalidstr04': ('{% if var|default:"Foo" %}Yes{% else %}No{% endif %}', {}, 'Yes'), + 'invalidstr05': ('{{ var }}', {}, ('', 'INVALID %s', 'var')), + 'invalidstr06': ('{{ var.prop }}', {'var': {}}, ('', 'INVALID %s', 'var.prop')), ### MULTILINE ############################################################# @@ -737,6 +739,7 @@ class Templates(unittest.TestCase): # Set TEMPLATE_STRING_IF_INVALID to a known string old_invalid = settings.TEMPLATE_STRING_IF_INVALID + expected_invalid_str = 'INVALID' for name, vals in tests: install() @@ -744,6 +747,10 @@ class Templates(unittest.TestCase): if isinstance(vals[2], tuple): normal_string_result = vals[2][0] invalid_string_result = vals[2][1] + if '%s' in invalid_string_result: + expected_invalid_str = 'INVALID %s' + invalid_string_result = invalid_string_result % vals[2][2] + template.invalid_var_format_string = True else: normal_string_result = vals[2] invalid_string_result = vals[2] @@ -754,7 +761,7 @@ class Templates(unittest.TestCase): activate('en-us') for invalid_str, result in [('', normal_string_result), - ('INVALID', invalid_string_result)]: + (expected_invalid_str, invalid_string_result)]: settings.TEMPLATE_STRING_IF_INVALID = invalid_str try: output = loader.get_template(name).render(template.Context(vals[1])) @@ -768,6 +775,10 @@ class Templates(unittest.TestCase): if 'LANGUAGE_CODE' in vals[1]: deactivate() + if template.invalid_var_format_string: + expected_invalid_str = 'INVALID' + template.invalid_var_format_string = False + loader.template_source_loaders = old_template_loaders deactivate() settings.TEMPLATE_DEBUG = old_td |
