Exemple #1
0
 def test_get_friends_who_are_user(self):
     process_session(self.client, user_id=1)
     response = self.client.post('/friends/get',
                                 data=json.dumps(self.post_friends_destroy_pine_user2),
                                 content_type='application/json').content.decode('utf-8')
     response = json.loads(response)
     assert response[Protocol.RESULT] == Protocol.SUCCESS
Exemple #2
0
    def test_destroy_friend_after_add_no_pine_friend(self):
        # create friendship with no pine user
        process_session(self.client, user_id=3)
        response = self.client.post('/friends/create',
                                    data=json.dumps({
                                        'phone_numbers': ["01087877711", "01099991111", "01087871111", "01098514123"]
                                    }),
                                    content_type='application/json').content.decode('utf-8')
        response = json.loads(response)
        assert response[Protocol.RESULT] == Protocol.SUCCESS

        # get friends list count
        response = self.client.get('/friends/list', content_type='application/json').content.decode('utf-8')
        response = json.loads(response)
        assert response[Protocol.RESULT] == Protocol.SUCCESS
        before_friends_count = len(response[Protocol.DATA])

        # destroy friendship
        response = self.client.post('/friends/destroy',
                                    data=json.dumps({
                                        'phone_numbers': ["01087877711", "01099991111", "01087871111", "01098514123"]
                                    }),
                                    content_type='application/json').content.decode('utf-8')
        response = json.loads(response)
        assert response[Protocol.RESULT] == Protocol.SUCCESS

        # get friends list count after destroy friendship
        response = self.client.get('/friends/list', content_type='application/json').content.decode('utf-8')
        response = json.loads(response)
        assert response[Protocol.RESULT] == Protocol.SUCCESS
        assert before_friends_count == len(response[Protocol.DATA]) + 4
Exemple #3
0
 def test_create_pine_friend_to_user_becoming_user_following(self):
     process_session(self.client, user_id=2)
     response = self.client.post('/friends/create',
                                 data=json.dumps(self.post_friends_create_pine_user2),
                                 content_type='application/json').content.decode('utf-8')
     response = json.loads(response)
     assert response[Protocol.RESULT] == Protocol.SUCCESS
Exemple #4
0
 def test_post_comment_block(self):
     process_session(self.client, user_id=5)
     response = self.client.post('/comments/2/block',
                                 content_type='application/json').content.decode('utf-8')
     response = json.loads(response)
     assert response[Protocol.RESULT] == Protocol.SUCCESS
     assert response[Protocol.MESSAGE] == ''
Exemple #5
0
 def test_post_thread_comment(self):
     process_session(self.client, user_id=1)
     response = self.client.post('/threads/1/comments',
                                 data=json.dumps(self.post_thread_comment_json),
                                 content_type='application/json').content.decode('utf-8')
     response = json.loads(response)
     assert response[Protocol.RESULT] == Protocol.SUCCESS
Exemple #6
0
    def test_like_unlike_like_crash(self):
        process_session(self.client, user_id=3)

        # like 8 thread
        response = self.client.post('/threads/8/like',
                                    content_type='application/json').content.decode('utf-8')
        response = json.loads(response)
        assert response[Protocol.RESULT] == Protocol.SUCCESS

        # get like count
        response = self.client.get('/threads/8', content_type='application/json').content.decode('utf-8')
        response = json.loads(response)
        assert response[Protocol.RESULT] == Protocol.SUCCESS
        before_like_count = response[Protocol.DATA]['like_count']

        # unlike thread
        response = self.client.post('/threads/8/unlike',
                                    content_type='application/json').content.decode('utf-8')
        response = json.loads(response)
        assert response[Protocol.RESULT] == Protocol.SUCCESS

        # get like count
        response = self.client.get('/threads/8', content_type='application/json').content.decode('utf-8')
        response = json.loads(response)
        assert response[Protocol.RESULT] == Protocol.SUCCESS
        assert response[Protocol.DATA]['like_count'] == before_like_count - 1

        # like thread
        response = self.client.post('/threads/8/like',
                                    content_type='application/json').content.decode('utf-8')
        response = json.loads(response)
        assert response[Protocol.RESULT] == Protocol.SUCCESS
