Ejemplo n.º 1
0
    def test_http_save_fake_account_with_exist_account(self):
        self.set_up()
        '''Since this user already has a twitter account, then no matter the new twitter account is fake or real,
        http_save_account() would return a false indicate that this user already has a twitter account
        (notice, in this case currently we CANNOT distinguish non-exist follower from already exist account
        since both cases will return False)'''

        flr_name = 'testFollower'
        follower = Follower(name=flr_name, user=self.user)
        follower.save()
        ajax_dict = {
            'flr_name': flr_name,
            'act_type': 'twitter',
            'act_id': None,
            'screen_name': 'charleszhuochen'
        }
        Utils.ajax_post_json(self.client, url_save_account, ajax_dict)
        ajax_dict = {
            'flr_name': flr_name,
            'act_type': 'twitter',
            'act_id': None,
            'screen_name': 'fakeuserfakeuserthisisfakeuseribek'
        }
        response = Utils.ajax_post_json(self.client, url_save_account,
                                        ajax_dict)
        self.assertEqual('False', response.content)
Ejemplo n.º 2
0
class StatusViewTest(TestCase):
    def set_up(self):
        setup_dict = Utils.set_up()
        self.client = setup_dict['client']
        self.user = setup_dict['user']
        flr_name = 'testFollower'
        self.follower = Follower(name=flr_name, user=self.user)
        self.follower.save()
        self.tw_account = TwAccount(follower=self.follower,
                                    act_id='3991423984',
                                    screen_name='charleszhuochen')
        self.tw_account.save()
        self.qr_account = QrAccount(follower=self.follower,
                                    user_name='quan-zhang-27')
        self.qr_account.save()

    def test_refresh_status(self):
        self.set_up()

        ajax_dict = {'site_type': 'quora'}
        response = Utils.ajax_post_json(self.client, url_refresh_status_site,
                                        ajax_dict)
        status_list = json.loads(response.content)['status_list']
        self.assertEqual(10, len(status_list))
        for status in status_list:
            print status

        # since_id = status_list[0]["id"]
        # ajax_dict = {'site_type': 'twitter',
        #              'since_id': since_id}
        # response = Utils.ajax_post_json(self.client, url_refresh_status_site, ajax_dict)
        # status_list = json.loads(response.content)['status_list']
        # self.assertEqual(0, len(status_list))

    def test_refresh_status_flr(self):
        self.set_up()

        ajax_dict = {'flr_name': self.follower.name}
        response = Utils.ajax_post_json(self.client, url_refresh_status_flr,
                                        ajax_dict)
        status_list = json.loads(response.content)['status_list']
        # for status in status_list:
        #     print "%s\t" % status['act_type']
        #     print status.get('time_stamp', None)
        #     print "\n"
        ajax_dict = {
            'flr_name': self.follower.name,
            'lt_st_time': '2015-12-02 03:49:00'
        }
        response = Utils.ajax_post_json(self.client, url_refresh_status_flr,
                                        ajax_dict)
        status_list = json.loads(response.content)['status_list']
        for status in status_list:
            print "%s\t" % status['act_type']
            print status.get('time_stamp', None)
            print "\n"
Ejemplo n.º 3
0
    def test_refresh_status(self):
        self.set_up()
        flr_name = 'testFollower'
        follower = Follower(name=flr_name, user=self.user)
        follower.save()
        qr_account = QrAccount(follower=follower, user_name='quan-zhang-27')
        qr_account.save()

        qr_account_list = [qr_account, ]

        status_list =  QrStatusView.refresh_status(qr_account_list)
        print status_list
Ejemplo n.º 4
0
 def test_http_save_account(self):
     self.set_up()
     '''normal case: an exist follower save a new account, the account would save in to database and return True'''
     flr_name = 'testFollower'
     follower = Follower(name=flr_name, user=self.user)
     follower.save()
     ajax_dict = {'flr_name': flr_name,
                  'act_type': 'twitter',
                  # 'act_id': None,
                  'screen_name': 'charleszhuochen'}
     '''save_account would return True'''
     response = Utils.ajax_post_json(self.client, url_save_account, ajax_dict)
     self.assertEqual('True', response.content)
Ejemplo n.º 5
0
    def test_refresh_status(self):
        self.set_up()
        flr_name = 'testFollower'
        follower = Follower(name=flr_name, user=self.user)
        follower.save()
        qr_account = QrAccount(follower=follower, user_name='quan-zhang-27')
        qr_account.save()

        qr_account_list = [
            qr_account,
        ]

        status_list = QrStatusView.refresh_status(qr_account_list)
        print status_list
