Example #1
0
 def test_write_unexpected_values_to_config(self):
     ''' Make sure that we can't write unexpected values to the google analytics config file.
     '''
     with self.app.app_context():
         # try to write some unexpected values to the config
         unexpected_values = {
             "esme_cordelia_hoggett": "magda_szubanski",
             "farmer_arthur_hoggett": "james_cromwell",
             "hot_headed_chef": "paul_livingston",
             "woman_in_billowing_gown": "saskia_campbell"
         }
         # include an expected value too
         unexpected_values['access_token'] = u'woofer_token'
         google_api_functions.write_ga_config(unexpected_values, self.app.config['RUNNING_STATE_DIR'])
         # ask for the config contents
         ga_config = google_api_functions.read_ga_config(self.app.config['RUNNING_STATE_DIR'])
         # there are four values
         self.assertEqual(len(ga_config), 4)
         # they are named as expected
         self.assertTrue(u'access_token' in ga_config)
         self.assertTrue(u'refresh_token' in ga_config)
         self.assertTrue(u'profile_id' in ga_config)
         self.assertTrue(u'project_domain' in ga_config)
         # their values are as expected (including the expected value set above)
         self.assertEqual(ga_config['access_token'], u'woofer_token')
         self.assertEqual(ga_config['refresh_token'], u'refresh_meows')
         self.assertEqual(ga_config['profile_id'], u'12345678')
         self.assertEqual(ga_config['project_domain'], u'example.com')
Example #2
0
    def setUp(self):
        # allow logging
        logging.disable(logging.NOTSET)

        self.work_path = mkdtemp(prefix='chime-repo-clones-')

        repo_path = dirname(abspath(__file__)) + '/../test-app.git'
        upstream_repo_dir = mkdtemp(prefix='repo-upstream-',
                                    dir=self.work_path)
        upstream_repo_path = join(upstream_repo_dir, 'test-app.git')
        copytree(repo_path, upstream_repo_path)
        self.upstream = repo_functions.ChimeRepo(upstream_repo_path)
        repo_functions.ignore_task_metadata_on_merge(self.upstream)
        self.origin = self.upstream.clone(mkdtemp(prefix='repo-origin-',
                                                  dir=self.work_path),
                                          bare=True)
        repo_functions.ignore_task_metadata_on_merge(self.origin)

        create_app_environ = {}
        create_app_environ['GA_CLIENT_ID'] = 'client_id'
        create_app_environ['GA_CLIENT_SECRET'] = 'meow_secret'

        self.ga_config_dir = mkdtemp(prefix='chime-config-',
                                     dir=self.work_path)
        create_app_environ['RUNNING_STATE_DIR'] = self.ga_config_dir
        create_app_environ['WORK_PATH'] = self.work_path
        create_app_environ['REPO_PATH'] = self.origin.working_dir
        create_app_environ['AUTH_DATA_HREF'] = 'http://example.com/auth.csv'
        create_app_environ['BROWSERID_URL'] = 'http://localhost'
        create_app_environ['LIVE_SITE_URL'] = 'http://example.org/'

        self.app = create_app(create_app_environ)

        # write a tmp config file
        config_values = {
            "access_token": "meowser_token",
            "refresh_token": "refresh_meows",
            "profile_id": "12345678",
            "project_domain": ""
        }
        with self.app.app_context():
            google_api_functions.write_ga_config(
                config_values, self.app.config['RUNNING_STATE_DIR'])

        random.choice = MagicMock(return_value="P")
Example #3
0
    def setUp(self):
        # allow logging
        logging.disable(logging.NOTSET)

        self.work_path = mkdtemp(prefix='chime-repo-clones-')

        repo_path = dirname(abspath(__file__)) + '/../test-app.git'
        upstream_repo_dir = mkdtemp(prefix='repo-upstream-', dir=self.work_path)
        upstream_repo_path = join(upstream_repo_dir, 'test-app.git')
        copytree(repo_path, upstream_repo_path)
        self.upstream = repo_functions.ChimeRepo(upstream_repo_path)
        repo_functions.ignore_task_metadata_on_merge(self.upstream)
        self.origin = self.upstream.clone(mkdtemp(prefix='repo-origin-', dir=self.work_path), bare=True)
        repo_functions.ignore_task_metadata_on_merge(self.origin)

        create_app_environ = {}
        create_app_environ['GA_CLIENT_ID'] = 'client_id'
        create_app_environ['GA_CLIENT_SECRET'] = 'meow_secret'

        self.ga_config_dir = mkdtemp(prefix='chime-config-', dir=self.work_path)
        create_app_environ['RUNNING_STATE_DIR'] = self.ga_config_dir
        create_app_environ['WORK_PATH'] = self.work_path
        create_app_environ['REPO_PATH'] = self.origin.working_dir
        create_app_environ['AUTH_DATA_HREF'] = 'http://example.com/auth.csv'
        create_app_environ['BROWSERID_URL'] = 'http://localhost'
        create_app_environ['LIVE_SITE_URL'] = 'http://example.org/'

        self.app = create_app(create_app_environ)

        # write a tmp config file
        config_values = {
            "access_token": "meowser_token",
            "refresh_token": "refresh_meows",
            "profile_id": "12345678",
            "project_domain": ""
        }
        with self.app.app_context():
            google_api_functions.write_ga_config(config_values, self.app.config['RUNNING_STATE_DIR'])

        random.choice = MagicMock(return_value="P")