Exemple #7
0
 def test_post_friends_thread_no_image(self):
     process_session(self.client, user_id=2)
     response = self.client.post(URL,
                                 data=json.dumps(self.post_friend_thread_json),
                                 content_type='application/json').content.decode('utf-8')
     response = json.loads(response)
     assert response[Protocol.RESULT] == Protocol.SUCCESS, response
Exemple #8
0
 def test_register_push_service(self):
     process_session(self.client, user_id=1)
     response = self.client.post('/users/register/push',
                                 data=json.dumps({
                                     'device_type': 'android',
                                     'push_id': '1234567890'
                                 }), content_type='application/json').content.decode('utf-8')
     response = json.loads(response)
     assert response[Protocol.RESULT] == Protocol.SUCCESS, response
Exemple #9
0
 def test_post_comment(self):
     c = Client()
     process_session(c, user_id=1)
     response = c.post('/threads/3/comments',
             data=json.dumps({
                'content':'for ttt'
             }),
             content_type='application/json').content.decode('utf-8')
     response = json.loads(response)
     assert response[Protocol.RESULT] == Protocol.SUCCESS, response
Exemple #10
0
 def test_get_latest_friend_timeline(self):
     process_session(self.client, user_id=1)
     uri = parse.urlencode({
         'count': 2
     })
     response = self.client.get('/timeline/friends?'+uri, content_type='application/json').content.decode('utf-8')
     response = json.loads(response)
     assert response[Protocol.RESULT] == Protocol.SUCCESS
     assert len(response[Protocol.DATA]) == 2
     assert response[Protocol.DATA][0]['type'] == 1  # thread is not author
     assert response[Protocol.DATA][1]['type'] == 0  # thread is author
Exemple #11
0
 def test_post_friends_thread_with_image(self):
     process_session(self.client, user_id=2)
     response = None
     with open(settings.BASE_DIR + '/resources/jpeg_sample.jpeg', 'rb') as fp:
         j = {
             'json': json.dumps(self.post_friend_thread_json),
             'bg_image_file': fp
         }
         response = self.client.post(URL, j).content.decode('utf-8')
         response = json.loads(response)
     assert response[Protocol.RESULT] == Protocol.SUCCESS, response
Exemple #12
0
    def test_get_thread_after_report_thread(self):
        # report thread
        process_session(self.client, user_id=2)
        response = self.client.post(URL+'/1/block',
                                    content_type='application/json').content.decode('utf-8')
        response = json.loads(response)
        assert response[Protocol.RESULT] == Protocol.SUCCESS

        # get thread
        response = self.client.get(URL+'/1', content_type='application/json').content.decode('utf-8')
        response = json.loads(response)
        assert response[Protocol.RESULT] == Protocol.FAIL
Exemple #13
0
    def test_get_thread(self):
        process_session(self.client, user_id=2)
        response = self.client.get(URL+'/1', content_type='application/json').content.decode('utf-8')
        response = json.loads(response)
        assert response[Protocol.RESULT] == Protocol.SUCCESS
        assert response[Protocol.DATA]['id'] == 1
        assert response[Protocol.DATA]['type'] == 0     # not author

        process_session(self.client, user_id=1)
        response = self.client.get(URL+'/1', content_type='application/json').content.decode('utf-8')
        response = json.loads(response)
        assert response[Protocol.RESULT] == Protocol.SUCCESS
        assert response[Protocol.DATA]['type'] == 1     # author
Exemple #14
0
 def get_friend_timeline_since_offset(self):
     process_session(self.client, user_id=1)
     uri = parse.urlencode({
         'offset_id': 3,
         'count': 2
     })
     response = self.client.get('/timeline/friends/since_offset?'+uri, content_type='application/json').content.decode('utf-8')
     response = json.loads(response)
     assert response[Protocol.RESULT] == Protocol.SUCCESS, response
     assert len(response[Protocol.DATA]) == 2, response
     assert response[Protocol.DATA][0]['type'] == 0  # thread is not author
     assert response[Protocol.DATA][0]['view_count'] == 0
     assert response[Protocol.DATA][1]['type'] == 1  # thread is author
