class CredentialTests(unittest.TestCase):
    credentials_file_path = os.path.join(PROJECT_DIR, "secrets", "credentials_file")
    current_dir = os.path.dirname(os.path.realpath(__file__))
    test_file = os.path.join(current_dir, "test_file")

    def setUp(self):
        """
        Instantiate GoogleAuth object
        """
        self.auth = GoogleAuth()
        open(self.test_file, "w+").close()

    def tearDown(self):
        """
        Remove auth object after tests
        """
        del self.auth
        os.remove(self.test_file)

    def test_check_credentials_from_browser(self):
        """
        Basic check if browser returns credentials
        """
        # local_webserver_auth() returns credentials and saves them into file
        self.credentials = self.auth.local_webserver_auth()
        self.assertIsNotNone(self.credentials)
        sleep(10)

    def test_check_saved_credentials(self):
        """
        Function to save credentials to file and check if it's not empty
        """
        self.credentials = self.auth.local_webserver_auth()

        self.auth.save_credentials_to_file(credentials_file=self.test_file)
        with open(self.test_file) as f:
            self.content = f.readlines()
        self.assertIsNotNone(self.content)
        sleep(10)

    def test_credentials_with_regex(self):
        """
        Function to check credentials are properly returned
        """
        self.credentials = self.auth.local_webserver_auth()
        self.assertIsInstance(self.credentials, OAuth2Credentials)
        self.assertRegexpMatches(self.credentials.token_uri, "^http(?:s)*://\S+")
        self.assertRegexpMatches(self.credentials.access_token, ".+")
        self.assertRegexpMatches(self.credentials.client_id, ".+")
        sleep(10)
 def setUp(self):
     """
     Instantiate GoogleAuth object
     """
     self.auth = GoogleAuth()
     open(self.test_file, "w+").close()