예제 #1
0
파일: tests.py 프로젝트: StetHD/canvas-2
 def test_get_post_by_short_id(self):
     comment = create_comment()
     result = self.get('/public_api/posts/{0}'.format(short_id(comment.id)))
     self.assertAPISuccess(result)
     result = self.post('/public_api/posts/{0}'.format(short_id(comment.id)))
     self.assertAPISuccess(result)
     json = util.loads(result.content)
     self.check_comment(comment.details(), json)
예제 #2
0
파일: tests.py 프로젝트: eiritana/canvas
 def test_handle_bad_post_id(self):
     comment = create_comment()
     result = self.get('/public_api/posts/{0}'.format(
         short_id(comment.id + 10000)))
     self.assertAPIFailure(result)
     result = self.post('/public_api/posts/{0}'.format(
         short_id(comment.id + 10000)))
     self.assertAPIFailure(result)
예제 #3
0
파일: tests.py 프로젝트: eiritana/canvas
 def test_get_post_by_short_id(self):
     comment = create_comment()
     result = self.get('/public_api/posts/{0}'.format(short_id(comment.id)))
     self.assertAPISuccess(result)
     result = self.post('/public_api/posts/{0}'.format(short_id(
         comment.id)))
     self.assertAPISuccess(result)
     json = util.loads(result.content)
     self.check_comment(comment.details(), json)
예제 #4
0
파일: tests.py 프로젝트: StetHD/canvas-2
 def test_get_single_distinct_post_by_posted_ids(self):
     comment = create_comment()
     id_list = [ short_id(comment.id), short_id(comment.id), short_id(comment.id) ]
     req = {'ids': id_list}
     result = self.post('/public_api/posts/', data=req)
     self.assertAPISuccess(result)
     json = util.loads(result.content)
     self.assertEqual(1, len(json['posts']))
     self.check_comment(comment.details(), json['posts'][0])
예제 #5
0
파일: tests.py 프로젝트: eiritana/canvas
 def test_get_some_bad_some_good_posts_by_post(self):
     comment = create_comment()
     comment1 = create_comment()
     id_list = [short_id(x.id) for x in [comment, comment1]]
     id_list.append(short_id(comment.id + 10000))
     req = {'ids': id_list}
     result = self.post('/public_api/posts/', data=req)
     self.assertAPISuccess(result)
     json = util.loads(result.content)
     self.assertEqual(2, len(json['posts']))
     self.check_comment(comment.details(), json['posts'][0])
예제 #6
0
파일: tests.py 프로젝트: StetHD/canvas-2
 def test_get_some_bad_some_good_posts_by_post(self):
     comment = create_comment()
     comment1 = create_comment()
     id_list = [short_id(x.id) for x in [comment, comment1]]
     id_list.append(short_id(comment.id + 10000))
     req = {'ids': id_list}
     result = self.post('/public_api/posts/', data=req)
     self.assertAPISuccess(result)
     json = util.loads(result.content)
     self.assertEqual(2, len(json['posts']))
     self.check_comment(comment.details(), json['posts'][0])
예제 #7
0
파일: tests.py 프로젝트: eiritana/canvas
 def test_get_single_distinct_post_by_posted_ids(self):
     comment = create_comment()
     id_list = [
         short_id(comment.id),
         short_id(comment.id),
         short_id(comment.id)
     ]
     req = {'ids': id_list}
     result = self.post('/public_api/posts/', data=req)
     self.assertAPISuccess(result)
     json = util.loads(result.content)
     self.assertEqual(1, len(json['posts']))
     self.check_comment(comment.details(), json['posts'][0])
예제 #8
0
파일: tests.py 프로젝트: StetHD/canvas-2
 def check_comment(self, expected, json):
     self.assertEqual(short_id(expected.id), json['id'])
     self.assertEqual(expected.title, json['title'])
     self.assertEqual(expected.category, json['category'])
     self.assertEqual(expected.reply_text, json['caption'])
     self.assertEqual(expected.author_name, json['author_name'])
     self.assertEqual(expected.parent_comment, json['parent_comment'])
     self.assertEqual(expected.parent_url, json['parent_url'])
     self.assertEqual(short_id(expected.thread_op_comment_id), json['thread_op_id'])
     self.assertEqual("https://{0}".format(settings.DOMAIN) + expected.share_page_url, json['share_page_url'])
     self.assertEqual(expected.replied_comment, json['reply_to'])
     self.assertEqual(expected.top_sticker(), json['top_sticker'])
     self.assertEqual(int(expected.timestamp), json['timestamp'])
     self.assertEqual("https://{0}".format(settings.DOMAIN) + expected.url, json['url'])
