Skip to content

Commit

Permalink
Fix switch_project if project ID is given as CLI command
Browse files Browse the repository at this point in the history
  • Loading branch information
aronmolnar committed Sep 19, 2024
1 parent 9751cc0 commit 773ea01
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 17 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 0.23
* Fix error for rendering with alternative design

# 0.22
* Update reptor for updated SysReptor field definition
* Raise error if wrong server URL was specified
Expand Down
2 changes: 1 addition & 1 deletion reptor/api/NotesAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __init__(self, **kwargs) -> None:

@property
def private_note(self):
return self.reptor.get_config().get_cli_overwrite().get("private_note")
return self.reptor.get_config().get("private_note")

def get_notes(self) -> typing.List[Note]:
"""Gets list of notes"""
Expand Down
2 changes: 1 addition & 1 deletion reptor/api/ProjectsAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def duplicate_and_cleanup(self):

self.delete_project()
self.switch_project(original_project_id)
self.log.info(f"Cleaned up duplicated project")
self.log.info("Cleaned up duplicated project")

def switch_project(self, new_project_id) -> None:
self.reptor._config._raw_config["project_id"] = new_project_id
Expand Down
10 changes: 5 additions & 5 deletions reptor/api/tests/test_notes_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def json(self):
@pytest.fixture(autouse=True)
def setUp(self):
reptor._config._raw_config["server"] = "https://demo.sysre.pt"
reptor._config._raw_config["cli"] = {"private_note": True}
reptor._config._raw_config["private_note"] = True
self.notes = NotesAPI(reptor=reptor)

def _mock_methods(self):
Expand All @@ -53,7 +53,7 @@ def _mock_methods(self):
def test_notes_api_init(self):
# Test valid personal note
reptor._config._raw_config["server"] = "https://demo.sysre.pt"
reptor._config._raw_config["cli"] = {"private_note": True}
reptor._config._raw_config["private_note"] = True
try:
n = NotesAPI(reptor=reptor)
assert n.private_note
Expand All @@ -62,7 +62,7 @@ def test_notes_api_init(self):

# Test valid project note
reptor._config._raw_config["server"] = "https://demo.sysre.pt"
reptor._config._raw_config["cli"] = {"private_note": False}
reptor._config._raw_config["private_note"] = False
reptor._config._raw_config["project_id"] = (
"2b5de38d-2932-4112-b0f7-42c4889dd64d"
)
Expand All @@ -74,13 +74,13 @@ def test_notes_api_init(self):

# Test missing project id and missing private_note
reptor._config._raw_config["server"] = "https://demo.sysre.pt"
reptor._config._raw_config["cli"] = {"private_note": False}
reptor._config._raw_config["private_note"] = False
reptor._config._raw_config["project_id"] = ""
with pytest.raises(ValueError):
NotesAPI(reptor=reptor)

# Test missing server
reptor._config._raw_config["server"] = ""
reptor._config._raw_config["cli"] = {"private_note": True}
reptor._config._raw_config["private_note"] = True
with pytest.raises(ValueError):
NotesAPI(reptor=reptor)
8 changes: 5 additions & 3 deletions reptor/lib/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,18 @@ def load_config(
self._no_config_file = True
config["server"] = os.environ.get("REPTOR_SERVER", config.get("server"))
config["token"] = os.environ.get("REPTOR_TOKEN", config.get("token"))
config["project_id"] = os.environ.get(
"REPTOR_PROJECT_ID", config.get("project_id")
)
config["project_id"] = os.environ.get("REPTOR_PROJECT_ID", config.get("project_id"))
if server:
config["server"] = server
if token:
config["token"] = token
if project_id:
config["project_id"] = project_id

for k, v in self.get_cli_overwrite().items():
if v:
config[k] = v

if not return_only:
self._raw_config = config
return config
Expand Down
6 changes: 1 addition & 5 deletions reptor/lib/reptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,7 @@ def get_active_project_id(self) -> str:
Returns:
str: Project ID
"""
if self.get_config().get_cli_overwrite().get("project_id", ""):
return self.get_config().get_cli_overwrite().get("project_id", "")
if self.get_config().get_project_id():
return self.get_config().get_project_id()
return ""
return self.get_config().get_project_id() or ""

@property
def api(self) -> APIManager:
Expand Down
2 changes: 1 addition & 1 deletion reptor/plugins/projects/File/File.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def run(self):
else:
notetitle = "Uploads"
icon = "📤"
timestamp = not self.reptor.get_config().get("cli").get("no_timestamp")
timestamp = not self.reptor.get_config().get("cli", dict()).get("no_timestamp")

for file in files:
self.reptor.api.notes.upload_file(
Expand Down
2 changes: 1 addition & 1 deletion reptor/plugins/projects/Note/Note.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def _write_note(self):
else:
self.notetitle = "Uploads"
icon = "📤"
timestamp = not self.reptor.get_config().get_cli_overwrite().get("no_timestamp")
timestamp = not self.reptor.get_config().get("cli", dict()).get("no_timestamp")

"""
Notes accept stdin only
Expand Down

0 comments on commit 773ea01

Please sign in to comment.