Exemple #15
0
 def get_friend_timeline_previous_offset(self):
     process_session(self.client, user_id=1)
     uri = parse.urlencode({
         'offset_id': 5,
         'count': 2
     })
     response = self.client.get('/timeline/friends/previous_offset?'+uri, content_type='application/json').content.decode('utf-8')
     response = json.loads(response)
     print(response)
     assert response[Protocol.RESULT] == Protocol.SUCCESS
     assert len(response[Protocol.DATA]) == 2
     assert response[Protocol.DATA][0]['id'] == 3
     assert response[Protocol.DATA][1]['id'] == 1
Exemple #16
0
    def test_create_friendship_herself(self):
        process_session(self.client, user_id=1)
        response = self.client.post('/friends/create',
                                    data=json.dumps({
                                        'phone_numbers': ['01032080403']
                                    }),
                                    content_type='application/json').content.decode('utf-8')
        response = json.loads(response)
        assert response[Protocol.RESULT] == Protocol.SUCCESS

        response = self.client.get('/friends/list', content_type='application/json').content.decode('utf-8')
        response = json.loads(response)
        assert response[Protocol.RESULT] == Protocol.SUCCESS
        assert not '01032080403' in response[Protocol.DATA]
Exemple #17
0
    def test_get_comment_like_after_post_comment_unlike(self):
        process_session(self.client, user_id=1)
        response = json.loads(self.client.get('/threads/1/comments').content.decode('utf-8'))
        assert response[Protocol.RESULT] == Protocol.SUCCESS
        before_comment_like_count = response[Protocol.DATA][0]['like_count']

        response = self.client.post('/comments/1/unlike',
                                    content_type='application/json').content.decode('utf-8')
        response = json.loads(response)
        assert response[Protocol.RESULT] == Protocol.SUCCESS

        response = json.loads(self.client.get('/threads/1/comments').content.decode('utf-8'))
        assert response[Protocol.RESULT] == Protocol.SUCCESS
        assert response[Protocol.DATA][0]['like_count'] == before_comment_like_count - 1
Exemple #18
0
    def user_3_add_x2_friendship_is_crashed(self):
        process_session(self.client, user_id=3)
        response = self.client.post('/friends/create',
                                    data=json.dumps({
                                        'phone_numbers': ['01087877711', '01099991111', '01087871111']
                                    }),
                                    content_type='application/json').content.decode('utf-8')
        response = json.loads(response)
        assert response[Protocol.RESULT] == Protocol.SUCCESS

        response = self.client.post('/friends/create',
                                    data=json.dumps({
                                        'phone_numbers': ['01087877711', '01099991111', '01087871111']
                                    }),
                                    content_type='application/json').content.decode('utf-8')
        response = json.loads(response)
        assert response[Protocol.RESULT] == Protocol.SUCCESS
Exemple #19
0
    def test_create_duplicated_friendship(self):
        process_session(self.client, user_id=3)
        response = self.client.post('/friends/create',
                                    data=json.dumps({
                                        'phone_numbers': ['01011111111', '01011111111']
                                    }),
                                    content_type='application/json').content.decode('utf-8')
        response = json.loads(response)
        assert response[Protocol.RESULT] == Protocol.SUCCESS

        response = self.client.post('/friends/create',
                                    data=json.dumps({
                                        'phone_numbers': ['01011111111', '01011111111']
                                    }),
                                    content_type='application/json').content.decode('utf-8')
        response = json.loads(response)
        assert response[Protocol.RESULT] == Protocol.SUCCESS