예제 #9
0
파일: tests.py 프로젝트: eiritana/canvas
 def test_get_post_and_replies(self):
     comment = create_comment(anonymous=True)
     rep1 = create_comment(parent_comment=comment, replied_comment=comment)
     rep2 = create_comment(parent_comment=comment, replied_comment=rep1)
     rep3 = create_comment(parent_comment=comment, replied_comment=rep1)
     rep4 = create_comment(parent_comment=comment)
     reply_ids = [short_id(x.id) for x in [rep1, rep2, rep3, rep4]]
     req = {'ids': [short_id(comment.id)]}
     result = self.post('/public_api/posts/', data=req)
     self.assertAPISuccess(result)
     json = util.loads(result.content)
     self.assertEqual(1, len(json['posts']))
     post = json['posts'][0]
     for id in reply_ids:
         self.assertIn(id, [x['id'] for x in post['replies']])
예제 #10
0
파일: tests.py 프로젝트: StetHD/canvas-2
 def test_get_post_and_replies(self):
     comment = create_comment(anonymous=True)
     rep1 = create_comment(parent_comment=comment, replied_comment=comment)
     rep2 = create_comment(parent_comment=comment, replied_comment=rep1)
     rep3 = create_comment(parent_comment=comment, replied_comment=rep1)
     rep4 = create_comment(parent_comment=comment)
     reply_ids = [short_id(x.id) for x in [rep1, rep2, rep3, rep4]]
     req = {'ids': [short_id(comment.id)]}
     result = self.post('/public_api/posts/', data=req)
     self.assertAPISuccess(result)
     json = util.loads(result.content)
     self.assertEqual(1, len(json['posts']))
     post = json['posts'][0]
     for id in reply_ids:
         self.assertIn(id, [x['id'] for x in post['replies']])
예제 #11
0
파일: tests.py 프로젝트: StetHD/canvas-2
 def test_respect_moderated_posts(self):
     user = create_user()
     comments = [create_comment(author=user) for x in range(4)]
     comments[0].moderate_and_save(Visibility.HIDDEN, user)
     comments[1].moderate_and_save(Visibility.DISABLED, user)
     comments[2].moderate_and_save(Visibility.UNPUBLISHED, user)
     comments[3].moderate_and_save(Visibility.CURATED, user)
     username = user.username
     result = self.get('/public_api/users/{0}'.format(username))
     self.assertAPISuccess(result)
     json = util.loads(result.content)
     returned_posts = [x['id'] for x in json['posts']]
     self.assertIn(short_id(comments[0].id), returned_posts)
     self.assertNotIn(short_id(comments[1].id), returned_posts)
     self.assertNotIn(short_id(comments[2].id), returned_posts)
     self.assertIn(short_id(comments[3].id), returned_posts)
예제 #12
0
파일: tests.py 프로젝트: eiritana/canvas
 def test_respect_moderated_posts(self):
     user = create_user()
     comments = [create_comment(author=user) for x in range(4)]
     comments[0].moderate_and_save(Visibility.HIDDEN, user)
     comments[1].moderate_and_save(Visibility.DISABLED, user)
     comments[2].moderate_and_save(Visibility.UNPUBLISHED, user)
     comments[3].moderate_and_save(Visibility.CURATED, user)
     username = user.username
     result = self.get('/public_api/users/{0}'.format(username))
     self.assertAPISuccess(result)
     json = util.loads(result.content)
     returned_posts = [x['id'] for x in json['posts']]
     self.assertIn(short_id(comments[0].id), returned_posts)
     self.assertNotIn(short_id(comments[1].id), returned_posts)
     self.assertNotIn(short_id(comments[2].id), returned_posts)
     self.assertIn(short_id(comments[3].id), returned_posts)
