Skip to content
This repository was archived by the owner on Mar 30, 2026. It is now read-only.

Commit f0babcc

Browse files
committed
Add tests for repo_add method()
1 parent 676e7e2 commit f0babcc

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

tests/test_core.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
# sgit imports
77
from sgit.core import Sgit, DEFAULT_REPO_CONTENT
8+
from sgit.exceptions import *
89

910
# 3rd party imports
1011
import pytest
@@ -83,3 +84,35 @@ def test_repo_list(sgit):
8384
## The default configfile after init_repo is empty and usable here
8485
retcode = sgit.repo_list()
8586
assert retcode == 1
87+
88+
89+
def test_repo_add(sgit):
90+
retcode = sgit.init_repo()
91+
assert retcode == None
92+
93+
## Test exception failure if we send in the wrong data
94+
with pytest.raises(SgitConfigException) as pytest_wrapped_e:
95+
sgit.repo_add(None, None, None)
96+
97+
assert pytest_wrapped_e.type == SgitConfigException
98+
99+
## Do a valid add of a new repo
100+
name = 'foobar'
101+
gitrepo = '[email protected]/sgit'
102+
revision = 'master'
103+
104+
sgit.repo_add(name, gitrepo, revision)
105+
106+
saved_data = sgit._get_config_file()
107+
assert saved_data == {
108+
'repos': {
109+
name: {
110+
'clone-url': gitrepo,
111+
'revision': revision
112+
}
113+
}
114+
}
115+
116+
## If rerunning the same config then it should cause an error
117+
retcode = sgit.repo_add(name, gitrepo, revision)
118+
assert retcode == 1

0 commit comments

Comments
 (0)