Exemple #20
0
    def test_get_thread_comment_after_post_thread_comment(self):
        process_session(self.client, user_id=1)
        response = json.loads(self.client.get('/threads/2/comments').content.decode('utf-8'))
        assert response[Protocol.RESULT] == Protocol.SUCCESS
        assert len(response[Protocol.DATA]) == 0

        post_thread_comment_json = {
            'content': 'Hello, world.'
        }
        response = self.client.post('/threads/2/comments',
                                    data=json.dumps(post_thread_comment_json),
                                    content_type='application/json').content.decode('utf-8')
        response = json.loads(response)
        assert response[Protocol.RESULT] == Protocol.SUCCESS

        response = json.loads(self.client.get('/threads/2/comments').content.decode('utf-8'))
        assert response[Protocol.RESULT] == Protocol.SUCCESS
        assert len(response[Protocol.DATA]) == 1
Exemple #21
0
    def test_get_thread_comment(self):
        process_session(self.client, user_id=1)
        response = self.client.get('/threads/1/comments').content.decode('utf-8')
        response = json.loads(response)
        assert response[Protocol.RESULT] == Protocol.SUCCESS
        assert response[Protocol.DATA][0]['comment_user_id'] == 0
        assert response[Protocol.DATA][1]['comment_user_id'] == 1
        assert response[Protocol.DATA][0]['like_count'] == 3
        assert response[Protocol.DATA][1]['like_count'] == 0
        assert response[Protocol.DATA][0]['liked'] is True
        assert response[Protocol.DATA][1]['liked'] is False
        assert response[Protocol.DATA][0]['comment_type'] == 3
        assert response[Protocol.DATA][1]['comment_type'] == 0

        process_session(self.client, user_id=4)
        response = self.client.get('/threads/1/comments').content.decode('utf-8')
        response = json.loads(response)
        assert response[Protocol.DATA][0]['comment_type'] == 2
        assert response[Protocol.DATA][2]['comment_type'] == 1
        assert response[Protocol.DATA][2]['comment_user_id'] == 2
Exemple #22
0
    def test_get_thread_comment_thread_author_is_not_commented_first(self):
        # thread 3 authored user6 commented user1, user6
        process_session(self.client, user_id=1)
        response = self.client.get('/threads/3/comments').content.decode('utf-8')
        response = json.loads(response)
        assert response[Protocol.RESULT] == Protocol.SUCCESS
        assert len(response[Protocol.DATA]) == 2
        assert response[Protocol.DATA][0]['comment_user_id'] == 1
        assert response[Protocol.DATA][1]['comment_user_id'] == 0
        assert response[Protocol.DATA][0]['like_count'] == 0
        assert response[Protocol.DATA][1]['like_count'] == 0
        assert response[Protocol.DATA][0]['liked'] is False
        assert response[Protocol.DATA][1]['liked'] is False
        assert response[Protocol.DATA][0]['comment_type'] == 1
        assert response[Protocol.DATA][1]['comment_type'] == 2

        process_session(self.client, user_id=6)
        response = self.client.get('/threads/3/comments').content.decode('utf-8')
        response = json.loads(response)
        assert response[Protocol.DATA][0]['comment_user_id'] == 1
        assert response[Protocol.DATA][1]['comment_user_id'] == 0
        assert response[Protocol.DATA][0]['comment_type'] == 0
        assert response[Protocol.DATA][1]['comment_type'] == 3
