Ticket #15032: 15032-tests.diff

File 15032-tests.diff, 3.0 KB (added by Ramiro Morales, 14 years ago)

Patch for the Django test suite

  • tests/regressiontests/admin_views/models.py

    diff -r 13b0c8dc6ed9 tests/regressiontests/admin_views/models.py
    a b  
    615615class AlbumAdmin(admin.ModelAdmin):
    616616    list_filter = ['title']
    617617
     618class Employee(Person):
     619    code = models.CharField(max_length=20)
     620
     621class WorkHour(models.Model):
     622    datum = models.DateField()
     623    employee = models.ForeignKey(Employee)
     624
     625class WorkHourAdmin(admin.ModelAdmin):
     626    list_display = ('datum', 'employee')
     627    list_filter = ('employee',)
     628
    618629admin.site.register(Article, ArticleAdmin)
    619630admin.site.register(CustomArticle, CustomArticleAdmin)
    620631admin.site.register(Section, save_as=True, inlines=[ArticleInline])
     
    646657admin.site.register(PlotDetails)
    647658admin.site.register(CyclicOne)
    648659admin.site.register(CyclicTwo)
     660admin.site.register(WorkHour, WorkHourAdmin)
     661
    649662
    650663# We intentionally register Promo and ChapterXtra1 but not Chapter nor ChapterXtra2.
    651664# That way we cover all four cases:
  • tests/regressiontests/admin_views/tests.py

    diff -r 13b0c8dc6ed9 tests/regressiontests/admin_views/tests.py
    a b  
    3333    FooAccount, Gallery, ModelWithStringPrimaryKey, \
    3434    Person, Persona, Picture, Podcast, Section, Subscriber, Vodcast, \
    3535    Language, Collector, Widget, Grommet, DooHickey, FancyDoodad, Whatsit, \
    36     Category, Post, Plot, FunkyTag, Chapter, Book, Promo
     36    Category, Post, Plot, FunkyTag, Chapter, Book, Promo, WorkHour, Employee
    3737
    3838
    3939class AdminViewBasicTest(TestCase):
     
    4747
    4848    def setUp(self):
    4949        self.old_language_code = settings.LANGUAGE_CODE
    50         self.client.login(username='super', password='secret')
     50        self.client.login(username='super',password='secret')
    5151
    5252    def tearDown(self):
    5353        settings.LANGUAGE_CODE = self.old_language_code
     
    382382        except SuspiciousOperation:
    383383            self.fail("Filters should be allowed if they involve a local field without the need to whitelist them in list_filter or date_hierarchy.")
    384384
     385        e1 = Employee.objects.create(name='Anonymous', gender=1, age=22, alive=True, code='123')
     386        e2 = Employee.objects.create(name='Visitor', gender=2, age=19, alive=True, code='124')
     387        WorkHour.objects.create(datum=datetime.datetime.now(), employee=e1)
     388        WorkHour.objects.create(datum=datetime.datetime.now(), employee=e2)
     389        response = self.client.get("/test_admin/admin/admin_views/workhour/")
     390        self.assertEqual(response.status_code, 200)
     391        self.assertContains(response, 'employee__person_ptr__exact')
     392        self.client.get("/test_admin/admin/admin_views/workhour/?employee__person_ptr__exact=%d" % e1.pk)
     393        self.assertEqual(response.status_code, 200)
     394
    385395class SaveAsTests(TestCase):
    386396    fixtures = ['admin-views-users.xml','admin-views-person.xml']
    387397
Back to Top