-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Leah Wasser
committed
Nov 23, 2021
1 parent
ab686ce
commit 541f1ef
Showing
2 changed files
with
56 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,6 +46,21 @@ def example_student_repo(tmpdir): | |
return repo_dir | ||
|
||
|
||
@pytest.fixture() | ||
def example_student_repo_git(tmpdir, example_student_repo): | ||
"""A fixture with an initialized git repo""" | ||
|
||
import contextlib | ||
|
||
# Create the repo dir | ||
repo_path = example_student_repo | ||
with open(os.devnull, "w") as f, contextlib.redirect_stdout(f): | ||
# This just suppresses print messages so we aren't getting extra | ||
# stdout to weed through | ||
abcgit.init_and_commit(repo_path) | ||
return repo_path | ||
|
||
|
||
# TODO: add an actual check here for the standard out | ||
def test_check_git_ssh_pass(): | ||
"""When ssh is setup correctly, the check should run and pass with no | ||
|
@@ -177,6 +192,46 @@ def test_clone_repo_bad_repo( | |
) | ||
|
||
|
||
# TODO: I'm not sure there is any point of failure here because this doesn't | ||
# check | ||
# that the remote is valid in the function. is that ok? | ||
def test_add_remote(tmpdir, example_student_repo_git): | ||
"""Function that tests the add remote correctly adds a new remote to a | ||
git repo""" | ||
|
||
repo_path = example_student_repo_git | ||
abcgit.add_remote( | ||
directory=repo_path, | ||
organization="demo-org", | ||
remote_repo="student-repo", | ||
) | ||
# Now check that setting the remote worked | ||
ret = abcgit._call_git("remote", "-v", directory=repo_path) | ||
assert ret.stdout.startswith( | ||
"origin\t[email protected]:demo-org/student-repo.git (fetch)" | ||
) | ||
|
||
|
||
# Test repo changed | ||
def test_repo_changed(tmpdir, example_student_repo_git): | ||
"""Should return True if the repo is dirty""" | ||
repo_path = example_student_repo_git | ||
# Make that puppy dirty / change stuff | ||
a_file = Path(repo_path, "README.md") | ||
a_file.write_text("Some new text in the readme") | ||
ret = abcgit.repo_changed(directory=repo_path) | ||
assert ret | ||
|
||
|
||
# TODO this test and the above could be in the same test fun. not sure what | ||
# best practice is here | ||
def test_repo_clean(tmpdir, example_student_repo_git): | ||
"""Should return True if the repo is dirty""" | ||
repo_path = example_student_repo_git | ||
ret = abcgit.repo_changed(directory=repo_path) | ||
assert ret is False | ||
|
||
|
||
# TODO here we are calling git and it works. This makes me think that call | ||
# git doesn't need to be mocked at all and we can assume that the user has | ||
# git setup. | ||
|