diff --git a/tests/conftest.py b/tests/conftest.py index f512e7d5..65dbae1c 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -40,7 +40,7 @@ def _debug(settings: SettingsWrapper) -> None: template["OPTIONS"]["debug"] = True -@pytest.fixture() +@pytest.fixture def main_heading() -> str: """An example fixture containing some html fragment.""" return '
Report, manage, escalate!
' @@ -76,13 +76,13 @@ def django_db_setup( # noqa: PT004 django_db_blocker.restore() -@pytest.fixture() +@pytest.fixture def incident() -> Incident: return IncidentFactory.build() -@pytest.fixture() -@pytest.mark.django_db() +@pytest.fixture +@pytest.mark.django_db def incident_saved() -> Incident: incident: Incident = IncidentFactory.build() incident.component.group.save() diff --git a/tests/test_api/test_api_urls.py b/tests/test_api/test_api_urls.py index 06a51b04..999c1a97 100644 --- a/tests/test_api/test_api_urls.py +++ b/tests/test_api/test_api_urls.py @@ -22,7 +22,7 @@ def test_api_schema(client: Client) -> None: assert response.status_code == 200 -@pytest.mark.django_db() +@pytest.mark.django_db def test_incidents_cost_api(admin_client: Client, admin_user: User) -> None: """This test ensures that the incidents costs API endpoint is accessible for an admin""" admin_client.force_login(admin_user) @@ -31,7 +31,7 @@ def test_incidents_cost_api(admin_client: Client, admin_user: User) -> None: assert response.status_code == 200 -@pytest.mark.django_db() +@pytest.mark.django_db def test_incidents_cost_api_unauthorized(client: Client) -> None: """This test ensures that the incidents costs API endpoint is not accessible for a guest user""" user = UserFactory.create() @@ -41,7 +41,7 @@ def test_incidents_cost_api_unauthorized(client: Client) -> None: assert response.status_code == 403 -@pytest.mark.django_db() +@pytest.mark.django_db def test_incidents_cost_type_api(admin_client: Client, admin_user: User) -> None: """This test ensures that the incidents cost types API endpoint is accessible for an admin""" admin_client.force_login(admin_user) @@ -50,7 +50,7 @@ def test_incidents_cost_type_api(admin_client: Client, admin_user: User) -> None assert response.status_code == 200 -@pytest.mark.django_db() +@pytest.mark.django_db def test_incidents_cost_api_type_unauthorized(client: Client) -> None: """This test ensures that the incidents costs API endpoint is not accessible for a guest user""" user = UserFactory.create() diff --git a/tests/test_firefighter/test_urls.py b/tests/test_firefighter/test_urls.py index 8458a2e9..5e0566a5 100644 --- a/tests/test_firefighter/test_urls.py +++ b/tests/test_firefighter/test_urls.py @@ -17,7 +17,7 @@ logger = logging.getLogger(__name__) -@pytest.mark.django_db() +@pytest.mark.django_db def test_health_check(client: Client) -> None: """This test ensures that health check is accessible.""" response = client.get("/api/v2/firefighter/monitoring/healthcheck") @@ -25,7 +25,7 @@ def test_health_check(client: Client) -> None: assert response.status_code == 200 -@pytest.mark.django_db() +@pytest.mark.django_db def test_admin_unauthorized(client: Client) -> None: """This test ensures that admin panel requires auth.""" response = client.get("/admin/") @@ -33,7 +33,7 @@ def test_admin_unauthorized(client: Client) -> None: assert response.status_code == 302 -@pytest.mark.django_db() +@pytest.mark.django_db @pytest.mark.usefixtures("_debug") def test_admin_authorized(admin_client: Client, admin_user: User) -> None: """This test ensures that admin panel is accessible.""" @@ -44,7 +44,7 @@ def test_admin_authorized(admin_client: Client, admin_user: User) -> None: assert response.status_code == 200 -@pytest.mark.django_db() +@pytest.mark.django_db def test_admin_docs_unauthorized(client: Client) -> None: """This test ensures that admin panel docs requires auth.""" response = client.get("/admin/doc/") @@ -54,7 +54,7 @@ def test_admin_docs_unauthorized(client: Client) -> None: assert response.url == "/admin/login/?next=/admin/doc/" -@pytest.mark.django_db() +@pytest.mark.django_db def test_admin_docs_authorized(admin_client: Client) -> None: """This test ensures that admin panel docs are accessible.""" response = admin_client.get("/admin/doc/") @@ -63,7 +63,7 @@ def test_admin_docs_authorized(admin_client: Client) -> None: assert b"docutils" not in response.content -@pytest.mark.django_db() +@pytest.mark.django_db def test_robotstxt_present(client: Client) -> None: """This test ensures that robots.txt is present.""" response = client.get("/robots.txt") @@ -72,7 +72,7 @@ def test_robotstxt_present(client: Client) -> None: assert b"Disallow: /" in response.content -@pytest.mark.django_db() +@pytest.mark.django_db def test_login_sso_button_admin_login(client: Client) -> None: """This test ensures that login page contains the SSO button.""" response = client.get("/admin/login/") @@ -81,7 +81,7 @@ def test_login_sso_button_admin_login(client: Client) -> None: assert b"Log in with SSO" in response.content -@pytest.mark.django_db() +@pytest.mark.django_db def test_error_500_pretty(client: Client) -> None: """This test ensures that 500 error page is pretty.""" with pytest.raises(Exception, match="Test exception for 500"): # noqa: PT012 @@ -91,7 +91,7 @@ def test_error_500_pretty(client: Client) -> None: assert b"Please try again later, and report it" in response.content -@pytest.mark.django_db() +@pytest.mark.django_db def test_error_404_pretty(client: Client) -> None: """This test ensures that 404 error page is pretty.""" response = client.get("/err/404/") @@ -100,7 +100,7 @@ def test_error_404_pretty(client: Client) -> None: assert b"Please check the URL in the address bar and try again" in response.content -@pytest.mark.django_db() +@pytest.mark.django_db def test_error_403_pretty(client: Client) -> None: """This test ensures that 403 error page is pretty.""" response = client.get("/err/403/") @@ -109,7 +109,7 @@ def test_error_403_pretty(client: Client) -> None: assert b"You do not have permission to access this page." in response.content -@pytest.mark.django_db() +@pytest.mark.django_db def test_error_400_pretty(client: Client) -> None: """This test ensures that 400 error page is pretty.""" response = client.get("/err/400/") @@ -129,7 +129,7 @@ def test_errors_json(client: Client) -> None: assert json.loads(response.content).get("error") is not None -@pytest.mark.django_db() +@pytest.mark.django_db @pytest.mark.timeout(30) @pytest.mark.usefixtures("_debug") def test_all_admin_list_no_error(admin_client: Client, admin_user: User) -> None: diff --git a/tests/test_incidents/test_forms/test_form_select_impact.py b/tests/test_incidents/test_forms/test_form_select_impact.py index a7994e36..a97df347 100644 --- a/tests/test_incidents/test_forms/test_form_select_impact.py +++ b/tests/test_incidents/test_forms/test_form_select_impact.py @@ -5,7 +5,7 @@ from firefighter.incidents.forms.select_impact import SelectImpactForm -@pytest.mark.django_db() +@pytest.mark.django_db @pytest.mark.parametrize( ("form_data", "expected_priority"), [ @@ -63,7 +63,7 @@ def test_suggest_priority_from_impact(form_data, expected_priority): assert priority == expected_priority -@pytest.mark.django_db() +@pytest.mark.django_db @pytest.mark.parametrize( ("form_data", "expected_priority"), [ @@ -96,7 +96,7 @@ def test_suggest_priority_from_impact(form_data, expected_priority): ), ], ) -@pytest.mark.django_db() +@pytest.mark.django_db def test_suggest_priority_from_impact_with_invalid_form(form_data, expected_priority): form = SelectImpactForm(data=form_data) assert not form.is_valid() diff --git a/tests/test_incidents/test_forms/test_form_utils.py b/tests/test_incidents/test_forms/test_form_utils.py index fa138dcb..599e3b90 100644 --- a/tests/test_incidents/test_forms/test_form_utils.py +++ b/tests/test_incidents/test_forms/test_form_utils.py @@ -20,12 +20,12 @@ class GroupedModelChoiceFieldForm(Form): ) -@pytest.fixture() +@pytest.fixture def group() -> Group: return Group.objects.create(name="Group 1") -@pytest.fixture() +@pytest.fixture def components(group: Group): return [ Component.objects.create(name="Component 1", group=group, order=1), @@ -46,7 +46,7 @@ def test_enum_choice_field_invalid() -> None: assert "status" in form.errors -@pytest.mark.django_db() +@pytest.mark.django_db def test_grouped_model_choice_field_valid(components: list[Component]): form = GroupedModelChoiceFieldForm({"component": components[0].id}) assert form.is_valid() diff --git a/tests/test_incidents/test_forms/test_update_key_events.py b/tests/test_incidents/test_forms/test_update_key_events.py index 7d8b7bf8..7ff3e3fb 100644 --- a/tests/test_incidents/test_forms/test_update_key_events.py +++ b/tests/test_incidents/test_forms/test_update_key_events.py @@ -10,12 +10,12 @@ from firefighter.incidents.models.milestone_type import MilestoneType -@pytest.fixture() +@pytest.fixture def user() -> User: return User.objects.create_user(username="testuser") -@pytest.fixture() +@pytest.fixture def milestone_type() -> MilestoneType: return MilestoneType( event_type="detected", @@ -26,7 +26,7 @@ def milestone_type() -> MilestoneType: ) -@pytest.mark.django_db() +@pytest.mark.django_db def test_incident_update_key_events_form( user: User, incident_saved: Incident, milestone_type: MilestoneType ): diff --git a/tests/test_incidents/test_incident_urls.py b/tests/test_incidents/test_incident_urls.py index 6c1b58a5..83ed1b6f 100644 --- a/tests/test_incidents/test_incident_urls.py +++ b/tests/test_incidents/test_incident_urls.py @@ -16,7 +16,7 @@ logger = logging.getLogger(__name__) -@pytest.mark.django_db() +@pytest.mark.django_db def test_incidents_dashboard_unauthorized(client: Client) -> None: """This test ensures that the incidents dashboard is not accessible, and that we are redirect to auth.""" response = client.get(reverse("incidents:dashboard")) @@ -24,7 +24,7 @@ def test_incidents_dashboard_unauthorized(client: Client) -> None: assert response.status_code == 302 -@pytest.mark.django_db() +@pytest.mark.django_db def test_incidents_list_unauthorized(client: Client) -> None: """This test ensures that the incidents page list is accessible.""" response = client.get(reverse("incidents:incident-list")) @@ -32,7 +32,7 @@ def test_incidents_list_unauthorized(client: Client) -> None: assert response.status_code == 302 -@pytest.mark.django_db() +@pytest.mark.django_db @pytest.mark.usefixtures("_debug") def test_incidents_statistics_unauthorized(client: Client) -> None: """This test ensures that the incidents statistics page is accessible.""" @@ -41,7 +41,7 @@ def test_incidents_statistics_unauthorized(client: Client) -> None: assert response.status_code == 302 -@pytest.mark.django_db() +@pytest.mark.django_db @pytest.mark.usefixtures("_debug") def test_incidents_dashboard_authorized(admin_client: Client, admin_user: User) -> None: """This test ensures that the incidents dashboard is accessible for an admin.""" @@ -51,7 +51,7 @@ def test_incidents_dashboard_authorized(admin_client: Client, admin_user: User) assert response.status_code == 200 -@pytest.mark.django_db() +@pytest.mark.django_db @pytest.mark.usefixtures("_debug") def test_incidents_details(client: Client, admin_user: User) -> None: """This test ensures that the incidents dashboard is accessible for an admin.""" @@ -65,7 +65,7 @@ def test_incidents_details(client: Client, admin_user: User) -> None: assert response.status_code == 200 -@pytest.mark.django_db() +@pytest.mark.django_db @pytest.mark.usefixtures("_debug") def test_incidents_details_unauthorized_404_redirect(client: Client) -> None: """This test ensures that the incidents dashboard will return a 404.""" @@ -76,7 +76,7 @@ def test_incidents_details_unauthorized_404_redirect(client: Client) -> None: assert response.status_code == 302 -@pytest.mark.django_db() +@pytest.mark.django_db @pytest.mark.usefixtures("_debug") def test_incidents_details_authorized_404(client: Client, admin_user: User) -> None: """This test ensures that the incidents dashboard will return a 404.""" @@ -88,7 +88,7 @@ def test_incidents_details_authorized_404(client: Client, admin_user: User) -> N assert response.status_code == 404 -@pytest.mark.django_db() +@pytest.mark.django_db @pytest.mark.usefixtures("_debug") def test_incident_create_unauthorized(client: Client) -> None: """This test ensures that the incident create page is accessible.""" @@ -98,7 +98,7 @@ def test_incident_create_unauthorized(client: Client) -> None: assert response.status_code == 302 -@pytest.mark.django_db() +@pytest.mark.django_db @pytest.mark.usefixtures("_debug") def test_component_list(client: Client) -> None: """This test ensures that the component list is accessible.""" @@ -107,7 +107,7 @@ def test_component_list(client: Client) -> None: assert response.status_code == 302 -@pytest.mark.django_db() +@pytest.mark.django_db @pytest.mark.usefixtures("_debug") def test_incident_list(client: Client) -> None: """This test ensures that the incident list is accessible.""" diff --git a/tests/test_incidents/test_models/test_incident_model.py b/tests/test_incidents/test_models/test_incident_model.py index 850de072..05fb5e7a 100644 --- a/tests/test_incidents/test_models/test_incident_model.py +++ b/tests/test_incidents/test_models/test_incident_model.py @@ -13,7 +13,7 @@ from firefighter.incidents.models import Incident -@pytest.mark.django_db() +@pytest.mark.django_db class TestIncident(django.TestCase): """This is a property-based test that ensures model correctness.""" diff --git a/tests/test_incidents/test_views/test_incident_detail_view.py b/tests/test_incidents/test_views/test_incident_detail_view.py index 5131562a..c8333f40 100644 --- a/tests/test_incidents/test_views/test_incident_detail_view.py +++ b/tests/test_incidents/test_views/test_incident_detail_view.py @@ -8,7 +8,7 @@ from firefighter.incidents.models.user import User -@pytest.mark.django_db() +@pytest.mark.django_db def test_incident_detail_view( client: Client, main_heading: str, incident_saved: Incident, admin_user: User ) -> None: diff --git a/tests/test_incidents/test_views/test_index_view.py b/tests/test_incidents/test_views/test_index_view.py index b78a737e..78ca8cad 100644 --- a/tests/test_incidents/test_views/test_index_view.py +++ b/tests/test_incidents/test_views/test_index_view.py @@ -7,7 +7,7 @@ from firefighter.incidents.models.user import User -@pytest.mark.django_db() +@pytest.mark.django_db def test_main_page(client: Client, main_heading: str, admin_user: User) -> None: """This test ensures that main page works.""" client.force_login(admin_user) @@ -17,7 +17,7 @@ def test_main_page(client: Client, main_heading: str, admin_user: User) -> None: assert main_heading in str(response.content) -@pytest.mark.django_db() +@pytest.mark.django_db def test_hello_page(client: Client, main_heading: str, admin_user: User) -> None: """This test ensures that dashboard page works.""" client.force_login(admin_user) diff --git a/tests/test_raid/test_raid_client_users.py b/tests/test_raid/test_raid_client_users.py index 4d8d2343..eafe3e0c 100644 --- a/tests/test_raid/test_raid_client_users.py +++ b/tests/test_raid/test_raid_client_users.py @@ -38,7 +38,7 @@ def user(self, *args: Any, **kwargs: Any): ) -@pytest.fixture() +@pytest.fixture def user() -> User: return User.objects.create( name="John Doe", @@ -47,7 +47,7 @@ def user() -> User: ) -@pytest.fixture() +@pytest.fixture def not_user() -> User: return User.objects.create( name="John Does Not Exist", @@ -56,12 +56,12 @@ def not_user() -> User: ) -@pytest.fixture() +@pytest.fixture def raid_client() -> MockJiraClient: return MockJiraClient() -@pytest.mark.django_db() +@pytest.mark.django_db def test_get_jira_user_from_user( raid_client: MockJiraClient, user: User, mocker: MockerFixture ): @@ -80,7 +80,7 @@ def test_get_jira_user_from_user( assert jira_user.user.email == "johndoe@example.com" -@pytest.mark.django_db() +@pytest.mark.django_db def test_get_jira_user_from_user_in_db( raid_client: MockJiraClient, user: User, mocker: MockerFixture ): @@ -96,14 +96,14 @@ def test_get_jira_user_from_user_in_db( _search_users.assert_not_called() -@pytest.mark.django_db() +@pytest.mark.django_db def test_get_jira_user_from_jira_id(raid_client: MockJiraClient): # Test when the Jira ID is valid and exists in Jira jira_user = raid_client.get_jira_user_from_jira_id("123") assert jira_user.user.email == "johndoe@example.com" -@pytest.mark.django_db() +@pytest.mark.django_db def test_get_jira_user_from_jira_id_user_already_exists( raid_client: MockJiraClient, user: User ): @@ -112,7 +112,7 @@ def test_get_jira_user_from_jira_id_user_already_exists( assert jira_user.user.email == "johndoe@example.com" -@pytest.mark.django_db() +@pytest.mark.django_db def test_get_jira_user_from_jira_id_invalid_id(raid_client: MockJiraClient, user: User): with pytest.raises(ValueError, match="Jira account id is empty"): raid_client.get_jira_user_from_jira_id(None) # type: ignore diff --git a/tests/test_slack/conftest.py b/tests/test_slack/conftest.py index b513504e..8ecde95b 100644 --- a/tests/test_slack/conftest.py +++ b/tests/test_slack/conftest.py @@ -21,23 +21,23 @@ # Fixture to create a SlackUser instance -@pytest.fixture() +@pytest.fixture def slack_user_saved() -> SlackUser: user = UserFactory.create() return SlackUserFactory.create(user=user) -@pytest.fixture() +@pytest.fixture def conversation() -> Conversation: return SlackConversationFactory.create() -@pytest.fixture() +@pytest.fixture def user() -> User: return UserFactory() -@pytest.fixture() +@pytest.fixture def slack_user(user: User) -> SlackUser: return SlackUserFactory.create(user=user) @@ -56,11 +56,11 @@ def __init__(self, *args: Any, **kwargs: Any) -> None: self.conversations_join = MagicMock() # type: ignore[method-assign] -@pytest.fixture() +@pytest.fixture def mock_web_client() -> MockWebClient: return MockWebClient() -@pytest.fixture() +@pytest.fixture def incident_channel(incident_saved: Incident) -> IncidentChannel: return IncidentChannelFactory.create(incident=incident_saved) diff --git a/tests/test_slack/test_models/test_conversations.py b/tests/test_slack/test_models/test_conversations.py index fd565d20..a13c8189 100644 --- a/tests/test_slack/test_models/test_conversations.py +++ b/tests/test_slack/test_models/test_conversations.py @@ -6,7 +6,7 @@ from tests.test_slack.conftest import MockWebClient -@pytest.mark.django_db() +@pytest.mark.django_db def test_update_topic( conversation: Conversation, mock_web_client: MockWebClient ) -> None: @@ -16,7 +16,7 @@ def test_update_topic( assert mock_web_client.conversations_setTopic.called -@pytest.mark.django_db() +@pytest.mark.django_db def test_conversations_join( conversation: Conversation, mock_web_client: MockWebClient ) -> None: diff --git a/tests/test_slack/test_models/test_incident_channel.py b/tests/test_slack/test_models/test_incident_channel.py index ec0f721a..3717372f 100644 --- a/tests/test_slack/test_models/test_incident_channel.py +++ b/tests/test_slack/test_models/test_incident_channel.py @@ -20,12 +20,12 @@ from tests.test_slack.conftest import MockWebClient -@pytest.fixture() +@pytest.fixture def users_mapped() -> list[User]: return UserFactory.create_batch(5) -@pytest.mark.django_db() +@pytest.mark.django_db def test_get_active_slack_users( incident_channel: IncidentChannel, users_mapped: list[User] ): @@ -45,7 +45,7 @@ def test_get_active_slack_users( assert all(user.is_active for user in active_users) -@pytest.mark.django_db() +@pytest.mark.django_db def test_get_slack_id_list(incident_channel: IncidentChannel, users_mapped: list[User]): slack_ids = {f"slack_id{i}" for i in range(len(users_mapped))} for user, slack_id in zip(users_mapped, slack_ids, strict=True): @@ -57,7 +57,7 @@ def test_get_slack_id_list(incident_channel: IncidentChannel, users_mapped: list assert retrieved_slack_ids == slack_ids -@pytest.mark.django_db() +@pytest.mark.django_db def test_invite_users_with_slack_id( incident_channel: IncidentChannel, users_mapped: list[User], @@ -78,7 +78,7 @@ def test_invite_users_with_slack_id( ) -@pytest.mark.django_db() +@pytest.mark.django_db def test_invite_users_to_conversation_individually( incident_channel: IncidentChannel, users_mapped: list[User], @@ -105,7 +105,7 @@ def test_invite_users_to_conversation_individually( assert invited_slack_ids == user_slack_ids -@pytest.mark.django_db() +@pytest.mark.django_db def test_invite_users_to_conversation_individually_single_failure( incident_channel: IncidentChannel, users_mapped: list[User], @@ -141,7 +141,7 @@ def side_effect(args: Any, kwargs: Any) -> Any: ) # individual invite was called once for each user -@pytest.mark.django_db() +@pytest.mark.django_db def test_invite_users_to_conversation_batch_success( incident_channel: IncidentChannel, users_mapped: list[User], @@ -168,7 +168,7 @@ def test_invite_users_to_conversation_batch_success( ) # batch invite was called once -@pytest.mark.django_db() +@pytest.mark.django_db def test_invite_users_to_conversation_batch_fail( incident_channel: IncidentChannel, users_mapped: list[User], @@ -209,7 +209,7 @@ def test_invite_users_to_conversation_batch_fail( # XXX(dugab): Deduplicate tests -@pytest.mark.django_db() +@pytest.mark.django_db def test_invite_users(incident_channel: IncidentChannel, mock_web_client: WebClient): # Prepare test data incident_channel.channel_id = "test_channel" @@ -246,7 +246,7 @@ def test_invite_users(incident_channel: IncidentChannel, mock_web_client: WebCli assert set(incident_channel.incident.members.all()) == set(users) -@pytest.mark.django_db() +@pytest.mark.django_db def test_invite_users_one( incident_channel: IncidentChannel, user, slack_user, mock_web_client: WebClient ): @@ -258,7 +258,7 @@ def test_invite_users_one( assert slack_user.user in incident_channel.incident.members.all() -@pytest.mark.django_db() +@pytest.mark.django_db def test_invite_users_one_no_slack( incident_channel: IncidentChannel, mock_web_client: WebClient ): @@ -298,7 +298,7 @@ def test_invite_users_one_no_slack( # assert -@pytest.mark.django_db() +@pytest.mark.django_db def test_invite_users_all_inactive( incident_channel: IncidentChannel, caplog: pytest.LogCaptureFixture ): @@ -323,7 +323,7 @@ def test_invite_users_all_inactive( ) -@pytest.mark.django_db() +@pytest.mark.django_db def test_channel_name_from_incident_no_argument( incident_channel: IncidentChannel, incident_saved: Incident ) -> None: @@ -332,7 +332,7 @@ def test_channel_name_from_incident_no_argument( assert incident_channel.channel_name_from_incident() == expected_channel_name -@pytest.mark.django_db() +@pytest.mark.django_db def test_channel_name_from_incident_argument_matches( incident_channel: IncidentChannel, incident_saved: Incident ): @@ -344,7 +344,7 @@ def test_channel_name_from_incident_argument_matches( ) -@pytest.mark.django_db() +@pytest.mark.django_db def test_channel_name_from_incident_argument_does_not_match( incident_channel: IncidentChannel, incident_saved: Incident ): @@ -361,7 +361,7 @@ def test_channel_name_from_incident_argument_does_not_match( ) -@pytest.mark.django_db() +@pytest.mark.django_db def test_rename_if_needed_no_rename(incident_channel: IncidentChannel): incident_channel.channel_name_from_incident = MagicMock() incident_channel.channel_name_from_incident.return_value = incident_channel.name @@ -370,7 +370,7 @@ def test_rename_if_needed_no_rename(incident_channel: IncidentChannel): incident_channel.save.assert_not_called() -@pytest.mark.django_db() +@pytest.mark.django_db def test_rename_if_needed_slack_api_error( incident_channel: IncidentChannel, mock_web_client: MockWebClient ): @@ -387,7 +387,7 @@ def test_rename_if_needed_slack_api_error( incident_channel.save.assert_not_called() -@pytest.mark.django_db() +@pytest.mark.django_db def test_rename_if_needed_success( incident_channel: IncidentChannel, mock_web_client: MockWebClient ): @@ -409,7 +409,7 @@ def test_rename_if_needed_success( incident_channel.save.assert_called_once() -@pytest.mark.django_db() +@pytest.mark.django_db def test_rename_if_needed(incident_channel: IncidentChannel): mock_client = MagicMock(spec=WebClient) mock_client.conversations_rename.return_value = { @@ -464,7 +464,7 @@ def test_rename_if_needed(incident_channel: IncidentChannel): assert incident_channel.name == "incident-renamed" -@pytest.mark.django_db() +@pytest.mark.django_db def test_set_incident_channel_topic(incident_channel: IncidentChannel) -> None: mock_client = MagicMock(spec=WebClient) mock_client.conversations_setTopic.return_value = {"ok": True} @@ -473,7 +473,7 @@ def test_set_incident_channel_topic(incident_channel: IncidentChannel) -> None: assert mock_client.conversations_setTopic.called -@pytest.mark.django_db() +@pytest.mark.django_db def test_archive_channel(incident_channel: IncidentChannel) -> None: mock_client = MagicMock(spec=WebClient) mock_client.conversations_archive.return_value = {"ok": True} @@ -485,7 +485,7 @@ def test_archive_channel(incident_channel: IncidentChannel) -> None: assert mock_client.conversations_archive.called -@pytest.mark.django_db() +@pytest.mark.django_db def test_rename_if_needed_error(incident_channel: IncidentChannel) -> None: mock_client = MagicMock(spec=WebClient) mock_client.conversations_rename.side_effect = SlackApiError( diff --git a/tests/test_slack/test_models/test_slack_user.py b/tests/test_slack/test_models/test_slack_user.py index e9020027..7ca38c1a 100644 --- a/tests/test_slack/test_models/test_slack_user.py +++ b/tests/test_slack/test_models/test_slack_user.py @@ -30,7 +30,7 @@ } -@pytest.fixture() +@pytest.fixture def valid_user_info() -> dict[str, dict[str, Any] | Any]: return { "ok": True, @@ -64,7 +64,7 @@ def test_unpack_user_info() -> None: assert unpacked_user_info["deleted"] is False -@pytest.mark.django_db() +@pytest.mark.django_db def test_slack_user_link(slack_user_saved: SlackUser): link = slack_user_saved.link @@ -72,7 +72,7 @@ def test_slack_user_link(slack_user_saved: SlackUser): assert f"&id={slack_user_saved.slack_id}" in link -@pytest.mark.django_db() +@pytest.mark.django_db def test_update_user_info(slack_user_saved: SlackUser, mock_web_client: MockWebClient): slack_user = slack_user_saved @@ -103,7 +103,7 @@ def test_update_user_info(slack_user_saved: SlackUser, mock_web_client: MockWebC assert updated_user.email != slack_user.user.email -@pytest.mark.django_db() +@pytest.mark.django_db def test_update_user_info_slack_api_error( slack_user_saved: SlackUser, mock_web_client: MockWebClient ): @@ -133,7 +133,7 @@ def test_update_user_info_slack_api_error( assert updated_slack_user.image == slack_user.image -@pytest.mark.django_db() +@pytest.mark.django_db def test_update_user_info_empty_response( slack_user_saved: SlackUser, mock_web_client: MockWebClient ): @@ -163,7 +163,7 @@ def test_update_user_info_empty_response( # Add these test functions to your test file -@pytest.mark.django_db() +@pytest.mark.django_db def test_unpack_user_info_bot(valid_user_info: dict[str, Any]): valid_user_info["user"]["is_bot"] = True unpacked_user_info = SlackUser.objects.unpack_user_info(valid_user_info) @@ -171,7 +171,7 @@ def test_unpack_user_info_bot(valid_user_info: dict[str, Any]): assert unpacked_user_info["name"] == valid_user_info["user"]["profile"]["real_name"] -@pytest.mark.django_db() +@pytest.mark.django_db def test_unpack_user_info_no_image(valid_user_info): valid_user_info["user"]["profile"]["image_512"] = None valid_user_info["user"]["profile"]["image_192"] = None @@ -179,7 +179,7 @@ def test_unpack_user_info_no_image(valid_user_info): assert "image" not in unpacked_user_info -@pytest.mark.django_db() +@pytest.mark.django_db def test_link(slack_user_saved: SlackUser): slack_user = slack_user_saved expected_link = ( @@ -188,7 +188,7 @@ def test_link(slack_user_saved: SlackUser): assert slack_user.link == expected_link -@pytest.mark.django_db() +@pytest.mark.django_db def test_str_representation(slack_user_saved: SlackUser): slack_user = slack_user_saved assert str(slack_user) == slack_user.slack_id diff --git a/tests/test_slack/test_slack_utils.py b/tests/test_slack/test_slack_utils.py index 62a5f3b2..64df1fdf 100644 --- a/tests/test_slack/test_slack_utils.py +++ b/tests/test_slack/test_slack_utils.py @@ -9,12 +9,12 @@ from firefighter.slack.utils import respond -@pytest.fixture() +@pytest.fixture def mock_slack_client() -> MagicMock: return MagicMock() -@pytest.fixture() +@pytest.fixture def body_channel() -> dict[str, str]: return { "channel_id": "C12345", @@ -22,22 +22,22 @@ def body_channel() -> dict[str, str]: } -@pytest.fixture() +@pytest.fixture def body_dm() -> dict[str, str]: return {"channel_name": "directmessage", "user_id": "U12345"} -@pytest.fixture() +@pytest.fixture def body_no_user_id() -> dict[str, str | dict[str, str]]: return {"channel_id": "C12345", "user": {"id": "U12345"}} -@pytest.fixture() +@pytest.fixture def body_no_channel_id() -> dict[str, str | dict[str, str]]: return {"channel": {"id": "C12345"}, "user_id": "U12345"} -@pytest.fixture() +@pytest.fixture def body_view_submission() -> dict[str, str]: return {"type": "view_submission", "channel_id": "C12345", "user_id": "U12345"} diff --git a/tests/test_slack/views/modals/test_close.py b/tests/test_slack/views/modals/test_close.py index f6cb960d..eb18f2f4 100644 --- a/tests/test_slack/views/modals/test_close.py +++ b/tests/test_slack/views/modals/test_close.py @@ -15,7 +15,7 @@ logger = logging.getLogger(__name__) -@pytest.mark.django_db() +@pytest.mark.django_db class TestCloseModal: @staticmethod def test_close_modal_build(mocker: MockerFixture) -> None: diff --git a/tests/test_slack/views/modals/test_open.py b/tests/test_slack/views/modals/test_open.py index 723a27e7..a077bdf8 100644 --- a/tests/test_slack/views/modals/test_open.py +++ b/tests/test_slack/views/modals/test_open.py @@ -25,17 +25,17 @@ def build_opening_data(**kwargs: Any) -> OpeningData: return data -@pytest.fixture() +@pytest.fixture def open_incident_context() -> OpeningData: return build_opening_data() -@pytest.fixture() +@pytest.fixture def user() -> User: return User(username="testuser", email="testuser@example.com") -@pytest.fixture() +@pytest.fixture def ack() -> MagicMock: return MagicMock() @@ -54,7 +54,7 @@ def test_get_done_review_blocks_can_submit_false( assert len(blocks) == 0 -@pytest.mark.django_db() +@pytest.mark.django_db def test_check_impact_form_invalid(open_incident_context: OpeningData) -> None: open_incident_context["impact_form_data"] = {"impact": "invalid"} # type: ignore[dict-item] result = OpenModal._check_impact_form(open_incident_context) @@ -112,7 +112,7 @@ def test_build_response_type_blocks_bis(open_incident_context: OpeningData) -> N assert all(isinstance(element, ButtonElement) for element in first_block.elements) -@pytest.mark.django_db() +@pytest.mark.django_db def test_build_modal_fn_empty(user: User) -> None: open_incident_context = OpeningData() view = OpenModal().build_modal_fn(open_incident_context, user=user) diff --git a/tests/test_slack/views/modals/test_send_sos.py b/tests/test_slack/views/modals/test_send_sos.py index 60a13d21..47e10ca6 100644 --- a/tests/test_slack/views/modals/test_send_sos.py +++ b/tests/test_slack/views/modals/test_send_sos.py @@ -12,10 +12,10 @@ logger = logging.getLogger(__name__) -@pytest.mark.django_db() +@pytest.mark.django_db class TestSendSosModal: @staticmethod - @pytest.fixture() + @pytest.fixture def incident() -> Incident: """Returns a valid incident.""" return IncidentFactory.build() diff --git a/tests/test_slack/views/modals/test_status.py b/tests/test_slack/views/modals/test_status.py index 8425dcc2..ed941d65 100644 --- a/tests/test_slack/views/modals/test_status.py +++ b/tests/test_slack/views/modals/test_status.py @@ -12,10 +12,10 @@ logger = logging.getLogger(__name__) -@pytest.mark.django_db() +@pytest.mark.django_db class TestStatusModal: @staticmethod - @pytest.fixture() + @pytest.fixture def incident() -> Incident: """Returns a valid incident.""" return IncidentFactory.build() diff --git a/tests/test_slack/views/modals/test_update_status.py b/tests/test_slack/views/modals/test_update_status.py index b22e67b7..baf262b7 100644 --- a/tests/test_slack/views/modals/test_update_status.py +++ b/tests/test_slack/views/modals/test_update_status.py @@ -15,10 +15,10 @@ SLACK_SEVERITY_HELP_GUIDE_URL = settings.SLACK_SEVERITY_HELP_GUIDE_URL -@pytest.mark.django_db() +@pytest.mark.django_db class TestUpdateStatusModal: @staticmethod - @pytest.fixture() + @pytest.fixture def incident() -> Incident: """Returns a valid incident.""" return IncidentFactory.build()