Ejemplo n.º 1
0
 def handle(self, *args, **options):
     apps = []
     update = options.get('update')  # Not implemented yet. Always update.
     if args:
         for arg in args:
             try:
                 application = settings.FACEBOOK_APPS[arg]
                 apps.append(application)
             except KeyError:
                 raise CommandError('Application %s does not exist' %arg )
     else:
          apps.append(settings.FACEBOOK_APPS.values()[0])
     
     for app in apps:
         graph = get_static_graph(app_dict=app)
         testusers = TestUsers(graph)
         users = testusers.get_test_users()
         self.stdout.write(u' Testusers: %s\n' % users)
         for user in users:
             installed = '*' if getattr(user, 'access_token', False) else ''
             self.stdout.write(u'%s\t%s %s\n' % (user.id, user.login_url, installed))
Ejemplo n.º 2
0
def fb_testuser_menu(app_name=None):
    graph = get_static_graph(app_name)
    tu = TestUsers(graph)
    testusers = tu.get_test_users()
    return {'users': testusers}
class FacebookTestUser(Tube):
    def __init__(self, app_name=None, unique=False, **kwargs):
        super(FacebookTestUser, self).__init__(**kwargs)
        self.app_name = app_name
        self.unique = unique

        self.graph = get_static_graph(self.app_name)
        self.testusers = TestUsers(self.graph)
        self.users = []
        self.index = 0

    def __iter__(self):
        return self

    def set_up(self, cls, count, **kwargs):
        testuser_list = self.testusers.get_test_users()

        if count and count > len(testuser_list):
            remaining = count - len(testuser_list)
            try:
                print 'Not enough Test users (%s). Generating %s more.\n' % (
                    len(testuser_list), count - len(testuser_list))
            except IOError:
                pass
            for i in range(remaining):
                self._generate_new_user()
        self._user_for_testuser(testuser_list)

    def _user_for_testuser(self, testuser_list):
        try:
            print u'Checking for Facebook Test users...:\n'
        except IOError:
            pass
        for testuser in testuser_list:
            user, created = User.objects.get_or_create(id=int(testuser.id))
            if created:
                user.get_from_facebook(self.graph, save=True)
            self.users.append(user)
        try:
            print u'Done. Found %s testusers.' % len(testuser_list)
        except IOError:
            pass

    def _generate_new_user(self):
        newuser = self.testusers.generate_new_test_user(installed=True,
                                                        permissions=['email'])
        try:
            print u'Generated new Testuser: %s\n' % newuser
        except IOError:
            pass
        # The App wants Facebook Users, not Testusers.
        user, created = User.objects.get_or_create(id=int(newuser.id))
        if created:
            user.get_from_facebook(self.graph, save=True)
        self.users.append(user)
        return user

    def next(self):
        if self.index == len(self.users) - 1:
            if self.unique:
                try:
                    return self._generate_new_user()
                except GraphAPIError:
                    raise StopIteration
            else:
                self.index = 0
                return self.users[self.index]
        self.index += 1
        return self.users[self.index]
Ejemplo n.º 4
0
class FacebookTestUser(Tube):
    def __init__(self, app_name=None, unique=False, **kwargs):
        super(FacebookTestUser, self).__init__(**kwargs)
        self.app_name = app_name
        self.unique = unique

        self.graph = get_static_graph(self.app_name)
        self.testusers = TestUsers(self.graph)
        self.users = []
        self.index = 0

    def __iter__(self):
        return self

    def set_up(self, cls, count, **kwargs):
        testuser_list = self.testusers.get_test_users()

        if count and count > len(testuser_list):
            remaining = count - len(testuser_list)
            try:
                print "Not enough Test users (%s). Generating %s more.\n" % (
                    len(testuser_list),
                    count - len(testuser_list),
                )
            except IOError:
                pass
            for i in range(remaining):
                self._generate_new_user()
        self._user_for_testuser(testuser_list)

    def _user_for_testuser(self, testuser_list):
        try:
            print u"Checking for Facebook Test users...:\n"
        except IOError:
            pass
        for testuser in testuser_list:
            user, created = User.objects.get_or_create(id=int(testuser.id))
            if created:
                user.get_from_facebook(self.graph, save=True)
            self.users.append(user)
        try:
            print u"Done. Found %s testusers." % len(testuser_list)
        except IOError:
            pass

    def _generate_new_user(self):
        newuser = self.testusers.generate_new_test_user(installed=True, permissions=["email"])
        try:
            print u"Generated new Testuser: %s\n" % newuser
        except IOError:
            pass
        # The App wants Facebook Users, not Testusers.
        user, created = User.objects.get_or_create(id=int(newuser.id))
        if created:
            user.get_from_facebook(self.graph, save=True)
        self.users.append(user)
        return user

    def next(self):
        if self.index == len(self.users) - 1:
            if self.unique:
                try:
                    return self._generate_new_user()
                except GraphAPIError:
                    raise StopIteration
            else:
                self.index = 0
                return self.users[self.index]
        self.index += 1
        return self.users[self.index]