def test_cd_repos(self): cd = CD() assert cd.name == "cd" assert len(cd.argnos) == 3 assert sum([i in cd.argnos for i in range(3)]) == 3 ghub = GHub(fromenv=True) assert ghub.context.context == "root" args = ["repos"] cd(args, ghub) assert ghub.context.context == "repos" args = ["ghub"] cd(args, ghub) assert ghub.context.context == "repo" assert ghub.context.location == "BBloggsbott/ghub" args = [".."] cd(args, ghub) assert ghub.context.context == "repos" args = ["ghub"] cd(args, ghub) cd(args, ghub) assert ghub.context.location == "BBloggsbott/ghub/ghub" cd([], ghub) assert ghub.context.context == "root" cd(["user", "defunkt"], ghub) assert ghub.context.context == "user" args = ["repos"] cd(args, ghub) assert ghub.context.context == "repos" cd([".."], ghub) args = ["repo", "BBloggsbott/ghub"] cd(args, ghub) assert ghub.context.context == "repo" assert ghub.context.location == "BBloggsbott/ghub"
def test_execute(self): interpreter = Interpreter() ghub = GHub(fromenv=True) assert ghub.context.context == "root" interpreter.execute("cd repos", ghub) assert ghub.context.context == "repos" interpreter.execute("cd ghub", ghub) assert ghub.context.context == "repo" res = interpreter.execute("cat requirements.txt", ghub) assert res interpreter.execute("ls", ghub) interpreter.execute("cd", ghub) assert ghub.context.context == "root"
def test_cat(self): cd = CD() cat = CAT() ghub = GHub(fromenv=True) res = cat([], ghub) assert ghub.context.context == "root" assert not res cd(["repos"], ghub) cd(["ghub"], ghub) assert ghub.context.context == "repo" res = cat(["dummy.txt"], ghub) assert not res res = cat(["requirements.txt"], ghub) assert res
def test_cd_stars(self): cd = CD() ghub = GHub(fromenv=True) assert ghub.context.context == "root" args = ["stars"] cd(args, ghub) assert ghub.context.context == "stars" cd([], ghub) assert ghub.context.context == "root" cd(["user", "defunkt"], ghub) assert ghub.context.context == "user" args = ["stars"] cd(args, ghub) assert ghub.context.context == "stars"
def test_watch_unwatch(self): cd = CD() watch = WATCH() unwatch = UNWATCH() ghub = GHub(fromenv=True) cd(["repos"], ghub) cd(["ghub"], ghub) watch_url = (ghub.api_url + ghub.endpoints["repos"] + "BBloggsbott/ghub" + "/subscription") response = ghub.github.get(watch_url) watching = False if response.status_code == 200: watching = True unwatch([], ghub) response = ghub.github.get(watch_url) assert response.status_code == 404 watch([], ghub) response = ghub.github.get(watch_url) assert response.status_code == 200 unwatch([], ghub) response = ghub.github.get(watch_url) assert response.status_code == 404 if watching: watch([], ghub) repo_name = "BBloggsbott/ghub" watch_url = ghub.api_url + ghub.endpoints[ "repos"] + repo_name + "/subscription" response = ghub.github.get(watch_url) watching = False if response.status_code == 200: watching = True unwatch([repo_name], ghub) response = ghub.github.get(watch_url) assert response.status_code == 404 watch([repo_name], ghub) response = ghub.github.get(watch_url) assert response.status_code == 200 unwatch([repo_name], ghub) response = ghub.github.get(watch_url) assert response.status_code == 404 if watching: watch([repo_name], ghub)
def test_star_unstar(self): cd = CD() star = STAR() unstar = UNSTAR() ghub = GHub(fromenv=True) cd(["repos"], ghub) cd(["ghub"], ghub) star_url = (ghub.api_url + ghub.endpoints["user"] + "/" + "starred/" + "BBloggsbott/ghub") response = ghub.github.get(star_url) starred = False if response.status_code == 204: starred = True unstar([], ghub) response = ghub.github.get(star_url) assert response.status_code == 404 star([], ghub) response = ghub.github.get(star_url) assert response.status_code == 204 unstar([], ghub) response = ghub.github.get(star_url) assert response.status_code == 404 if starred: star([], ghub) repo_name = "BBloggsbott/ghub" star_url = ghub.api_url + ghub.endpoints[ "user"] + "/" + "starred/" + repo_name response = ghub.github.get(star_url) starred = False if response.status_code == 204: starred = True unstar([repo_name], ghub) response = ghub.github.get(star_url) assert response.status_code == 404 star([repo_name], ghub) response = ghub.github.get(star_url) assert response.status_code == 204 unstar([repo_name], ghub) response = ghub.github.get(star_url) assert response.status_code == 404 if starred: star([repo_name], ghub)
def test_cd_followers(self): cd = CD() ghub = GHub(fromenv=True) assert ghub.context.context == "root" args = ["followers"] cd(args, ghub) assert ghub.context.context == "followers" assert ghub.context.location == "BBloggsbott/followers" args = [".."] cd(args, ghub) assert ghub.context.context == "root" cd(["user", "defunkt"], ghub) assert ghub.context.context == "user" args = ["followers"] cd(args, ghub) assert ghub.context.context == "followers" assert ghub.context.location == "defunkt/followers" args = [".."] cd(args, ghub) assert ghub.context.context == "user"
def test_get_user_tabs(self): ghub = GHub(fromenv=True) githubutils.get_user_tabs(ghub, "repos") assert ghub.context.context == "repos" assert ghub.context.location == "BBloggsbott/repos" ghub.context = ghub.context.prev_context githubutils.get_user_tabs(ghub, "stars") assert ghub.context.context == "stars" assert ghub.context.location == "BBloggsbott/stars" ghub.context = ghub.context.prev_context githubutils.get_user_tabs(ghub, "following") assert ghub.context.context == "following" assert ghub.context.location == "BBloggsbott/following" ghub.context = ghub.context.prev_context githubutils.get_user_tabs(ghub, "followers") assert ghub.context.context == "followers" assert ghub.context.location == "BBloggsbott/followers" ghub.context = ghub.context.prev_context
def test_instance_creation(self): ghub = GHub(fromenv=True) assert ghub.user["login"] == "BBloggsbott" assert ghub.context.context == "root"
def test_get_items(self): ghub = GHub(fromenv=True) ghub.context.cache = get_tree(ghub, "BBloggsbott/ghub") items = repoutils.get_items_in_tree(ghub) assert len(items) != 0
def test_authorize(self): ghub = GHub(fromenv=True) auth = githubutils.authorize(ghub, fromenv=True) assert auth == True
def test_get_user(self): ghub = GHub(fromenv=True) res = githubutils.get_user(ghub, "BBloggsbott") assert res != False
def test_latest_commit(self): ghub = GHub(fromenv=True) res = githubutils.get_latest_commit(ghub, "BBloggsbott/ghub") assert res != False
def test_fork_repo(self): ghub = GHub(fromenv=True) res = githubutils.fork_repo(ghub, "BBloggsbott/ghub") assert res == False
def test_clone_repo(self): ghub = GHub(fromenv=True) res = githubutils.clone_repo(ghub, "~/gitClones", "BBloggsbott/ghub") assert res