Ejemplo n.º 1
0
    def _pre_setup(self):
        if self.facebook_test_user:
            if type(self.facebook_test_user) not in [str, unicode]:
                raise Exception("facebook_test_user variable must be a string (found a %s)" % type(self.facebook_test_user))

            app_name = get_app_name_from_test_case(type(self).__module__)
            facetools_fixture_name = _get_facetools_test_fixture_name(app_name)

            if not hasattr(self, 'fixtures'):
                self.fixtures = []
            if facetools_fixture_name not in self.fixtures:
                self.fixtures.append(facetools_fixture_name)
            super(FacebookTestCaseMixin, self)._pre_setup()

            # Make sure anybody that needs to sync their models loaded from fixtures
            # has a chance to do so now that the refreshed user test data is available.
            try:
                for test_user in TestUser.objects.all():
                    sync_facebook_test_user.send(sender=None, test_user=test_user)

                # Allow code to configure the test client so it has a signed request
                # of the specified test user for each request
                self.test_user = TestUser.objects.get(name=self.facebook_test_user)
                setup_facebook_test_client.send(sender=None, client=self.client, signed_request=_create_signed_request(
                    settings.FACEBOOK_APPLICATION_SECRET_KEY,
                    str(self.test_user.facebook_id),
                    oauth_token=self.test_user.access_token,
                ))
            except TestUser.DoesNotExist:
                raise TestUserNotLoaded("Test user %s hasn't been loaded via the %s fixture (did you run sync_facebook_test_users?)" %
                                        (self.facebook_test_user, facetools_fixture_name))
        else:
            super(FacebookTestCaseMixin, self)._pre_setup()
Ejemplo n.º 2
0
 def set_client_signed_request(self, facebook_id, access_token):
     """
     Allow code to configure the test client so it has a signed request
     of the specified test user for each request
     """
     setup_facebook_test_client.send(sender=None, client=self.client, signed_request=_create_signed_request(
         settings.FACEBOOK_APPLICATION_SECRET_KEY, facebook_id, oauth_token=access_token))