| 1627 | class AdminResponseChangeTest(TestCase): |
| 1628 | fixtures = ['admin-views-users.xml'] |
| 1629 | |
| 1630 | def setUp(self): |
| 1631 | self.client.login(username='super', password='secret') |
| 1632 | self.data = {'title':"I Could Go Anywhere", 'content':"Versatile", 'date':datetime.datetime.now()} |
| 1633 | article = Article.objects.create(**self.data) |
| 1634 | self.pk = article.id |
| 1635 | |
| 1636 | def test_response_add(self): |
| 1637 | """Add test for #12241: ModelAdmin.response_add should preserve the request |
| 1638 | query string after the redirection if the "save and continue" button |
| 1639 | is used within the admin.""" |
| 1640 | |
| 1641 | self.data['_continue'] = True |
| 1642 | self.data['date_0'] = u"2008-03-18" |
| 1643 | self.data['date_1'] = u"11:54:58" |
| 1644 | response = self.client.post('/test_admin/admin/admin_views/article/%d/?test=1' % self.pk, self.data) |
| 1645 | self.assertEqual(response.status_code, 302) |
| 1646 | location = urlparse.urlparse(response['Location']) |
| 1647 | parsed_query_string = urlparse.parse_qs(location.query) |
| 1648 | self.assertTrue('test' in parsed_query_string.keys()) |
| 1649 | |
| 1650 | response = self.client.post('/test_admin/admin/admin_views/article/add/?test=1', self.data) |
| 1651 | self.assertEqual(response.status_code, 302) |
| 1652 | location = urlparse.urlparse(response['Location']) |
| 1653 | parsed_query_string = urlparse.parse_qs(location.query) |
| 1654 | self.assertTrue('test' in parsed_query_string.keys()) |
| 1655 | |
| 1656 | # test the popup redirection |
| 1657 | self.data['_popup'] = 1 |
| 1658 | response = self.client.post('/test_admin/admin/admin_views/article/add/', self.data) |
| 1659 | self.assertEqual(response.status_code, 302) |
| 1660 | location = urlparse.urlparse(response['Location']) |
| 1661 | parsed_query_string = urlparse.parse_qs(location.query) |
| 1662 | self.assertTrue('_popup' in parsed_query_string.keys()) |
| 1663 | |
| 1664 | # test the popup redirection and another GET parameter |
| 1665 | response = self.client.post('/test_admin/admin/admin_views/article/add/?test=1', self.data) |
| 1666 | self.assertEqual(response.status_code, 302) |
| 1667 | location = urlparse.urlparse(response['Location']) |
| 1668 | parsed_query_string = urlparse.parse_qs(location.query) |
| 1669 | self.assertTrue('test' in parsed_query_string.keys()) |
| 1670 | self.assertTrue('_popup' in parsed_query_string.keys()) |
| 1671 | |
| 1672 | # without anything |
| 1673 | self.data['date_0'] = u"2008-03-18" |
| 1674 | self.data['date_1'] = u"11:54:58" |
| 1675 | del self.data['_popup'] |
| 1676 | response = self.client.post('/test_admin/admin/admin_views/article/add/', self.data) |
| 1677 | self.assertEqual(response.status_code, 302) |
| 1678 | location = urlparse.urlparse(response['Location']) |
| 1679 | parsed_query_string = urlparse.parse_qs(location.query) |
| 1680 | self.assertFalse('test' in parsed_query_string.keys()) |
| 1681 | self.assertFalse('_popup' in parsed_query_string.keys()) |
| 1682 | |
| 1683 | def test_response_change(self): |
| 1684 | """Change test for issue #12241. ModelAdmin.response_change should |
| 1685 | preserve the query string.""" |
| 1686 | |
| 1687 | self.data['date_0'] = u"2008-03-18" |
| 1688 | self.data['date_1'] = u"11:54:58" |
| 1689 | self.data['_continue'] = True |
| 1690 | |
| 1691 | response = self.client.post('/test_admin/admin/admin_views/article/%d/?test=1' % self.pk, self.data) |
| 1692 | self.assertEqual(response.status_code, 302) |
| 1693 | location = urlparse.urlparse(response['Location']) |
| 1694 | parsed_query_string = urlparse.parse_qs(location.query) |
| 1695 | self.assertTrue('test' in parsed_query_string.keys()) |
| 1696 | self.assertFalse('_popup' in parsed_query_string.keys()) |
| 1697 | |
| 1698 | response = self.client.post('/test_admin/admin/admin_views/article/%d/' % self.pk, self.data) |
| 1699 | self.assertEqual(response.status_code, 302) |
| 1700 | location = urlparse.urlparse(response['Location']) |
| 1701 | parsed_query_string = urlparse.parse_qs(location.query) |
| 1702 | self.assertFalse('test' in parsed_query_string.keys()) |
| 1703 | self.assertFalse('_popup' in parsed_query_string.keys()) |
| 1704 | |
| 1705 | |
| 1706 | |