Ejemplo n.º 6
0
 def set_up(self):
     setup_dict = Utils.set_up()
     self.client = setup_dict['client']
     self.user = setup_dict['user']
     flr_name = 'testFollower'
     self.follower = Follower(name=flr_name, user=self.user)
     self.follower.save()
     self.tw_account = TwAccount(follower=self.follower,
                                 act_id='3991423984',
                                 screen_name='charleszhuochen')
     self.tw_account.save()
     self.qr_account = QrAccount(follower=self.follower,
                                 user_name='quan-zhang-27')
     self.qr_account.save()
Ejemplo n.º 7
0
    def test_verify_exist_account(self):
        self.set_up()
        '''verify a new account while the follower already have one will return False'''
        follower = Follower(name='testFollower', user=self.user)
        follower.save()
        tw_account = TwAccount(follower=follower, act_id='3991423984', screen_name='charleszhuochen')
        tw_account.save()

        ajax_dict = {'act_type': 'twitter',
                  'flr_name': 'testFollower',
                  'act_id': None,
                  'screen_name': '_QuanZhang_'}
        response = Utils.ajax_post_json(self.client, url_verify_account, ajax_dict)
        self.assertEqual('False', response.content)
Ejemplo n.º 8
0
    def test_http_save_fake_account(self):
        self.set_up()
        ''' if an user try to save a fake account, then the verifycation module would return '404' indicates that
        this account could not pass verification since could not find it on that social website '''

        flr_name = 'testFollower'
        follower = Follower(name=flr_name, user=self.user)
        follower.save()
        ajax_dict = {'flr_name': flr_name,
                     'act_type': 'twitter',
                     'act_id': None,
                     'screen_name': 'fakeuserfakeuserthisisfakeuseribek'}
        response = Utils.ajax_post_json(self.client, url_save_account, ajax_dict)
        self.assertEqual('404', response.content)
Ejemplo n.º 9
0
class StatusViewTest(TestCase):
    def set_up(self):
        setup_dict = Utils.set_up()
        self.client = setup_dict['client']
        self.user = setup_dict['user']
        flr_name = 'testFollower'
        self.follower = Follower(name=flr_name, user=self.user)
        self.follower.save()
        self.tw_account = TwAccount(follower=self.follower, act_id='3991423984', screen_name='charleszhuochen')
        self.tw_account.save()
        self.qr_account = QrAccount(follower=self.follower, user_name='quan-zhang-27')
        self.qr_account.save()

    def test_refresh_status(self):
        self.set_up()

        ajax_dict = {'site_type': 'quora'}
        response = Utils.ajax_post_json(self.client, url_refresh_status_site, ajax_dict)
        status_list = json.loads(response.content)['status_list']
        self.assertEqual(10, len(status_list))
        for status in status_list:
            print status

        # since_id = status_list[0]["id"]
        # ajax_dict = {'site_type': 'twitter',
        #              'since_id': since_id}
        # response = Utils.ajax_post_json(self.client, url_refresh_status_site, ajax_dict)
        # status_list = json.loads(response.content)['status_list']
        # self.assertEqual(0, len(status_list))

    def test_refresh_status_flr(self):
        self.set_up()

        ajax_dict = {'flr_name': self.follower.name}
        response = Utils.ajax_post_json(self.client, url_refresh_status_flr, ajax_dict)
        status_list = json.loads(response.content)['status_list']
        # for status in status_list:
        #     print "%s\t" % status['act_type']
        #     print status.get('time_stamp', None)
        #     print "\n"
        ajax_dict = {'flr_name': self.follower.name,
                     'lt_st_time': '2015-12-02 03:49:00'}
        response = Utils.ajax_post_json(self.client, url_refresh_status_flr, ajax_dict)
        status_list = json.loads(response.content)['status_list']
        for status in status_list:
            print "%s\t" % status['act_type']
            print status.get('time_stamp', None)
            print "\n"
Ejemplo n.º 10
0
 def test_http_save_account(self):
     self.set_up()
     '''normal case: an exist follower save a new account, the account would save in to database and return True'''
     flr_name = 'testFollower'
     follower = Follower(name=flr_name, user=self.user)
     follower.save()
     ajax_dict = {
         'flr_name': flr_name,
         'act_type': 'twitter',
         # 'act_id': None,
         'screen_name': 'charleszhuochen'
     }
     '''save_account would return True'''
     response = Utils.ajax_post_json(self.client, url_save_account,
                                     ajax_dict)
     self.assertEqual('True', response.content)
