Ejemplo n.º 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')
Ejemplo n.º 2
0
 def test_get_malformed_config_file(self):
     ''' Make sure that a malformed 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))
         # write some garbage to the file
         with google_api_functions.WriteLocked(ga_config_path) as iofile:
             iofile.seek(0)
             iofile.truncate(0)
             iofile.write('{"access_token": "meowser_access_token", "refresh_token": "meowser_refre')
         # 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 empty strings
         self.assertEqual(ga_config['access_token'], u'')
         self.assertEqual(ga_config['refresh_token'], u'')
         self.assertEqual(ga_config['profile_id'], u'')
         self.assertEqual(ga_config['project_domain'], u'')
         # verify that the file exists again
         self.assertTrue(isfile(ga_config_path))
Ejemplo n.º 3
0
 def test_read_missing_config_file(self):
     ''' Make sure that reading from 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))
         # 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 empty strings
         self.assertEqual(ga_config['access_token'], u'')
         self.assertEqual(ga_config['refresh_token'], u'')
         self.assertEqual(ga_config['project_domain'], u'')
         self.assertEqual(ga_config['profile_id'], u'')
Ejemplo n.º 4
0
    def test_successful_request_new_google_access_token(self):
        with self.app.test_request_context():
            with HTTMock(self.mock_successful_request_new_google_access_token):
                google_api_functions.request_new_google_access_token('meowser_refresh_token', self.app.config['RUNNING_STATE_DIR'], self.app.config['GA_CLIENT_ID'], self.app.config['GA_CLIENT_SECRET'])

                with self.app.app_context():
                    ga_config = google_api_functions.read_ga_config(self.app.config['RUNNING_STATE_DIR'])
                self.assertEqual(ga_config['access_token'], 'meowser_access_token')
Ejemplo n.º 5
0
    def test_successful_request_new_google_access_token(self):
        with self.app.test_request_context():
            with HTTMock(self.mock_successful_request_new_google_access_token):
                google_api_functions.request_new_google_access_token(
                    "meowser_refresh_token",
                    self.app.config["RUNNING_STATE_DIR"],
                    self.app.config["GA_CLIENT_ID"],
                    self.app.config["GA_CLIENT_SECRET"],
                )

                with self.app.app_context():
                    ga_config = google_api_functions.read_ga_config(self.app.config["RUNNING_STATE_DIR"])
                self.assertEqual(ga_config["access_token"], "meowser_access_token")
Ejemplo n.º 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')