From c20fe588f6175f8df0ac6d51de078c65499a2dab Mon Sep 17 00:00:00 2001 From: Johanna England Date: Thu, 28 Nov 2024 16:03:03 +0100 Subject: [PATCH 1/2] Remove unused variables --- .../dev/management/commands/create_source.py | 2 +- tests/auth/test_models.py | 4 ++-- tests/incident/test_filters.py | 2 +- tests/incident/test_incident_fields.py | 16 ++++++++-------- tests/incident/test_views.py | 2 +- tests/notificationprofile/test_github236.py | 1 - tests/notificationprofile/test_serializers.py | 4 ++-- tests/notificationprofile/test_views.py | 2 +- 8 files changed, 16 insertions(+), 17 deletions(-) diff --git a/src/argus/dev/management/commands/create_source.py b/src/argus/dev/management/commands/create_source.py index ce3524ae5..25c8fd714 100644 --- a/src/argus/dev/management/commands/create_source.py +++ b/src/argus/dev/management/commands/create_source.py @@ -17,4 +17,4 @@ def handle(self, *args, **options): source_type = options.get("source_type") or "argus" sst = SourceSystemTypeFactory(name=source_type) user = SourceUserFactory(username=source) - ss = SourceSystemFactory(name=source, type=sst, user=user) + SourceSystemFactory(name=source, type=sst, user=user) diff --git a/tests/auth/test_models.py b/tests/auth/test_models.py index 28513df1e..9fc501f03 100644 --- a/tests/auth/test_models.py +++ b/tests/auth/test_models.py @@ -20,7 +20,7 @@ def test_is_end_user(self): def test_is_source_system(self): user = SourceUserFactory() - ss = SourceSystemFactory(user=user) + SourceSystemFactory(user=user) self.assertTrue(user.is_source_system) @@ -56,7 +56,7 @@ def test_is_not_dormant_if_source_of_incident(self): user = SourceUserFactory() source = SourceSystemFactory(user=user) - incident = StatelessIncidentFactory(source=source) + StatelessIncidentFactory(source=source) self.assertTrue(user.is_used()) def test_is_not_dormant_if_actor_of_event(self): diff --git a/tests/incident/test_filters.py b/tests/incident/test_filters.py index 7da1ea3e8..a73ef3890 100644 --- a/tests/incident/test_filters.py +++ b/tests/incident/test_filters.py @@ -112,7 +112,7 @@ def test_ticket_false(self): def test_tags_single(self): user = SourceUserFactory() tag1 = TagFactory(key="testkey1", value="testvalue1") - tag2 = TagFactory(key="testkey2", value="testvalue2") + TagFactory(key="testkey2", value="testvalue2") incident5 = StatefulIncidentFactory(source=self.source1) for incident in (self.incident1, self.incident2, self.incident3): IncidentTagRelation.objects.get_or_create(tag=tag1, incident=incident, added_by=user) diff --git a/tests/incident/test_incident_fields.py b/tests/incident/test_incident_fields.py index f864bf76b..1c048b581 100644 --- a/tests/incident/test_incident_fields.py +++ b/tests/incident/test_incident_fields.py @@ -113,31 +113,31 @@ class KeyValueFieldTest(TestCase): def test_key_value_must_not_be_empty(self): f = KeyValueField() with self.assertRaises(ValidationError): - result = f.clean("") + f.clean("") def test_key_value_must_not_be_just_equals(self): f = KeyValueField() with self.assertRaises(ValidationError): - result = f.clean("=") + f.clean("=") def test_key_value_must_contain_at_least_one_equals(self): f = KeyValueField() with self.assertRaises(ValidationError): - result = f.clean("boo") + f.clean("boo") def test_value_cannot_be_empty(self): f = KeyValueField() with self.assertRaises(ValidationError): - result = f.clean("a=") + f.clean("a=") def test_key_must_fit_regex(self): # [a-z0-9_]+ f = KeyValueField() with self.assertRaises(ValidationError): - result = f.clean("=v") + f.clean("=v") with self.assertRaises(ValidationError): - result = f.clean(" =v") + f.clean(" =v") with self.assertRaises(ValidationError): - result = f.clean("A=v") + f.clean("A=v") with self.assertRaises(ValidationError): - result = f.clean("-=v") + f.clean("-=v") diff --git a/tests/incident/test_views.py b/tests/incident/test_views.py index 928103a9f..1d4682b74 100644 --- a/tests/incident/test_views.py +++ b/tests/incident/test_views.py @@ -368,7 +368,7 @@ def test_source_cannot_delete_unowned_incident_if_indelible_is_False(self): source_type = SourceSystemTypeFactory() user = SourceUserFactory() - source = SourceSystemFactory(type=source_type, user=user) + SourceSystemFactory(type=source_type, user=user) self.client.force_authenticate(user=user) response = self.client.delete(path=f"/api/v2/incidents/{incident_pk}/") diff --git a/tests/notificationprofile/test_github236.py b/tests/notificationprofile/test_github236.py index 5c7d768a3..a234fc753 100644 --- a/tests/notificationprofile/test_github236.py +++ b/tests/notificationprofile/test_github236.py @@ -51,7 +51,6 @@ def tearDown(self): connect_signals() def test_sending_event_to_multiple_profiles_of_the_same_user_should_not_raise_exception(self): - LOG_PREFIX = "INFO:argus.notificationprofile.media:" # Send a test event self.incident = create_fake_incident() event = self.incident.events.get(type=Event.Type.INCIDENT_START) diff --git a/tests/notificationprofile/test_serializers.py b/tests/notificationprofile/test_serializers.py index 9369988f2..69767e023 100644 --- a/tests/notificationprofile/test_serializers.py +++ b/tests/notificationprofile/test_serializers.py @@ -91,7 +91,7 @@ def test_cannot_create_timeslot_with_duplicate_name(self): ) # serializer.create works on already validated data with self.assertRaises(IntegrityError): - obj = serializer.create(validated_data) + serializer.create(validated_data) def test_can_update_timeslot(self): timeslot = TimeslotFactory(name="existing name", user=self.user) @@ -127,4 +127,4 @@ def test_cannot_update_timeslot_with_duplicate_name(self): ) # serializer.create works on already validated data with self.assertRaises(IntegrityError): - obj = serializer.update(timeslot, validated_data) + serializer.update(timeslot, validated_data) diff --git a/tests/notificationprofile/test_views.py b/tests/notificationprofile/test_views.py index 08b5277b9..bc05cab56 100644 --- a/tests/notificationprofile/test_views.py +++ b/tests/notificationprofile/test_views.py @@ -233,7 +233,7 @@ def setUp(self): self.source2 = SourceSystemFactory(name="System 2", type=source_type2, user=source2_user) self.incident1 = StatelessIncidentFactory(source=self.source1) - incident2 = StatelessIncidentFactory(source=self.source2) + StatelessIncidentFactory(source=self.source2) timeslot1 = TimeslotFactory(user=user1, name="Never") filter1 = FilterFactory( From af85edab866ffcf0471379874ad9a8e07091fadc Mon Sep 17 00:00:00 2001 From: Johanna England Date: Thu, 28 Nov 2024 16:03:45 +0100 Subject: [PATCH 2/2] Remove unused exception object --- src/argus/notificationprofile/media/email.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/argus/notificationprofile/media/email.py b/src/argus/notificationprofile/media/email.py index 37e17a765..600490a99 100644 --- a/src/argus/notificationprofile/media/email.py +++ b/src/argus/notificationprofile/media/email.py @@ -45,7 +45,7 @@ def send_email_safely(function, additional_error=None, *args, **kwargs) -> int: try: result = function(*args, **kwargs) return result - except ConnectionRefusedError as e: + except ConnectionRefusedError: EMAIL_HOST = getattr(settings, "EMAIL_HOST", None) if not EMAIL_HOST: LOG.error("Notification: Email: EMAIL_HOST not set, cannot send")