Ejemplo n.º 11
0
 def test_http_delete_account(self):
     self.set_up()
     '''normal case: delete an exist account would return True'''
     flr_name = 'testFollower'
     follower = Follower(name=flr_name, user=self.user)
     follower.save()
     tw_account = TwAccount(follower=follower, act_id='3991423984', screen_name='charleszhuochen')
     tw_account.save()
     '''before delete, TwAccount has this account'''
     self.assertEqual(True, TwAccount.objects.filter(follower__name=flr_name).exists())
     ajax_dict = {'flr_name': 'testFollower',
                  'act_type': 'twitter'}
     response = Utils.ajax_post_json(self.client, url_delete_account, ajax_dict)
     '''after delete, TwAccount does not has this account anymore'''
     self.assertEqual('True', response.content)
     self.assertEqual(False, TwAccount.objects.filter(follower__name=flr_name).exists())
Ejemplo n.º 12
0
    def test_http_save_fake_account(self):
        self.set_up()
        ''' if an user try to save a fake account, then the verifycation module would return '404' indicates that
        this account could not pass verification since could not find it on that social website '''

        flr_name = 'testFollower'
        follower = Follower(name=flr_name, user=self.user)
        follower.save()
        ajax_dict = {
            'flr_name': flr_name,
            'act_type': 'twitter',
            'act_id': None,
            'screen_name': 'fakeuserfakeuserthisisfakeuseribek'
        }
        response = Utils.ajax_post_json(self.client, url_save_account,
                                        ajax_dict)
        self.assertEqual('404', response.content)
Ejemplo n.º 13
0
    def test_refresh_status(self):
        self.set_up()
        follower = Follower(name='testFollower', user=self.user)
        follower.save()
        tw_account = TwAccount(follower=follower, act_id='3991423984', screen_name='charleszhuochen')
        tw_account.save()

        tw_account_list = [tw_account, ]
        since_id = None
        status_list = TwStatusView.refresh_status(tw_account_list, since_id)
        print(status_list[0]['created_at'])
        latest_status = TwStatus.objects.get(id=status_list[0]['id'])
        print(latest_status.created_at)
        self.assertEqual(10, len(status_list))
        since_id = int(status_list[0]['id'])
        status_list = TwStatusView.refresh_status(tw_account_list, since_id)
        self.assertEqual(0, len(status_list))
Ejemplo n.º 14
0
    def test_http_save_account_with_exist_account(self):
        self.set_up()
        '''Since this user already has a twitter account after first save, then the second save would get a False'''

        flr_name = 'testFollower'
        follower = Follower(name=flr_name, user=self.user)
        follower.save()
        ajax_dict = {'flr_name': flr_name,
                     'act_type': 'twitter',
                     'act_id': None,
                     'screen_name': 'charleszhuochen'}
        Utils.ajax_post_json(self.client, url_save_account, ajax_dict)
        ajax_dict = {'flr_name': flr_name,
                     'act_type': 'twitter',
                     'act_id': None,
                     'screen_name': '_QuanZhang_'}
        response = Utils.ajax_post_json(self.client, url_save_account, ajax_dict)
        self.assertEqual('False', response.content)
Ejemplo n.º 15
0
    def test_verify_exist_account(self):
        self.set_up()
        '''verify a new account while the follower already have one will return False'''
        follower = Follower(name='testFollower', user=self.user)
        follower.save()
        tw_account = TwAccount(follower=follower,
                               act_id='3991423984',
                               screen_name='charleszhuochen')
        tw_account.save()

        ajax_dict = {
            'act_type': 'twitter',
            'flr_name': 'testFollower',
            'act_id': None,
            'screen_name': '_QuanZhang_'
        }
        response = Utils.ajax_post_json(self.client, url_verify_account,
                                        ajax_dict)
        self.assertEqual('False', response.content)
Ejemplo n.º 16
0
def add_follower(request):
    if request.is_ajax():
        if request.method != 'POST':
            raise Http404
        json_data = json.loads(request.body)
        try:
            flr_name = json_data.get(u'flr_name')
        except KeyError:
            print("KeyError in FollowerView:add_follower() when getting flr_name\n")
            return HttpResponse(False)
        if Follower.objects.filter(name=flr_name).exists():
            return HttpResponse(False)
        new_follower = Follower(name=flr_name, user=request.user)
        new_follower.save()
        response_dict = {'flr_id': new_follower.id,
                         'flr_name': new_follower.name}
        return JsonResponse(response_dict)
    else:
        raise Http404
