예제 #1
0
    def test_saving_and_retrieving_post(self):
        first_post = Post()
        first_post.board = self.default_board
        first_post.title = 'first post of title'
        first_post.content = 'first post of content'
        first_post.ip = '127.0.0.1'
        first_post.save()

        second_post = Post()
        second_post.board = self.default_board
        second_post.title = 'second post of title'
        second_post.content = 'second post of content'
        second_post.ip = '127.0.0.1'
        second_post.save()

        saved_posts = Post.objects.all()
        self.assertEqual(saved_posts.count(), 2)

        first_saved_post = saved_posts[0]
        second_saved_post = saved_posts[1]
        self.assertEqual(first_saved_post.title, 'first post of title')
        self.assertEqual(first_saved_post.content, 'first post of content')
        self.assertEqual(first_saved_post.ip, '127.0.0.1')
        self.assertEqual(second_saved_post.title, 'second post of title')
        self.assertEqual(second_saved_post.content, 'second post of content')
예제 #2
0
 def test_cannot_save_empty_content_post(self):
     post = Post()
     post.board = self.default_board
     post.title = 'This is a title'
     post.content = ''
     with self.assertRaises(ValidationError):
         post.save()
         post.full_clean()
예제 #3
0
    def test_post_save(self):
        post = Post()
        post.user = User.objects.get(pk=1)
        post.title = '제목'
        post.content = '내용'
        post.tags = 'abc'
        post.status = 'd'
        post.save()

        saved_post = Post.objects.first()
        self.assertEqual(saved_post, post)
예제 #4
0
    def test_is_delete_change_to_True_after_delete_post(self):
        delete_post = Post()
        delete_post.board = self.default_board
        delete_post.title = 'post of title'
        delete_post.content = 'post of content'
        delete_post.ip = '192.168.0.1'
        delete_post.save()

        self.assertEqual(delete_post.is_deleted, False)
        self.client.post(reverse('board:delete_post', args=[delete_post.id]))

        delete_post.refresh_from_db()

        self.assertEqual(delete_post.is_deleted, True)
예제 #5
0
    def setUpTestData(cls):
        # create user
        user = User.objects.create(name=name, email=email, password=password)

        # get token when login
        request = RequestFactory().post('/login/',
                                        data=json.dumps({
                                            'email': email,
                                            'password': password
                                        }),
                                        content_type='application/json')
        global token
        token = json.loads(login(request=request).content)['token']

        # create a post
        post = Post()
        post.author = user
        post.content = "測試用的發文"
        post.save()

        # get post_id
        for post_item in Post.objects.filter(content="測試用的發文"):
            global post_id
            post_id = post_item.id