Example #4
0
    def setUp(self):
        self.old_tempdir, tempfile.tempdir = tempfile.tempdir, mkdtemp(prefix='chime-TestGoogleApiFunctions-')

        create_app_environ = {}
        create_app_environ['BROWSERID_URL'] = 'http://example.com'
        create_app_environ['LIVE_SITE_URL'] = 'http://example.org/'
        create_app_environ['GA_CLIENT_ID'] = 'client_id'
        create_app_environ['GA_CLIENT_SECRET'] = 'meow_secret'

        self.ga_config_dir = mkdtemp(prefix='chime-config-')
        create_app_environ['RUNNING_STATE_DIR'] = self.ga_config_dir

        self.app = create_app(create_app_environ)

        # write a tmp config file
        config_values = {
            "access_token": "meowser_token",
            "refresh_token": "refresh_meows",
            "profile_id": "12345678",
            "project_domain": "example.com"
        }
        with self.app.app_context():
            google_api_functions.write_ga_config(config_values, self.app.config['RUNNING_STATE_DIR'])
Example #5
0
    def setUp(self):
        self.old_tempdir, tempfile.tempdir = tempfile.tempdir, mkdtemp(prefix="chime-TestGoogleApiFunctions-")

        create_app_environ = {}
        create_app_environ["BROWSERID_URL"] = "http://example.com"
        create_app_environ["LIVE_SITE_URL"] = "http://example.org/"
        create_app_environ["GA_CLIENT_ID"] = "client_id"
        create_app_environ["GA_CLIENT_SECRET"] = "meow_secret"

        self.ga_config_dir = mkdtemp(prefix="chime-config-")
        create_app_environ["RUNNING_STATE_DIR"] = self.ga_config_dir

        self.app = create_app(create_app_environ)

        # write a tmp config file
        config_values = {
            "access_token": "meowser_token",
            "refresh_token": "refresh_meows",
            "profile_id": "12345678",
            "project_domain": "example.com",
        }
        with self.app.app_context():
            google_api_functions.write_ga_config(config_values, self.app.config["RUNNING_STATE_DIR"])
Example #6
0
 def test_write_missing_config_file(self):
     ''' Make sure that writing to a missing google analytics config file doesn't raise errors.
     '''
     with self.app.app_context():
         ga_config_path = join(self.app.config['RUNNING_STATE_DIR'], google_api_functions.GA_CONFIG_FILENAME)
         # verify that the file exists
         self.assertTrue(isfile(ga_config_path))
         # remove the file
         remove(ga_config_path)
         # verify that the file's gone
         self.assertFalse(isfile(ga_config_path))
         # try to write some dummy config values
         write_config = {
             "access_token": "meowser_token",
             "refresh_token": "refresh_meows",
             "profile_id": "12345678",
             "project_domain": "example.com"
         }
         # write the config contents
         google_api_functions.write_ga_config(write_config, self.app.config['RUNNING_STATE_DIR'])
         # verify that the file exists
         self.assertTrue(isfile(ga_config_path))
         # ask for the config contents
         ga_config = google_api_functions.read_ga_config(self.app.config['RUNNING_STATE_DIR'])
         # there are four values
         self.assertEqual(len(ga_config), 4)
         # they are named as expected
         self.assertTrue(u'access_token' in ga_config)
         self.assertTrue(u'refresh_token' in ga_config)
         self.assertTrue(u'project_domain' in ga_config)
         self.assertTrue(u'profile_id' in ga_config)
         # their values are as expected (including the expected value set above)
         self.assertEqual(ga_config['access_token'], u'meowser_token')
         self.assertEqual(ga_config['refresh_token'], u'refresh_meows')
         self.assertEqual(ga_config['profile_id'], u'12345678')
         self.assertEqual(ga_config['project_domain'], u'example.com')