Ejemplo n.º 17
0
 def set_up(self):
     setup_dict = Utils.set_up()
     self.client = setup_dict['client']
     self.user = setup_dict['user']
     flr_name = 'testFollower'
     self.follower = Follower(name=flr_name, user=self.user)
     self.follower.save()
     self.tw_account = TwAccount(follower=self.follower, act_id='3991423984', screen_name='charleszhuochen')
     self.tw_account.save()
     self.qr_account = QrAccount(follower=self.follower, user_name='quan-zhang-27')
     self.qr_account.save()
Ejemplo n.º 18
0
    def test_http_save_fake_account_with_exist_account(self):
        self.set_up()
        '''Since this user already has a twitter account, then no matter the new twitter account is fake or real,
        http_save_account() would return a false indicate that this user already has a twitter account
        (notice, in this case currently we CANNOT distinguish non-exist follower from already exist account
        since both cases will return False)'''

        flr_name = 'testFollower'
        follower = Follower(name=flr_name, user=self.user)
        follower.save()
        ajax_dict = {'flr_name': flr_name,
                     'act_type': 'twitter',
                     'act_id': None,
                     'screen_name': 'charleszhuochen'}
        Utils.ajax_post_json(self.client, url_save_account, ajax_dict)
        ajax_dict = {'flr_name': flr_name,
                     'act_type': 'twitter',
                     'act_id': None,
                     'screen_name': 'fakeuserfakeuserthisisfakeuseribek'}
        response = Utils.ajax_post_json(self.client, url_save_account, ajax_dict)
        self.assertEqual('False', response.content)
Ejemplo n.º 19
0
    def test_refresh_status(self):
        self.set_up()
        follower = Follower(name='testFollower', user=self.user)
        follower.save()
        tw_account = TwAccount(follower=follower,
                               act_id='3991423984',
                               screen_name='charleszhuochen')
        tw_account.save()

        tw_account_list = [
            tw_account,
        ]
        since_id = None
        status_list = TwStatusView.refresh_status(tw_account_list, since_id)
        print(status_list[0]['created_at'])
        latest_status = TwStatus.objects.get(id=status_list[0]['id'])
        print(latest_status.created_at)
        self.assertEqual(10, len(status_list))
        since_id = int(status_list[0]['id'])
        status_list = TwStatusView.refresh_status(tw_account_list, since_id)
        self.assertEqual(0, len(status_list))
Ejemplo n.º 20
0
 def test_http_delete_account(self):
     self.set_up()
     '''normal case: delete an exist account would return True'''
     flr_name = 'testFollower'
     follower = Follower(name=flr_name, user=self.user)
     follower.save()
     tw_account = TwAccount(follower=follower,
                            act_id='3991423984',
                            screen_name='charleszhuochen')
     tw_account.save()
     '''before delete, TwAccount has this account'''
     self.assertEqual(
         True,
         TwAccount.objects.filter(follower__name=flr_name).exists())
     ajax_dict = {'flr_name': 'testFollower', 'act_type': 'twitter'}
     response = Utils.ajax_post_json(self.client, url_delete_account,
                                     ajax_dict)
     '''after delete, TwAccount does not has this account anymore'''
     self.assertEqual('True', response.content)
     self.assertEqual(
         False,
         TwAccount.objects.filter(follower__name=flr_name).exists())
Ejemplo n.º 21
0
    def test_http_save_account_with_exist_account(self):
        self.set_up()
        '''Since this user already has a twitter account after first save, then the second save would get a False'''

        flr_name = 'testFollower'
        follower = Follower(name=flr_name, user=self.user)
        follower.save()
        ajax_dict = {
            'flr_name': flr_name,
            'act_type': 'twitter',
            'act_id': None,
            'screen_name': 'charleszhuochen'
        }
        Utils.ajax_post_json(self.client, url_save_account, ajax_dict)
        ajax_dict = {
            'flr_name': flr_name,
            'act_type': 'twitter',
            'act_id': None,
            'screen_name': '_QuanZhang_'
        }
        response = Utils.ajax_post_json(self.client, url_save_account,
                                        ajax_dict)
        self.assertEqual('False', response.content)