Exemple #23
0
    def test_get_thread_comment_user_id_after_post_thread_comment(self):
        # thread 1 : comment user 1 8 4 1 8
        # Step 1. Setting comments
        process_session(self.client, user_id=1)
        response = self.client.post(
            '/threads/1/comments',
            data=json.dumps({'content': 'author comment'}),
            content_type='application/json').content.decode('utf-8')
        response = json.loads(response)
        assert response[Protocol.RESULT] == Protocol.SUCCESS

        process_session(self.client, user_id=8)
        response = self.client.post(
            '/threads/1/comments',
            data=json.dumps({'content': 'user 8 comment'}),
            content_type='application/json').content.decode('utf-8')
        response = json.loads(response)
        assert response[Protocol.RESULT] == Protocol.SUCCESS

        # Step 2. check comment type 0, 3
        process_session(self.client, user_id=1)
        response = self.client.get('/threads/1/comments').content.decode(
            'utf-8')
        response = json.loads(response)
        assert response[Protocol.RESULT] == Protocol.SUCCESS
        assert response[Protocol.DATA][0]['comment_type'] == 3
        assert response[Protocol.DATA][1]['comment_type'] == 0

        # Step 3. check comment type 0, 3
        process_session(self.client, user_id=4)
        response = self.client.get('/threads/1/comments').content.decode(
            'utf-8')
        response = json.loads(response)
        assert response[Protocol.RESULT] == Protocol.SUCCESS
        assert response[Protocol.DATA][0]['comment_type'] == 2
        assert response[Protocol.DATA][2]['comment_type'] == 1

        # Step 4. check comment user_id
        assert response[Protocol.DATA][0]['comment_user_id'] == 0
        assert response[Protocol.DATA][1]['comment_user_id'] == 1
        assert response[Protocol.DATA][2]['comment_user_id'] == 2
        assert response[Protocol.DATA][3]['comment_user_id'] == 0
        assert response[Protocol.DATA][4]['comment_user_id'] == 1
Exemple #24
0
    def test_get_thread_comment_user_id_after_post_thread_comment(self):
        # thread 1 : comment user 1 8 4 1 8
        # Step 1. Setting comments
        process_session(self.client, user_id=1)
        response = self.client.post('/threads/1/comments',
                                    data=json.dumps({'content': 'author comment'}),
                                    content_type='application/json').content.decode('utf-8')
        response = json.loads(response)
        assert response[Protocol.RESULT] == Protocol.SUCCESS

        process_session(self.client, user_id=8)
        response = self.client.post('/threads/1/comments',
                                    data=json.dumps({'content': 'user 8 comment'}),
                                    content_type='application/json').content.decode('utf-8')
        response = json.loads(response)
        assert response[Protocol.RESULT] == Protocol.SUCCESS

        # Step 2. check comment type 0, 3
        process_session(self.client, user_id=1)
        response = self.client.get('/threads/1/comments').content.decode('utf-8')
        response = json.loads(response)
        assert response[Protocol.RESULT] == Protocol.SUCCESS
        assert response[Protocol.DATA][0]['comment_type'] == 3
        assert response[Protocol.DATA][1]['comment_type'] == 0

        # Step 3. check comment type 0, 3
        process_session(self.client, user_id=4)
        response = self.client.get('/threads/1/comments').content.decode('utf-8')
        response = json.loads(response)
        assert response[Protocol.RESULT] == Protocol.SUCCESS
        assert response[Protocol.DATA][0]['comment_type'] == 2
        assert response[Protocol.DATA][2]['comment_type'] == 1

        # Step 4. check comment user_id
        assert response[Protocol.DATA][0]['comment_user_id'] == 0
        assert response[Protocol.DATA][1]['comment_user_id'] == 1
        assert response[Protocol.DATA][2]['comment_user_id'] == 2
        assert response[Protocol.DATA][3]['comment_user_id'] == 0
        assert response[Protocol.DATA][4]['comment_user_id'] == 1
Exemple #25
0
    def test_get_comment_like_after_post_comment_like(self):
        process_session(self.client, user_id=1)
        response = json.loads(
            self.client.get('/threads/1/comments').content.decode('utf-8'))
        assert response[Protocol.RESULT] == Protocol.SUCCESS
        before_comment_like_count = response[Protocol.DATA][0]['like_count']

        process_session(self.client, user_id=4)
        response = self.client.post(
            '/comments/1/like',
            content_type='application/json').content.decode('utf-8')
        response = json.loads(response)
        assert response[Protocol.RESULT] == Protocol.SUCCESS

        process_session(self.client, user_id=1)
        response = json.loads(
            self.client.get('/threads/1/comments').content.decode('utf-8'))
        assert response[Protocol.RESULT] == Protocol.SUCCESS
        assert response[
            Protocol.DATA][0]['like_count'] == before_comment_like_count + 1