예제 #13
0
파일: tests.py 프로젝트: StetHD/canvas-2
 def test_get_user_by_username(self):
     user = create_user()
     comments = [create_comment(author=user) for x in range(3)]
     anon_comments = [create_comment(author=user, anonymous=True) for x in range(3)]
     username = user.username
     result = self.get('/public_api/users/{0}'.format(username))
     self.assertAPISuccess(result)
     result = self.post('/public_api/users/{0}'.format(username))
     self.assertAPISuccess(result)
     json = util.loads(result.content)
     self.check_user(user, json)
     returned_posts = [x['id'] for x in json['posts']]
     for c in comments:
         self.assertIn(short_id(c.id), returned_posts)
     for c in anon_comments:
         self.assertNotIn(short_id(c.id), returned_posts)
예제 #14
0
파일: tests.py 프로젝트: eiritana/canvas
 def test_trim_max_request(self):
     comments = [
         create_comment() for x in range(knobs.PUBLIC_API_MAX_ITEMS + 2)
     ]
     id_list = [short_id(x.id) for x in comments]
     req = {'ids': id_list}
     result = self.post('/public_api/posts/', data=req)
     self.assertAPIFailure(result)
예제 #15
0
파일: tests.py 프로젝트: eiritana/canvas
 def test_get_user_by_username(self):
     user = create_user()
     comments = [create_comment(author=user) for x in range(3)]
     anon_comments = [
         create_comment(author=user, anonymous=True) for x in range(3)
     ]
     username = user.username
     result = self.get('/public_api/users/{0}'.format(username))
     self.assertAPISuccess(result)
     result = self.post('/public_api/users/{0}'.format(username))
     self.assertAPISuccess(result)
     json = util.loads(result.content)
     self.check_user(user, json)
     returned_posts = [x['id'] for x in json['posts']]
     for c in comments:
         self.assertIn(short_id(c.id), returned_posts)
     for c in anon_comments:
         self.assertNotIn(short_id(c.id), returned_posts)
예제 #16
0
파일: tests.py 프로젝트: eiritana/canvas
 def test_post_respects_anonymity(self):
     comment = create_comment(anonymous=True)
     id_list = [short_id(comment.id)]
     req = {'ids': id_list}
     result = self.post('/public_api/posts/', data=req)
     self.assertAPISuccess(result)
     json = util.loads(result.content)
     self.assertEqual(1, len(json['posts']))
     self.assertEqual("Anonymous", json['posts'][0]['author_name'])
예제 #17
0
파일: tests.py 프로젝트: StetHD/canvas-2
 def test_post_respects_anonymity(self):
     comment = create_comment(anonymous=True)
     id_list = [ short_id(comment.id) ]
     req = {'ids': id_list}
     result = self.post('/public_api/posts/', data=req)
     self.assertAPISuccess(result)
     json = util.loads(result.content)
     self.assertEqual(1, len(json['posts']))
     self.assertEqual("Anonymous", json['posts'][0]['author_name'])
예제 #18
0
파일: tests.py 프로젝트: eiritana/canvas
 def check_comment(self, expected, json):
     self.assertEqual(short_id(expected.id), json['id'])
     self.assertEqual(expected.title, json['title'])
     self.assertEqual(expected.category, json['category'])
     self.assertEqual(expected.reply_text, json['caption'])
     self.assertEqual(expected.author_name, json['author_name'])
     self.assertEqual(expected.parent_comment, json['parent_comment'])
     self.assertEqual(expected.parent_url, json['parent_url'])
     self.assertEqual(short_id(expected.thread_op_comment_id),
                      json['thread_op_id'])
     self.assertEqual(
         "https://{0}".format(settings.DOMAIN) + expected.share_page_url,
         json['share_page_url'])
     self.assertEqual(expected.replied_comment, json['reply_to'])
     self.assertEqual(expected.top_sticker(), json['top_sticker'])
     self.assertEqual(int(expected.timestamp), json['timestamp'])
     self.assertEqual("https://{0}".format(settings.DOMAIN) + expected.url,
                      json['url'])
