Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Constants and Paths #110

Merged
merged 10 commits into from
Jul 8, 2024
Merged

Constants and Paths #110

merged 10 commits into from
Jul 8, 2024

Conversation

ialarmedalien
Copy link
Collaborator

Description of PR purpose/changes

  • set up a file with text constants
  • switched over to using the Path module for quite a few of the file/path-related functions

Jira Ticket / Issue

N/A

Testing Instructions

  • Details for how to test the PR:
  • Tests pass locally and in GitHub Actions

Dev Checklist:

  • My code follows the guidelines at https://sites.google.com/lbl.gov/trussresources/home?authuser=0
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • (Python) I have run Ruff on changed Python code
  • If appropriate, I have recompiled the app and added the updated StaticNarrativeImpl.py, StaticNarrativeServer.py, and compile_report.json to this PR.

@ialarmedalien ialarmedalien requested a review from briehl July 3, 2024 23:46
@ialarmedalien ialarmedalien self-assigned this Jul 3, 2024
@@ -1,3 +1,5 @@
"""Custom StaticNarrative Errors."""
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding some extra documentation to this file.

err_msg = f"The Narrative {name} must be an integer > 0, not {number}"
if number is None or not str(number).isdigit():
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Casting to int meant that if you put in values like 4.5, they would get converted to 4 and the ref would appear valid, so I made this a bit more strict.

Comment on lines +46 to +48
missing_parts = [part for part in part_name if part not in ref]
if missing_parts:
msg = "Missing keys required to create a NarrativeRef: " + ", ".join(missing_parts)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ensure that it isn't possible to do NarrativeRef({"wsid": 12345}) and get a valid NarrativeRef out

@@ -100,11 +100,11 @@ def mock_adapter(request: requests.Request) -> requests.Response:
tag = params[0]["tag"]
ids = params[0]["ids"]
result = [_get_fake_nms_info(tag, ids)]
response._content = bytes(json.dumps({"result": result, "version": "1.1"}), "UTF-8")
response._content = bytes(json.dumps({"result": result, "version": "1.1"}), "UTF-8") # noqa: SLF001
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prevent warnings when accessing response._content

Comment on lines -195 to -216
def mock_auth_ok(user_id, token):
pass


def mock_auth_bad_token(token):
pass


def mock_ws_narrative_fetch(narrative_ref):
pass


def mock_ws_narrative_fetch_forbidden(narrative_ref):
pass


def mock_ws_info(ws_id):
pass


def mock_ws_info_unauth(ws_id):
pass
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

none of these are used

Comment on lines -10 to -12
# ensure there's a valid scratch dir and an assets dir
mkdir -p "$current_dir"/../scratch/nginx

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no longer need this (forgot to delete it in a previous PR)

Comment on lines +38 to +40
monkeypatch.setattr(Path, "is_absolute", starts_with_slash)
monkeypatch.setattr(Path, "is_dir", starts_with_slash)
monkeypatch.setattr(Path, "resolve", absolutify)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replace the old mocks with these monkey patched versions (arguably a bit simpler?)

@@ -7,8 +7,6 @@

from test.mocks import set_up_ok_mocks

USER_ID = "some_user"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

switching out USER_ID for fake_user from the conftest

Comment on lines -20 to -21
USER_ID = "some_user"
TOKEN = "some_token" # noqa: S105
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unused

Copy link

codecov bot commented Jul 5, 2024

Codecov Report

Attention: Patch coverage is 94.51220% with 9 lines in your changes missing coverage. Please review.

Project coverage is 72.47%. Comparing base (4cd0de1) to head (925e208).
Report is 1 commits behind head on develop.

Files Patch % Lines
lib/StaticNarrative/exporter/icon_util.py 91.22% 5 Missing ⚠️
lib/StaticNarrative/creator.py 94.11% 2 Missing ⚠️
lib/StaticNarrative/narrative_ref.py 80.00% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #110      +/-   ##
===========================================
+ Coverage    70.67%   72.47%   +1.79%     
===========================================
  Files           22       24       +2     
  Lines         1497     1544      +47     
===========================================
+ Hits          1058     1119      +61     
+ Misses         439      425      -14     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

yield mock_isdir
def absolutify(self: Path) -> Path:
"""Generate an absolute version of a path."""
return Path("/absolute") / self
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's pretty absolute!

from unittest.mock import MagicMock

import pytest
import StaticNarrative.exporter.icon_util

Check notice

Code scanning / CodeQL

Module is imported with 'import' and 'import from' Note test

Module 'StaticNarrative.exporter.icon_util' is imported with both 'import' and 'import from'.
@ialarmedalien ialarmedalien merged commit 2ce71f7 into develop Jul 8, 2024
12 checks passed
@ialarmedalien ialarmedalien deleted the constants branch July 8, 2024 20:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants