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()
def _create_test_user_fixture(app, app_name, test_users): """ Create the fixture for the test users """ fixture_file_path = os.path.join( _get_app_fixture_directory(app), _get_facetools_test_fixture_name(app_name)) _print('Creating fixture for test users at %s' % fixture_file_path) # Create the initial fixture old_stdout = sys.stdout try: sys.stdout = open(fixture_file_path, 'w') management.call_command('dumpdata', 'facetools', indent=4) finally: if sys.stdout != old_stdout: f = sys.stdout sys.stdout = old_stdout f.close() # Clean up the fixture so it only has this app's test users fixture_content = open(fixture_file_path).read() with open(fixture_file_path, 'w') as fixture_file: fixture_file.write( _clean_test_user_fixture(fixture_content, test_users))
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) self.test_user = TestUser.objects.get(name=self.facebook_test_user) self.set_client_signed_request(self.test_user.facebook_id, 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()
def _create_test_user_fixture(app, app_name, test_users): """ Create the fixture for the test users """ fixture_file_path = os.path.join(_get_app_fixture_directory(app), _get_facetools_test_fixture_name(app_name)) _print('Creating fixture for test users at %s' % fixture_file_path) # Create the initial fixture old_stdout = sys.stdout try: sys.stdout = open(fixture_file_path,'w') management.call_command('dumpdata', 'facetools', indent=4) finally: if sys.stdout != old_stdout: f=sys.stdout sys.stdout=old_stdout f.close() # Clean up the fixture so it only has this app's test users fixture_content = open(fixture_file_path).read() with open(fixture_file_path, 'w') as fixture_file: fixture_file.write(_clean_test_user_fixture(fixture_content, test_users))