예제 #19
0
파일: tests.py 프로젝트: eiritana/canvas
    def test_get_paged_user_posts(self):
        user = create_user()
        knobs.PUBLIC_API_PAGINATION_SIZE = 5
        first_five = [
            create_comment(author=user)
            for x in range(knobs.PUBLIC_API_PAGINATION_SIZE)
        ]
        second_five = [
            create_comment(author=user)
            for x in range(knobs.PUBLIC_API_PAGINATION_SIZE)
        ]
        data = {'ids': [user.username]}
        result = self.post('/public_api/users/', data=data)
        self.assertAPISuccess(result)
        json = util.loads(result.content)
        self.assertEqual(1, len(json['users']))
        self.assertEqual(knobs.PUBLIC_API_PAGINATION_SIZE,
                         len(json['users'][0]['posts']))
        returned_ids = [x['id'] for x in json['users'][0]['posts']]
        for x in second_five:
            self.assertIn(short_id(x.id), returned_ids)

        data = {
            'ids': [{
                'user': user.username,
                'skip': knobs.PUBLIC_API_PAGINATION_SIZE
            }]
        }
        result = self.post('/public_api/users/', data=data)
        self.assertAPISuccess(result)
        json = util.loads(result.content)
        self.assertEqual(1, len(json['users']))
        self.assertEqual(knobs.PUBLIC_API_PAGINATION_SIZE,
                         len(json['users'][0]['posts']))
        returned_ids = [x['id'] for x in json['users'][0]['posts']]
        for x in first_five:
            self.assertIn(short_id(x.id), returned_ids)
예제 #20
0
파일: tests.py 프로젝트: StetHD/canvas-2
    def test_get_paged_user_posts(self):
        user = create_user()
        knobs.PUBLIC_API_PAGINATION_SIZE = 5
        first_five = [create_comment(author=user) for x in range(knobs.PUBLIC_API_PAGINATION_SIZE)]
        second_five = [create_comment(author=user) for x in range(knobs.PUBLIC_API_PAGINATION_SIZE)]
        data = {'ids': [user.username]}
        result = self.post('/public_api/users/', data=data)
        self.assertAPISuccess(result)
        json = util.loads(result.content)
        self.assertEqual(1, len(json['users']))
        self.assertEqual(knobs.PUBLIC_API_PAGINATION_SIZE, len(json['users'][0]['posts']))
        returned_ids = [x['id'] for x in json['users'][0]['posts']]
        for x in second_five:
            self.assertIn(short_id(x.id), returned_ids)

        data = {'ids': [{'user':user.username, 'skip':knobs.PUBLIC_API_PAGINATION_SIZE}]}
        result = self.post('/public_api/users/', data=data)
        self.assertAPISuccess(result)
        json = util.loads(result.content)
        self.assertEqual(1, len(json['users']))
        self.assertEqual(knobs.PUBLIC_API_PAGINATION_SIZE, len(json['users'][0]['posts']))
        returned_ids = [x['id'] for x in json['users'][0]['posts']]
        for x in first_five:
            self.assertIn(short_id(x.id), returned_ids)
예제 #21
0
파일: models.py 프로젝트: StetHD/canvas-2
 def thread_op_id(self):
     return short_id(self.thread_op_comment_id)
예제 #22
0
파일: tests.py 프로젝트: StetHD/canvas-2
 def test_handle_bad_post_id(self):
     comment = create_comment()
     result = self.get('/public_api/posts/{0}'.format(short_id(comment.id+10000)))
     self.assertAPIFailure(result)
     result = self.post('/public_api/posts/{0}'.format(short_id(comment.id+10000)))
     self.assertAPIFailure(result)
예제 #23
0
파일: models.py 프로젝트: eiritana/canvas
 def post_id(self):
     return short_id(self.id)
예제 #24
0
파일: models.py 프로젝트: eiritana/canvas
 def thread_op_id(self):
     return short_id(self.thread_op_comment_id)
예제 #25
0
파일: models.py 프로젝트: StetHD/canvas-2
 def post_id(self):
     return short_id(self.id)
예제 #26
0
파일: tests.py 프로젝트: StetHD/canvas-2
 def test_trim_max_request(self):
     comments = [create_comment() for x in range(knobs.PUBLIC_API_MAX_ITEMS + 2)]
     id_list = [short_id(x.id) for x in comments]
     req = {'ids': id_list}
     result = self.post('/public_api/posts/', data=req)
     self.assertAPIFailure(result)