Пример #1
0
    def test(self):
        checkin_actor = TransactionManager.get_checkin_actor()
        board = Board.objects.create(title="공지사항")

        post1 = Post()
        post1.title = "공지사항 제 1번"
        post1.content = "첫번째 공지사항입니다."
        post1.author = checkin_actor
        post1.board = board
        post1.save()

        assert board.posts.count() == 1
        assert post1.board == board
        assert post1.title == "공지사항 제 1번"
        assert post1.content == "첫번째 공지사항입니다."
        assert post1.author == checkin_actor
        assert post1.created_date.date() == post1.published_date.date()

        post2 = Post()
        post2.title = "공지사항 제 2번"
        post2.content = "두번째 공지사항입니다."
        post2.author = checkin_actor
        post2.board = board
        post2.save()

        assert board.posts.count() == 2
        assert post2.board == board
        assert post2.title == "공지사항 제 2번"
        assert post2.content == "두번째 공지사항입니다."
        assert post2.author == checkin_actor
        assert post2.created_date.date() == post2.published_date.date()
Пример #2
0
 def test_transaction_checkin(self):
     with Transaction():
         human = User.objects.create()
         actor = DummyActor.objects.create(user=human)
         dummy = Dummy.objects.create()
     with Transaction(checkin_actor=actor) as tran:
         assert tran.checkin_actor == actor
         assert id(tran.checkin_actor) == id(actor)
         assert tran.login_user == human
         assert TransactionManager.get_checkin_actor() == actor
     with self.assertRaises(AssertionError):
         with Transaction(checkin_actor=dummy):
             pass