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_get(gitlab, mock_lookup):
    """Check _get_ method."""
    my_git = FileLookup()

    result = my_git.get()
    assert isinstance(result, str)
    assert TEST_JSON == my_git.get()
Example #3
0
def test_invalid_json(gitlab):
    """Check invalid JSON."""
    my_git = FileLookup()

    my_git.server.getfile.return_value = {'content': base64.b64encode(TEST_JSON_BYTES + b'}')}

    with pytest.raises(SystemExit):
        my_git.json()
Example #4
0
def test_json(gitlab):
    """Check _json_ method."""
    my_git = FileLookup()

    my_git.server.getfile.return_value = {'content': base64.b64encode(TEST_JSON_BYTES)}

    result = my_git.json()
    assert isinstance(result, dict)
    assert result['ship'] == 'pirate'
Example #5
0
def test_get(gitlab):
    """Check _get_ method."""
    my_git = FileLookup()

    my_git.server.getfile.return_value = {'content': base64.b64encode(TEST_JSON_BYTES)}

    result = my_git.get()
    assert isinstance(result, str)
    assert TEST_JSON == my_git.get()
Example #6
0
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')
Example #7
0
def test_runway_get(gitlab):
    """Make sure Git related attributes are missing when runway is specified."""
    my_git = FileLookup(runway_dir='/poop_deck')

    assert getattr(my_git, 'git_short') is None
    assert getattr(my_git, 'server') is None
    assert getattr(my_git, 'project_id') is None
Example #8
0
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.getproject.assert_called_with(my_git.git_short)
Example #9
0
def test_project_id_success(mock_gitlab):
    """Check resolving GitLab Project ID is successful."""
    project_id = 30

    mock_gitlab.Gitlab.return_value.getproject.return_value = {'id': project_id}

    seeker = FileLookup()

    assert seeker.project_id == project_id
Example #10
0
def test_project_id_exception(mock_gitlab):
    """Check resolving GitLab Project ID fails with exception."""
    mock_gitlab.Gitlab.return_value.getproject.return_value = False

    with pytest.raises(GitLabApiError):
        FileLookup()
Example #11
0
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
Example #12
0
def test_invalid_json(gitlab, mock_lookup):
    """Check invalid JSON."""
    my_git = FileLookup()

    with pytest.raises(SystemExit):
        my_git.json()
Example #13
0
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