Exemple #26
0
    def test_destroy_all_friend_after_add_no_pine_friend_and_pine_friend_x2(
            self):
        # create friendship with pine, no pine user
        process_session(self.client, user_id=3)
        response = self.client.post(
            '/friends/create',
            data=json.dumps({'phone_numbers': ["01032080403", "01099991111"]}),
            content_type='application/json').content.decode('utf-8')
        response = json.loads(response)
        assert response[Protocol.RESULT] == Protocol.SUCCESS

        # create friendship with no pine user again
        process_session(self.client, user_id=3)
        response = self.client.post(
            '/friends/create',
            data=json.dumps({'phone_numbers': ["01087537711"]}),
            content_type='application/json').content.decode('utf-8')
        response = json.loads(response)
        assert response[Protocol.RESULT] == Protocol.SUCCESS

        # get friends list count
        response = self.client.get(
            '/friends/list',
            content_type='application/json').content.decode('utf-8')
        response = json.loads(response)
        assert response[Protocol.RESULT] == Protocol.SUCCESS
        before_friends_count = len(response[Protocol.DATA])

        # destroy friendship
        response = self.client.post(
            '/friends/destroy',
            data=json.dumps({
                'phone_numbers': ["01032080403", "01099991111", '01087537711']
            }),
            content_type='application/json').content.decode('utf-8')
        response = json.loads(response)
        assert response[Protocol.RESULT] == Protocol.SUCCESS

        # get friends list count after destroy friendship
        response = self.client.get(
            '/friends/list',
            content_type='application/json').content.decode('utf-8')
        response = json.loads(response)
        assert response[Protocol.RESULT] == Protocol.SUCCESS
        assert before_friends_count == len(response[Protocol.DATA]) + 3

        # create friendship with pine, no pine user
        process_session(self.client, user_id=3)
        response = self.client.post(
            '/friends/create',
            data=json.dumps({'phone_numbers': ["01032080403", "01099991111"]}),
            content_type='application/json').content.decode('utf-8')
        response = json.loads(response)
        assert response[Protocol.RESULT] == Protocol.SUCCESS

        # get friends list count
        response = self.client.get(
            '/friends/list',
            content_type='application/json').content.decode('utf-8')
        response = json.loads(response)
        assert response[Protocol.RESULT] == Protocol.SUCCESS
        before_friends_count = len(response[Protocol.DATA])

        # destroy friendship
        response = self.client.post(
            '/friends/destroy',
            data=json.dumps({'phone_numbers': ["01032080403", "01099991111"]}),
            content_type='application/json').content.decode('utf-8')
        response = json.loads(response)
        assert response[Protocol.RESULT] == Protocol.SUCCESS

        # get friends list count after destroy friendship
        response = self.client.get(
            '/friends/list',
            content_type='application/json').content.decode('utf-8')
        response = json.loads(response)
        assert response[Protocol.RESULT] == Protocol.SUCCESS
        assert before_friends_count == len(response[Protocol.DATA]) + 2
Exemple #27
0
 def test_get_handshake_friends_count(self):
     process_session(self.client, user_id=1)
     response = self.client.get('/friends/handshake_count', content_type='application/json').content.decode('utf-8')
     response = json.loads(response)
     assert response[Protocol.RESULT] == Protocol.SUCCESS
Exemple #28
0
 def test_post_comment_report_myself(self):
     process_session(self.client, user_id=1)
     response = self.client.post('/comments/1/report',
                                 content_type='application/json').content.decode('utf-8')
     response = json.loads(response)
     assert response[Protocol.RESULT] == Protocol.FAIL
Exemple #29
0
 def test_post_report_thread(self):
     process_session(self.client, user_id=2)
     response = self.client.post(URL+'/7/report',
                                 content_type='application/json').content.decode('utf-8')
     response = json.loads(response)
     assert response[Protocol.RESULT] == Protocol.SUCCESS
Exemple #30
0
 def test_block_thread(self):
     process_session(self.client, user_id=1)
     response = self.client.post(URL+'/5/block',
                                 content_type='application/json').content.decode('utf-8')
     response = json.loads(response)
     assert response[Protocol.RESULT] == Protocol.SUCCESS, response[Protocol.MESSAGE]