Skip to content

Commit

Permalink
finish migration to pytest
Browse files Browse the repository at this point in the history
  • Loading branch information
NickTracker committed Aug 26, 2024
1 parent 96cd2a7 commit dbd687c
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 666 deletions.
12 changes: 9 additions & 3 deletions .github/workflows/python-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,19 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r server/requirements.txt
pip install -r requirements.txt
pip install pytest pytest-asyncio
working-directory: ./server

- name: Debug Environment Variables
run: |
echo "Printing environment variables:"
env | sort
- name: Run tests
run: |
python -m unittest discover server/app/tests
pytest -v -s --asyncio-mode=auto app/tests/test_should_parse_activations_async_test.py
working-directory: ./server
env:
PYTHONPATH: ${{ github.workspace }}/server
PYTEST_ADDOPTS: "--asyncio-mode=auto"
69 changes: 68 additions & 1 deletion server/app/tests/test_should_parse_activations_async_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -669,4 +669,71 @@ def setup_six_tasks_across_two_contacts_and_one_account(self, account_id):
add_mock_response(
"fetch_contacts_by_account_ids",
get_n_mock_contacts_for_account(2, account_id),
)
)

@pytest.mark.asyncio
@patch(
"app.salesforce_api._fetch_sobjects_async",
side_effect=mock_fetch_sobjects_async,
)
@patch("requests.get", side_effect=response_based_on_query)
async def test_should_update_activation_status_to_opportunity_created_without_additional_task(
self, mock_sobject_fetch, async_mock_sobject_fetch
):
with self.app.app_context():
# Set up the initial activation
self.setup_one_activity_per_contact_with_staggered_created_dates_and_one_event_under_a_single_account_and_one_opportunity_for_a_different_account()

initial_activations = await self.assert_and_return_payload_async(
asyncio.to_thread(self.client.post, "/fetch_prospecting_activity", headers=self.api_header)
)

meeting_set_activation = next(
a for a in initial_activations if a["status"] == "Meeting Set"
)

# Create a new opportunity for the account with "Meeting Set" status
mock_opportunity = get_mock_opportunity_for_account(
meeting_set_activation["account"]["id"]
)
mock_opportunity["Amount"] = 6969.42

add_mock_response(
"fetch_opportunities_by_account_ids_from_date",
[mock_opportunity],
)

# No new tasks
mock_contacts = get_n_mock_contacts_for_account(
1, meeting_set_activation["account"]["id"]
)
# mock twice since two different queries are being made against same endpoint
add_mock_response("fetch_contacts_by_account_ids", mock_contacts)
add_mock_response("fetch_contacts_by_account_ids", mock_contacts)
add_mock_response("contains_content_criteria_query", [])
add_mock_response("unique_values_content_criteria_query", [])
add_mock_response("fetch_events_by_account_ids_from_date", [])
add_mock_response("fetch_accounts_not_in_ids", [])

# Fetch updated activations
updated_activations = await self.assert_and_return_payload_async(
asyncio.to_thread(self.client.post, "/fetch_prospecting_activity", headers=self.api_header)
)

# Find the activation that should have been updated
updated_activation = next(
(
a
for a in updated_activations
if a["account"]["id"] == meeting_set_activation["account"]["id"]
),
None,
)

# Assert that the activation exists and has been updated
assert updated_activation is not None, "The activation should still exist"
assert updated_activation["status"] == "Opportunity Created", "Status should be 'Opportunity Created'"
assert updated_activation["opportunity"]["amount"] == 6969.42, "Opportunity amount should be updated"

# Check that no new prospecting effort was added
assert len(updated_activation["prospecting_effort"]) == len(meeting_set_activation["prospecting_effort"]), "No new prospecting effort should be added"
Loading

0 comments on commit dbd687c

Please sign in to comment.