示例#1
0
class PageAdminModelTest(TestCase):
    _multiprocess_can_split_ = True

    def setUp(self):
        self.pageadmin = PageAdmin(Page, AdminSite())

    def test_base_fields(self):
        self.assertEqual(
            self.pageadmin.get_form(None).base_fields.keys(),
            ['title', 'body', 'is_draft'])

    def test_save_new_model(self):
        user = create_user()
        faker = Faker()
        form = self.pageadmin.get_form(None)
        form.base_fields['title'] = faker.words().capitalize()
        form.base_fields['body'] = faker.paragraphs()
        form.base_fields['is_draft'] = True
        page = Page()
        request = HttpRequest()
        request.user = user
        self.pageadmin.save_model(request, page, form, True)
        self.assertEqual(page.author, user)

    def test_save_existing_model_by_different_user(self):
        author = create_user()
        faker = Faker()
        page = Page(
            author=author,
            title=faker.words().capitalize(),
            body=faker.paragraphs())
        page.save()
        form = self.pageadmin.get_form(page)
        user = create_user()
        request = HttpRequest()
        request.user = user
        self.pageadmin.save_model(request, page, form, False)
        self.assertNotEqual(page.author, user)
        self.assertGreater(page.modified_at, page.created_at)
示例#2
0
 def setUp(self):
     self.pageadmin = PageAdmin(Page, AdminSite())