Skip to content

Commit

Permalink
Update docstrings (#4)
Browse files Browse the repository at this point in the history
* tests for AuthController login function

* added comments and docstrings that were missing

* added missing comments and docstrings
  • Loading branch information
lealjd authored Mar 4, 2024
1 parent 6a0ccd8 commit 9274650
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,52 +13,80 @@ def test_utils_write_yamlerror(test_yaml_dict):
Tests that an exception is raised if yaml.dumps throws a yaml.YAMLError
"""

# generate a file name
file_name = str(uuid4())

# patch the dump function to raise a YAMLError
with patch("fractal.cli.utils.yaml.dump") as mock_dump:
with pytest.raises(yaml.YAMLError) as e:
mock_dump.side_effect = yaml.YAMLError

# call the function
write_user_data(test_yaml_dict, file_name)


def test_utils_write_verify_write(test_yaml_dict):
""" """
"""
Verify that a file is written
"""

# generate a file name
file_name = str(uuid4())

# verify that the fractal data directory does not exist prior to calling the function
assert not os.path.exists(FRACTAL_DATA_DIR)

# call the function
write_user_data(test_yaml_dict, file_name)

# verify that the directory exists
assert os.path.exists(f"{FRACTAL_DATA_DIR}/{file_name}")

# verify that the generated file's name matches the name generated locally
file_path = os.path.join(FRACTAL_DATA_DIR, file_name)

# load the yaml dict fixture
with open(file_path, "r") as file:
user_data = file.read()
user_data = yaml.safe_load(user_data)

# verify that the loaded yaml fixture matches what is generated by the function
assert user_data == test_yaml_dict

def test_utils_read_filenotfound():
"""
Tests that an exception is raised if there is no file matching the
string passed to the function
"""

# assert that the fractal data directory does not exist
assert not os.path.exists(FRACTAL_DATA_DIR)

# create a file name
file_name = "test_file_name"

# call the function to raise an exception
with pytest.raises(FileNotFoundError):
read_user_data(filename=file_name)

def test_utils_read_yamlerror(test_yaml_dict):
"""
Tests that an exception is raised if safe_load raises an exception.
"""

# generate a file name
file_name = str(uuid4())

# verify that there is no fractal data directory before writing
assert not os.path.exists(FRACTAL_DATA_DIR)

# call write_user_data to create a fractal data directory
write_user_data(test_yaml_dict, file_name)

# verify that the fractal data direcotry exists with the file name in it
assert os.path.exists(f"{FRACTAL_DATA_DIR}/{file_name}")

# patch safe_load to have it raise an exception
with patch('fractal.cli.utils.yaml.safe_load') as mock_load:
mock_load.side_effect = yaml.YAMLError()
with pytest.raises(yaml.YAMLError):
Expand All @@ -67,14 +95,23 @@ def test_utils_read_yamlerror(test_yaml_dict):

def test_utils_read_verify_read(test_yaml_dict):
"""
Tests that if no exceptions are raised, the yaml file is successfully read.
"""

# generate a file name
file_name = str(uuid4())

# verify that the fractal data directory exists
assert not os.path.exists(FRACTAL_DATA_DIR)

# call write_user_data to create the fractal data directory and the file
write_user_data(test_yaml_dict, file_name)

# verify that the fractal data directory exists with the file in it
assert os.path.exists(f"{FRACTAL_DATA_DIR}/{file_name}")

# call read_user_data passing the file name and store the result
yaml_file, _ = read_user_data(filename=file_name)

# verify that the yaml file that is read matches what was expected
assert yaml_file == test_yaml_dict

0 comments on commit 9274650

Please sign in to comment.