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

adding intake route unit tests #112

Merged
merged 1 commit into from
Feb 28, 2024
Merged

adding intake route unit tests #112

merged 1 commit into from
Feb 28, 2024

Conversation

MadelaineJ
Copy link
Collaborator

Problem
intake routes aren't currently being tested

Solution

  • added unit test for intake routes
  • updated get all intakes to look in a date range
  • had to rename update_intake to avoid function naming conflict
  • was able to remove defaults from intake schema
    Note: unit tests are the same unit tests as for encounters

Ticket URL
https://mediform.atlassian.net/browse/MEDI-56

Documentation
NA

Tests Run
make testapi

Problem

Solution

Ticket URL

Documentation

Tests Run
@MadelaineJ MadelaineJ requested a review from critch646 February 27, 2024 16:40
Copy link
Collaborator

@critch646 critch646 left a comment

Choose a reason for hiding this comment

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

Awesome!

Copy link
Collaborator

Choose a reason for hiding this comment

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

The decorate @pytest.mark.needs(postgres=True) invokes these two functions in conftest.py:

@lru_cache
def postgres_is_running() -> bool:
"""
Function returns True if Postgres is ready to accept database connections,
False otherwise.
"""
try:
connection = psycopg2.connect(
database=os.getenv("POSTGRES_DB"),
host=os.getenv("POSTGRES_HOST"),
port=str(os.getenv("POSTGRES_PORT")),
password=os.getenv("POSTGRES_PASSWORD"),
user=os.getenv("POSTGRES_USER"),
connect_timeout=1,
)
connection.close()
return True
except (Exception, psycopg2.DatabaseError):
pass
return False
def pytest_runtest_setup(item):
"""
Checks to see if a test case should run based on the specified 'needs' pytest marker.
"""
marker = item.get_closest_marker(name="needs")
needs = marker.kwargs if marker else {}
if needs.get("postgres", False) and not postgres_is_running():
pytest.skip("Skipped test case because Postgres is not available.")

Currently, it only checks for the medical DB and not the sanctuary one. conftest.py will need to be updated to check for the sanctuary db as well. It doesn't need to be this commit though (it could be done as part of the testing overhaul).

@MadelaineJ MadelaineJ merged commit 996090c into main Feb 28, 2024
1 check passed
@MadelaineJ MadelaineJ deleted the madelaine-sanctuary branch February 28, 2024 17:09
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