コード例 #1
0
ファイル: tests.py プロジェクト: ruslanosipov/rblog
class PostAdminModelTest(TestCase):
    _multiprocess_can_split_ = True

    def setUp(self):
        self.postadmin = PostAdmin(Post, AdminSite())

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

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

    def test_save_existing_model_by_different_user(self):
        author = create_user()
        faker = Faker()
        post = Post(
            author=author,
            title=faker.words().capitalize(),
            body=faker.paragraphs())
        post.save()
        form = self.postadmin.get_form(post)
        user = create_user()
        request = HttpRequest()
        request.user = user
        self.postadmin.save_model(request, post, form, False)
        self.assertNotEqual(post.author, user)
        self.assertGreater(post.modified_at, post.created_at)
コード例 #2
0
ファイル: tests.py プロジェクト: ruslanosipov/rblog
 def setUp(self):
     self.postadmin = PostAdmin(Post, AdminSite())