diff options
Diffstat (limited to 'tests/modeltests')
| -rw-r--r-- | tests/modeltests/basic/models.py | 13 | ||||
| -rw-r--r-- | tests/modeltests/fixtures/models.py | 18 | ||||
| -rw-r--r-- | tests/modeltests/test_client/models.py | 16 |
3 files changed, 38 insertions, 9 deletions
diff --git a/tests/modeltests/basic/models.py b/tests/modeltests/basic/models.py index d2220320a0..0a09579761 100644 --- a/tests/modeltests/basic/models.py +++ b/tests/modeltests/basic/models.py @@ -247,6 +247,19 @@ datetime.datetime(2005, 7, 28, 0, 0) >>> (s1 | s2 | s3)[::2] [<Article: Area woman programs in Python>, <Article: Third article>] +# Slicing works with longs. +>>> Article.objects.all()[0L] +<Article: Area woman programs in Python> +>>> Article.objects.all()[1L:3L] +[<Article: Second article>, <Article: Third article>] +>>> s3 = Article.objects.filter(id__exact=3) +>>> (s1 | s2 | s3)[::2L] +[<Article: Area woman programs in Python>, <Article: Third article>] + +# And can be mixed with ints. +>>> Article.objects.all()[1:3L] +[<Article: Second article>, <Article: Third article>] + # Slices (without step) are lazy: >>> Article.objects.all()[0:5].filter() [<Article: Area woman programs in Python>, <Article: Second article>, <Article: Third article>, <Article: Article 6>, <Article: Default headline>] diff --git a/tests/modeltests/fixtures/models.py b/tests/modeltests/fixtures/models.py index b59dc82884..b59c388bbd 100644 --- a/tests/modeltests/fixtures/models.py +++ b/tests/modeltests/fixtures/models.py @@ -26,54 +26,54 @@ __test__ = {'API_TESTS': """ # Reset the database representation of this app. # This will return the database to a clean initial state. ->>> management.flush(verbosity=0, interactive=False) +>>> management.call_command('flush', verbosity=0, interactive=False) # Syncdb introduces 1 initial data object from initial_data.json. >>> Article.objects.all() [<Article: Python program becomes self aware>] # Load fixture 1. Single JSON file, with two objects. ->>> management.load_data(['fixture1.json'], verbosity=0) +>>> management.call_command('loaddata', 'fixture1.json', verbosity=0) >>> Article.objects.all() [<Article: Time to reform copyright>, <Article: Poker has no place on ESPN>, <Article: Python program becomes self aware>] # Load fixture 2. JSON file imported by default. Overwrites some existing objects ->>> management.load_data(['fixture2.json'], verbosity=0) +>>> management.call_command('loaddata', 'fixture2.json', verbosity=0) >>> Article.objects.all() [<Article: Django conquers world!>, <Article: Copyright is fine the way it is>, <Article: Poker has no place on ESPN>, <Article: Python program becomes self aware>] # Load fixture 3, XML format. ->>> management.load_data(['fixture3.xml'], verbosity=0) +>>> management.call_command('loaddata', 'fixture3.xml', verbosity=0) >>> Article.objects.all() [<Article: XML identified as leading cause of cancer>, <Article: Django conquers world!>, <Article: Copyright is fine the way it is>, <Article: Poker on TV is great!>, <Article: Python program becomes self aware>] # Load a fixture that doesn't exist ->>> management.load_data(['unknown.json'], verbosity=0) +>>> management.call_command('loaddata', 'unknown.json', verbosity=0) # object list is unaffected >>> Article.objects.all() [<Article: XML identified as leading cause of cancer>, <Article: Django conquers world!>, <Article: Copyright is fine the way it is>, <Article: Poker on TV is great!>, <Article: Python program becomes self aware>] # Reset the database representation of this app. This will delete all data. ->>> management.flush(verbosity=0, interactive=False) +>>> management.call_command('flush', verbosity=0, interactive=False) >>> Article.objects.all() [<Article: Python program becomes self aware>] # Load fixture 1 again, using format discovery ->>> management.load_data(['fixture1'], verbosity=0) +>>> management.call_command('loaddata', 'fixture1', verbosity=0) >>> Article.objects.all() [<Article: Time to reform copyright>, <Article: Poker has no place on ESPN>, <Article: Python program becomes self aware>] # Try to load fixture 2 using format discovery; this will fail # because there are two fixture2's in the fixtures directory ->>> management.load_data(['fixture2'], verbosity=0) # doctest: +ELLIPSIS +>>> management.call_command('loaddata', 'fixture2', verbosity=0) # doctest: +ELLIPSIS Multiple fixtures named 'fixture2' in '...fixtures'. Aborting. >>> Article.objects.all() [<Article: Time to reform copyright>, <Article: Poker has no place on ESPN>, <Article: Python program becomes self aware>] # Dump the current contents of the database as a JSON fixture ->>> print management.dump_data(['fixtures'], format='json') +>>> management.call_command('dumpdata', 'fixtures', format='json') [{"pk": "3", "model": "fixtures.article", "fields": {"headline": "Time to reform copyright", "pub_date": "2006-06-16 13:00:00"}}, {"pk": "2", "model": "fixtures.article", "fields": {"headline": "Poker has no place on ESPN", "pub_date": "2006-06-16 12:00:00"}}, {"pk": "1", "model": "fixtures.article", "fields": {"headline": "Python program becomes self aware", "pub_date": "2006-06-16 11:00:00"}}] """} diff --git a/tests/modeltests/test_client/models.py b/tests/modeltests/test_client/models.py index 951a41d61c..98b6a808a1 100644 --- a/tests/modeltests/test_client/models.py +++ b/tests/modeltests/test_client/models.py @@ -246,6 +246,22 @@ class ClientTest(TestCase): login = self.client.login(username='inactive', password='password') self.failIf(login) + def test_logout(self): + # Log in + self.client.login(username='testclient', password='password') + + # Request a page that requires a login + response = self.client.get('/test_client/login_protected_view/') + self.assertEqual(response.status_code, 200) + self.assertEqual(response.context['user'].username, 'testclient') + + # Log out + self.client.logout() + + # Request a page that requires a login + response = self.client.get('/test_client/login_protected_view/') + self.assertRedirects(response, '/accounts/login/') + def test_session_modifying_view(self): "Request a page that modifies the session" # Session value isn't set initially |
