Ticket #17333: 17333-wip-regression-tests.diff

File 17333-wip-regression-tests.diff, 3.7 KB (added by Ramiro Morales, 13 years ago)
  • tests/regressiontests/admin_views/admin.py

    diff --git a/tests/regressiontests/admin_views/admin.py b/tests/regressiontests/admin_views/admin.py
    a b  
    2424    CoverLetter, Story, OtherStory, Book, Promo, ChapterXtra1, Pizza, Topping,
    2525    Album, Question, Answer, ComplexSortedPerson, PrePopulatedPostLargeSlug,
    2626    AdminOrderedField, AdminOrderedModelMethod, AdminOrderedAdminMethod,
    27     AdminOrderedCallable)
     27    AdminOrderedCallable, Report)
    2828
    2929
    3030def callable_year(dt_value):
     
    499499    ordering = ('order',)
    500500    list_display = ('stuff', admin_ordered_callable)
    501501
     502class ReportAdmin(admin.ModelAdmin):
     503    def has_add_permission(self, request):
     504        return False
    502505
    503506site = admin.AdminSite(name="admin")
    504507site.register(Article, ArticleAdmin)
     
    543546site.register(CoverLetter, CoverLetterAdmin)
    544547site.register(Story, StoryAdmin)
    545548site.register(OtherStory, OtherStoryAdmin)
     549site.register(Report, ReportAdmin)
    546550
    547551# We intentionally register Promo and ChapterXtra1 but not Chapter nor ChapterXtra2.
    548552# That way we cover all four cases:
  • tests/regressiontests/admin_views/models.py

    diff --git a/tests/regressiontests/admin_views/models.py b/tests/regressiontests/admin_views/models.py
    a b  
    566566class AdminOrderedCallable(models.Model):
    567567    order = models.IntegerField()
    568568    stuff = models.CharField(max_length=200)
     569
     570class Report(models.Model):
     571    title = models.CharField(max_length=100)
     572
     573    def __unicode__(self):
     574        return self.title
  • tests/regressiontests/admin_views/tests.py

    diff --git a/tests/regressiontests/admin_views/tests.py b/tests/regressiontests/admin_views/tests.py
    a b  
    3838    Book, Promo, WorkHour, Employee, Question, Answer, Inquisition, Actor,
    3939    FoodDelivery, RowLevelChangePermissionModel, Paper, CoverLetter, Story,
    4040    OtherStory, ComplexSortedPerson, Parent, Child, AdminOrderedField,
    41     AdminOrderedModelMethod, AdminOrderedAdminMethod, AdminOrderedCallable)
     41    AdminOrderedModelMethod, AdminOrderedAdminMethod, AdminOrderedCallable,
     42    Report)
    4243
    4344
    4445ERROR_MESSAGE = "Please enter the correct username and password \
     
    10901091        self.assertContains(response, 'id="login-form"')
    10911092
    10921093
     1094class AdminViewsNoPermissionsTest(TestCase):
     1095    """Regression test for #17333"""
     1096
     1097    urls = "regressiontests.admin_views.urls"
     1098    fixtures = ['admin-views-users.xml']
     1099
     1100    def setUp(self):
     1101        opts = Report._meta
     1102
     1103        # Programmatically remove add and change perms from on the Report model
     1104        # that syncdb should have created for us
     1105        #get_perm(Report, opts.get_add_permission()).delete()
     1106        #get_perm(Report, opts.get_change_permission()).delete()
     1107
     1108        # User who can change Reports
     1109        change_user = User.objects.get(username='changeuser')
     1110        change_user.user_permissions.add(get_perm(Report,
     1111            opts.get_change_permission()))
     1112
     1113        # login POST dict
     1114        self.changeuser_login = {
     1115            REDIRECT_FIELD_NAME: '/test_admin/admin/',
     1116            LOGIN_FORM_KEY: 1,
     1117            'username': 'changeuser',
     1118            'password': 'secret',
     1119        }
     1120
     1121    def test_no_add_perms(self):
     1122        self.client.get('/test_admin/admin/')
     1123        self.client.post('/test_admin/admin/', self.changeuser_login)
     1124        r = self.client.get('/test_admin/admin/')
     1125        self.assertEqual(r.status_code, 200)
     1126        self.client.get('/test_admin/admin/logout/')
     1127
    10931128class AdminViewDeletedObjectsTest(TestCase):
    10941129    urls = "regressiontests.admin_views.urls"
    10951130    fixtures = ['admin-views-users.xml', 'deleted-objects.xml']
Back to Top