Skip to content

Commit

Permalink
Add another NJ test
Browse files Browse the repository at this point in the history
  • Loading branch information
WillNilges committed Nov 1, 2024
1 parent f8f93ae commit 4405137
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/meshapi/management/commands/replay_join_records.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def handle(self, *args: Any, **options: Any) -> None:
table.add_row(asdict(entry).values())

if not options["all"]:
print("The following Join Requests have not been successfully submitted.")
print("The following Join Requests HAVE NOT been successfully submitted.")

print(table)

Expand Down
44 changes: 44 additions & 0 deletions src/meshapi/tests/test_replay_join_records.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,47 @@ def test_happy_replay_join_records(self, MockJoinRecordProcessorClass):
install.building.street_address,
"Did not get expected street address for submitted install.",
)

@patch("meshapi.util.join_records.JoinRecordProcessor")
def test_nj_replay_join_records(self, MockJoinRecordProcessorClass):
os.environ[JOIN_RECORD_BASE_NAME] = "mock-join-record-test"
sample_join_records = {
f"{JOIN_RECORD_BASE_NAME}/2024/10/30/12/34/56.json": JoinRecord(
first_name="Jon",
last_name="Smith",
email_address="js@gmail.com",
phone_number="+1 585-475-2411",
street_address="711 Hudson Street",
city="Hoboken",
state="NJ",
zip_code="07030",
apartment="",
roof_access=True,
referral="Totally faked mocked join record.",
ncl=True,
trust_me_bro=False,
submission_time="2024-10-30T12:34:56",
code="400",
replayed=1,
install_number=None,
)
}

# Set up a mocked instance of the bucket
mock_processor = MockJoinRecordProcessor(data=sample_join_records)
MockJoinRecordProcessorClass.side_effect = lambda *args, **kwargs: mock_processor

# Replay the records
management.call_command("replay_join_records", "--noinput")

records = mock_processor.get_all()
self.assertEqual(1, len(records), "Got unexpected number of records in mocked S3 bucket.")
for r in records:
expected_code = "400"
self.assertEqual(
expected_code,
r.code,
f"Did not find correct replay code in mocked S3 bucket. Expected: {expected_code}, Got: {r.code}",
)
self.assertEqual(2, r.replayed, "Did not get expected replay count.")
self.assertEqual(None, r.install_number, "Install Number is not None.")
2 changes: 0 additions & 2 deletions src/meshapi/util/join_records.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ def upload(self, join_record: JoinRecord, key: str) -> None:

def get_all(self) -> list[JoinRecord]:
response = self.s3_client.list_objects_v2(Bucket=JOIN_RECORD_BUCKET_NAME)
print(response)

join_records = []

# Loop through each object and get its contents
Expand Down

0 comments on commit 4405137

Please sign in to comment.