def test_token_file_ignoring_comments(self):
        """
        Test a valid login using the password file lambda. The file itself will
        contain comments to be ignored. This test will require that the test be
        able to write to a temp directory
        """
        #setup
        token_file = "/tmp/__test_token_file__.txt"
        util.delete_file(token_file)
        expected_token = "file-token"
        token_file_content = "#ignore this line\n" + expected_token
        common.write_file(token_file, token_file_content)

        #tests
        actual_token = common.read_file(token_file)
        self.assertEqual(token_file_content, actual_token)

        options = {'cmr.token.file': token_file}
        self.assertEqual(expected_token, token.token_file(options))

        actual = str(token.token(token.token_file, options))
        self.assertEqual(expected_token, actual)

        #cleanup
        util.delete_file(token_file)
Beispiel #2
0
 def test_write_read_round_trip(self):
     """
     Test the read and write functions by doing a full round trip test. Save
     some text to a temp file, then read it back, testing both functions at once
     """
     path = "/tmp/" + str(uuid.uuid4())
     expected = str(uuid.uuid4())
     com.write_file(path, expected)
     actual = com.read_file(path)
     os.remove(path)  # cleanup now
     self.assertEqual(expected, actual, "Write-Read round trip")
Beispiel #3
0
def token_file(options=None):
    """
    Load a token from a local user file assumed to be ~/.cmr_token
    Parameters:
        options (dictionary): Responds to:
            "cmr.token.file": location of token file, defaults to ~/.cmr_token
    Returns
        token from file
    """
    path_to_use = common.dict_or_default(options, "cmr.token.file", "~/.cmr_token")
    path = os.path.expanduser(path_to_use)
    clear_text = common.read_file(path)
    return clear_text
def token_file(config: dict = None):
    """
    Load a token from a local user file assumed to be ~/.cmr_token
    Parameters:
        config: Responds to:
            "cmr.token.file": location of token file, defaults to ~/.cmr_token
    Returns
        token from file
    """
    config = common.always(config)
    path_to_use = config.get('cmr.token.file', '~/.cmr_token')
    path = os.path.expanduser(path_to_use)
    clear_text = None
    raw_clear_text = common.read_file(path)
    if raw_clear_text is not None:
        for line in raw_clear_text.splitlines():
            if not line.startswith("#"):
                clear_text = line
                break  # we only need the first one
    return clear_text
Beispiel #5
0
    def test_token_file(self):
        """
        Test a valid login using the password file lambda with caching on. This
        will require that the test be able to write to a temp directory
        """
        #setup
        token_file = "/tmp/__test_token_file__.txt"
        util.delete_file(token_file)
        expected_token = "file-token"
        common.write_file(token_file, expected_token)

        #tests
        options = {'cmr.token.file': token_file}
        self.assertEqual(expected_token, token.token_file(options))

        actual = str(token.token(token.token_file, options))
        self.assertEqual(expected_token, actual)

        actual_token = common.read_file(token_file)
        self.assertEqual(expected_token, actual_token)

        #cleanup
        util.delete_file(token_file)
Beispiel #6
0
def token_file(config: dict = None):
    """
    Load a token from a local user file assumed to be ~/.cmr_token
    Parameters:
        config: Responds to:
            "cmr.token.file": location of token file, defaults to ~/.cmr_token
                for production, followed by a dot and the environment name if
                specified.
            "env": if not production, appended to the end of ~/.cmr_token with a dot
    Returns
        token from file
    """
    path_to_use = _token_file_path(config)

    path = os.path.expanduser(path_to_use)
    clear_text = None
    raw_clear_text = common.read_file(path)
    if raw_clear_text is not None:
        for line in raw_clear_text.splitlines():
            if not line.startswith("#"):
                clear_text = line
                break  # we only need the first one
    return clear_text
Beispiel #7
0
def valid_cmr_response(file):
    """Return a valid login response"""
    json_response = common.read_file(file)
    return tutil.MockResponse(json_response)
Beispiel #8
0
def valid_cmr_response(file, status=200):
    """return a valid login response"""
    json_response = common.read_file(file)
    return tutil.MockResponse(json_response, status=status)