~ubuntu-branches/ubuntu/quantal/python-django/quantal-security

« back to all changes in this revision

Viewing changes to tests/regressiontests/multiple_database/tests.py

  • Committer: Bazaar Package Importer
  • Author(s): Jamie Strandboge
  • Date: 2010-10-12 11:34:35 UTC
  • mfrom: (4.4.9 sid)
  • mto: This revision was merged to the branch mainline in revision 30.
  • Revision ID: james.westby@ubuntu.com-20101012113435-5rk3p18nyanuhj6g
* SECURITY UPDATE: XSS in CSRF protections. New upstream release
  - CVE-2010-3082
* debian/patches/01_disable_url_verify_regression_tests.diff:
  - updated to disable another test that fails without internet connection
  - patch based on work by Kai Kasurinen and Krzysztof Klimonda
* debian/control: don't Build-Depends on locales-all, which doesn't exist
  in maverick

Show diffs side-by-side

added added

removed removed

Lines of Context:
883
883
        self.assertRaises(ValueError, str, qs.query)
884
884
 
885
885
        # Evaluating the query shouldn't work, either
886
 
        self.assertRaises(ValueError, list, qs)
 
886
        try:
 
887
            for obj in qs:
 
888
                pass
 
889
            self.fail('Iterating over query should raise ValueError')
 
890
        except ValueError:
 
891
            pass
 
892
 
887
893
 
888
894
class TestRouter(object):
889
895
    # A test router. The behaviour is vaguely master/slave, but the
1491
1497
        self.old_routers = router.routers
1492
1498
        router.routers = [AuthRouter()]
1493
1499
 
1494
 
        # Redirect stdout to a buffer so we can test
1495
 
        # the output of a management command
1496
 
        self.old_stdout = sys.stdout
1497
 
        self.stdout = StringIO()
1498
 
        sys.stdout = self.stdout
1499
 
 
1500
1500
    def tearDown(self):
1501
1501
        # Restore the 'other' database as an independent database
1502
1502
        router.routers = self.old_routers
1503
1503
 
1504
 
        # Restore stdout
1505
 
        sys.stdout = self.old_stdout
1506
 
 
1507
1504
    def test_auth_manager(self):
1508
1505
        "The methods on the auth manager obey database hints"
1509
1506
        # Create one user using default allocation policy
1539
1536
 
1540
1537
        # Check that dumping the default database doesn't try to include auth
1541
1538
        # because allow_syncdb prohibits auth on default
1542
 
        self.stdout.flush()
1543
 
        management.call_command('dumpdata', 'auth', format='json', database='default')
1544
 
        self.assertEquals(self.stdout.getvalue(), '[]\n')
 
1539
        new_io = StringIO()
 
1540
        management.call_command('dumpdata', 'auth', format='json', database='default', stdout=new_io)
 
1541
        command_output = new_io.getvalue().strip()
 
1542
        self.assertEqual(command_output, '[]')
1545
1543
 
1546
1544
        # Check that dumping the other database does include auth
1547
 
        self.stdout.flush()
1548
 
        management.call_command('dumpdata', 'auth', format='json', database='other')
1549
 
        self.assertTrue('alice@example.com' in self.stdout.getvalue())
 
1545
        new_io = StringIO()
 
1546
        management.call_command('dumpdata', 'auth', format='json', database='other', stdout=new_io)
 
1547
        command_output = new_io.getvalue().strip()
 
1548
        self.assertTrue('"email": "alice@example.com",' in command_output)
1550
1549
 
1551
1550
class UserProfileTestCase(TestCase):
1552
1551
    def setUp(self):
1570
1569
        self.assertEquals(alice.get_profile().flavor, 'chocolate')
1571
1570
        self.assertEquals(bob.get_profile().flavor, 'crunchy frog')
1572
1571
 
 
1572
class AntiPetRouter(object):
 
1573
    # A router that only expresses an opinion on syncdb,
 
1574
    # passing pets to the 'other' database
 
1575
 
 
1576
    def allow_syncdb(self, db, model):
 
1577
        "Make sure the auth app only appears on the 'other' db"
 
1578
        if db == 'other':
 
1579
            return model._meta.object_name == 'Pet'
 
1580
        else:
 
1581
            return model._meta.object_name != 'Pet'
 
1582
        return None
1573
1583
 
1574
1584
class FixtureTestCase(TestCase):
1575
1585
    multi_db = True
1576
1586
    fixtures = ['multidb-common', 'multidb']
1577
1587
 
 
1588
    def setUp(self):
 
1589
        # Install the anti-pet router
 
1590
        self.old_routers = router.routers
 
1591
        router.routers = [AntiPetRouter()]
 
1592
 
 
1593
    def tearDown(self):
 
1594
        # Restore the 'other' database as an independent database
 
1595
        router.routers = self.old_routers
 
1596
 
1578
1597
    def test_fixture_loading(self):
1579
1598
        "Multi-db fixtures are loaded correctly"
1580
1599
        # Check that "Pro Django" exists on the default database, but not on other database
1612
1631
        except Book.DoesNotExist:
1613
1632
            self.fail('"The Definitive Guide to Django" should exist on both databases')
1614
1633
 
 
1634
    def test_pseudo_empty_fixtures(self):
 
1635
        "A fixture can contain entries, but lead to nothing in the database; this shouldn't raise an error (ref #14068)"
 
1636
        new_io = StringIO()
 
1637
        management.call_command('loaddata', 'pets', stdout=new_io, stderr=new_io)
 
1638
        command_output = new_io.getvalue().strip()
 
1639
        # No objects will actually be loaded
 
1640
        self.assertTrue("Installed 0 object(s) (of 2) from 1 fixture(s)" in command_output)
 
1641
 
1615
1642
class PickleQuerySetTestCase(TestCase):
1616
1643
    multi_db = True
1617
1644