23 lines
1.6 KiB
Markdown
23 lines
1.6 KiB
Markdown
Using Python and the {unit_test_package} package, write a suite of unit tests for the function '{function_name}', following the cases above. Include helpful comments to explain each line. Remember that we have a fetch_data function (given below in the example) that retrieves the necessary data from the database and returns it. Based on our function input, we should use different combinations of the output of this fetch_data function for these different test cases. The postgres connection string is given by the environment in the variable POSTGRES_CONNECTION_STRING (as specified below in the code), but you have read-only access. Therefore, you cannot commit anything to the database (i.e. you cannot use session.commit()) or delete anything from the database. You also should not mock any values from the database, as you should use the fetch_data function to retrieve the necessary data for you. Be sure to order the ORM classes such as each class comes after the classes they depend on. If the function_code uses a Base class that's not already defined, declare the Base as follows at the top of the file using DeclarativeBase (from sqlalchemy.orm).
|
|
```python
|
|
# imports
|
|
import {unit_test_package} # used for our unit tests
|
|
import os
|
|
from sqlalchemy.orm import DeclarativeBase
|
|
{{insert other imports as needed}}
|
|
|
|
POSTGRES_CONNECTION_STRING = os.environ.get("POSTGRES_CONNECTION_STRING")
|
|
|
|
class Base(DeclarativeBase):
|
|
pass
|
|
|
|
# function to test
|
|
{function_code}
|
|
|
|
# fetch data function
|
|
{fetch_data_function_code}
|
|
|
|
# unit tests
|
|
{package_comment}
|
|
{{insert unit test code here}}
|
|
```
|