Skip to content

Init app#1

Merged
ehanson8 merged 3 commits into
mainfrom
init-app
Nov 19, 2024
Merged

Init app#1
ehanson8 merged 3 commits into
mainfrom
init-app

Conversation

@ehanson8

Copy link
Copy Markdown
Contributor

Purpose and background context

Creating new app for integrating ArchivesSpace and Airtable. Minimal business logic and an SSM client to start. The bulk of the line changes are coming from Pipfile.lock

How can a reviewer manually see the effects of these changes?

NA

Includes new or updated dependencies?

YES

Changes expectations for external applications?

NO

What are the relevant tickets?

Developer

  • All new ENV is documented in README
  • All new ENV has been added to staging and production environments
  • All related Jira tickets are linked in commit message(s)
  • Stakeholder approval has been confirmed (or is not needed)

Code Reviewer(s)

  • The commit message is clear and follows our guidelines (not just this PR message)
  • There are appropriate tests covering any new functionality
  • The provided documentation is sufficient for understanding any new functionality introduced
  • Any manual tests have been performed or provided examples verified
  • New dependencies are appropriate or there were no changes

Why these changes are being introduced:
* Add utils module with business logic functions and an SSM client

How this addresses that need:
* Add parse_accession_number and
parse_extent_data functions
* Add SSMClient with methods to get and update parameters
* Add corresponding unit tests and fixtures for new methods and functions

Side effects of this change:
* None

Relevant ticket(s):
* https://mitlibraries.atlassian.net/browse/INFRA-367
@ehanson8 ehanson8 self-assigned this Nov 18, 2024
@ehanson8
ehanson8 marked this pull request as ready for review November 18, 2024 16:28

@ghukill ghukill left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Overall, looking good! Appreciating the tight tests to new functionality.

Had one question about the SSMClient.update_parameter() method.

Comment thread tests/test_utils.py
Comment on lines +4 to +19
def test_parse_accession_number_4_parts_success():
accession_record = {
"id_0": "2025",
"id_1": "214",
"id_2": "314",
"id_3": "514",
}
assert parse_accession_number(accession_record) == "2025-214-314-514"


def test_parse_accession_number_1_part_success():
assert parse_accession_number({"id_0": "2025"}) == "2025"


def test_parse_extent_data_no_extents_success():
assert parse_extent_data({}) == {}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

These are nice tests. I had some initial questions about the terse nature of the utility function, but these answered them!

Comment thread tests/test_utils.py
Comment on lines +22 to +47
def test_parse_extent_data_physical_linear_feet_success():
accession_record = {"extents": [{"number": "1.0", "extent_type": "linear_feet"}]}
assert parse_extent_data(accession_record) == {
"Pre-accessioning extent (linear feet)": 1.0
}


def test_parse_extent_data_digital_gigabyes_success():
accession_record = {"extents": [{"number": "2.0", "extent_type": "gigabytes"}]}
assert parse_extent_data(accession_record) == {"Pre-accessioning extent (GB)": 2.0}


def test_parse_extent_data_physical_not_linear_feet_success():
accession_record = {"extents": [{"number": "12.0", "extent_type": "box(es)"}]}
assert parse_extent_data(accession_record) == {
"Extent Number": 12.0,
"Extent Type": "box(es)",
}


def test_parse_extent_data_digital_not_gigabytes_success():
accession_record = {"extents": [{"number": "100.0", "extent_type": "megabytes"}]}
assert parse_extent_data(accession_record) == {
"Extent Number": 100.0,
"Extent Type": "megabytes",
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Same for these tests; nice and focused, they really paint a picture of how the utility function works.

Going forward with this app, if these tests grow, it might be worth considering refactoring to a single, parameterized test... but that feels like a balance. As-is, I like it.

Comment thread asati/utils.py
Comment on lines +57 to +66
def update_parameter(self, parameter_name: str, parameter_value: str) -> str:
self.client.put_parameter(
Name=parameter_name,
Value=parameter_value,
Overwrite=True,
)
updated_parameter = self.client.get_parameter(Name=parameter_name)
updated_parameter_value = updated_parameter["Parameter"]["Value"]
logger.info(f"SSM parameter updated: {updated_parameter_value}")
return updated_parameter_value

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I'm a little confused here. Am I following that this:

  1. sets a parameter with parameter_value, overwriting if exists
  2. retrieves that same parameter
  3. extracts the value from the boto3 response
  4. returns the extracted value, which theoretically should equal the original parameter_value passed to this method

Is this to confirm that the passed parameter_value was successfully set, confirmed by immediately retrieving it? If so, would it be worth a check that parameter_value == updated_parameter? Or, if not needed, could you perhaps immediately return the result of self.client.put_parameter()?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately, the put_parameter response very unhelpfully does not include the new value so that is why I added the get_parameter call. But you are correct that I should be checking parameter_value == updated_parameter, I will add that, good catch!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@ghukill Update made in new commit

* Add check to verify that SSM parameter is updated to the expected value
@coveralls

Copy link
Copy Markdown

Pull Request Test Coverage Report for Build 11899084760

Details

  • 35 of 37 (94.59%) changed or added relevant lines in 3 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-2.9%) to 97.143%

Changes Missing Coverage Covered Lines Changed/Added Lines %
asati/utils.py 33 35 94.29%
Totals Coverage Status
Change from base Build 11821989066: -2.9%
Covered Lines: 68
Relevant Lines: 70

💛 - Coveralls

@ghukill ghukill left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Changes look good to me!

Comment thread asati/utils.py
Comment on lines +65 to +69
if parameter_value == updated_parameter_value:
logger.info(f"SSM parameter updated: '{updated_parameter_value}'")
else:
message = "SSM parameter update failed: '{parameter_value}' was not set"
raise RuntimeError(message)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

👍

@ehanson8
ehanson8 merged commit 5ce4192 into main Nov 19, 2024
@ehanson8
ehanson8 deleted the init-app branch November 19, 2024 16:02
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.

4 participants