Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_init(gitlab):
"""Check init."""
my_git = FileLookup()
assert my_git.git_short == ''
assert my_git.server == gitlab.Gitlab.return_value
my_git.server.projects.get.assert_called_with(my_git.git_short)
def test_json(gitlab, mock_lookup):
"""Check _json_ method."""
my_git = FileLookup()
result = my_git.json()
assert isinstance(result, dict)
assert result['ship'] == 'pirate'
def test_runway_get(gitlab, tmpdir):
"""Make sure Git is not called when runway is specified."""
filename = 'test.json'
tmpdir.join(filename).write(TEST_JSON)
my_git = FileLookup(runway_dir=str(tmpdir))
result = my_git.get(filename=filename)
assert isinstance(result, str)
assert result == TEST_JSON
with pytest.raises(FileNotFoundError):
my_git.get(filename='parrot')
def test_invalid_json(gitlab, mock_lookup):
"""Check invalid JSON."""
my_git = FileLookup()
with pytest.raises(SystemExit):
my_git.json()
def test_project_success(mock_gitlab):
"""Check resolving GitLab Project ID is successful."""
mock_gitlab.Gitlab.return_value.projects.get.return_value = object
seeker = FileLookup()
assert seeker.project is object
def test_filelookup_attr():
"""Make sure Git related attributes are missing when runway is specified."""
my_git = FileLookup(runway_dir='/poop_deck')
assert my_git.git_short == ''
assert my_git.server is None
def test_get(gitlab, mock_lookup):
"""Check _get_ method."""
my_git = FileLookup()
result = my_git.get()
assert isinstance(result, str)
assert TEST_JSON == my_git.get()
def test_project_exception(mock_gitlab):
"""Check resolving GitLab Project ID fails with exception."""
mock_gitlab.Gitlab.return_value.projects.get.return_value = False
with pytest.raises(GitLabApiError):
FileLookup()