Skip to content

Commit

Permalink
v9.1.6
Browse files Browse the repository at this point in the history
  • Loading branch information
Ronny Vedrilla committed Oct 31, 2023
1 parent 7ad1945 commit c26b7ba
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 7 deletions.
9 changes: 9 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,12 @@ omit =
tests/*,
testapp/*,
conftest.py

[report]
precision = 2
show_missing = True
exclude_lines =
# Don't complain if tests don't hit defensive assertion code:
raise NotImplementedError
# Ignore type checking conditions
if TYPE_CHECKING:
2 changes: 1 addition & 1 deletion ambient_toolbox/mail/backends/whitelist_smtp.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def _process_recipients(self, email_messages):
def send_messages(self, email_messages):
"""
Checks if email-recipients are in allowed domains and cancels if not.
Uses regular smtp-sending afterwards.
Uses regular smtp-sending afterward.
"""
email_messages = self._process_recipients(email_messages)
return super().send_messages(email_messages)
18 changes: 17 additions & 1 deletion tests/drf/test_fields.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from unittest import mock

import pytest
from django.test import TestCase
from rest_framework import serializers
from rest_framework.serializers import ListSerializer
from rest_framework.serializers import ListSerializer, Serializer

from ambient_toolbox.drf.fields import RecursiveField
from testapp.models import ModelWithFkToSelf, ModelWithOneToOneToSelf
Expand Down Expand Up @@ -31,6 +33,20 @@ class Meta:


class RecursiveFieldTest(TestCase):
@mock.patch.object(Serializer, "update")
def test_update_super_called(self, mocked_update):
field = RecursiveField()
field.update(instance=None, validated_data={})

mocked_update.assert_called_once_with(None, {})

@mock.patch.object(Serializer, "create")
def test_create_super_called(self, mocked_create):
field = RecursiveField()
field.create(validated_data={})

mocked_create.assert_called_once_with({})

def test_many_true_regular(self):
serializer = TestManyTrueSerializer()

Expand Down
17 changes: 17 additions & 0 deletions tests/permissions/test_install_permission_fixtures_command.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from argparse import ArgumentParser
from unittest import mock

from django.test import TestCase
Expand All @@ -12,6 +13,15 @@ class InstallPermissionFixturesCommandTest(TestCase):
def setUpTestData(cls):
super().setUpTestData()

def test_add_arguments_regular(self):
command = Command()

parser = ArgumentParser()

command.add_arguments(parser)

self.assertTrue("--dry-run" in [action.option_strings[0] for action in parser._actions])

@override_settings(GROUP_PERMISSION_FIXTURES=['testapp.permissions.TestGroupDeclaration'])
@mock.patch.object(PermissionSetupService, 'process', return_value=([], []))
def test_run_command_regular(self, mocked_process):
Expand All @@ -26,3 +36,10 @@ def test_run_command_no_settings_variable(self, mocked_process):
command.handle()

mocked_process.assert_not_called()

@mock.patch.object(PermissionSetupService, 'process')
def test_run_command_dry_run(self, mocked_process):
command = Command()
command.handle(dry_run=True)

mocked_process.assert_not_called()
13 changes: 11 additions & 2 deletions tests/test_utils_model.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.test import TestCase

from ambient_toolbox.utils import object_to_dict
from testapp.models import MySingleSignalModel
from testapp.models import ForeignKeyRelatedModel, MySingleSignalModel


class UtilModelTest(TestCase):
Expand All @@ -17,6 +17,15 @@ def test_object_to_dict_with_id_with_blacklist(self):
obj = MySingleSignalModel.objects.create(value=17)
self.assertEqual(object_to_dict(obj, ['value'], True), {'id': obj.id})

def test_object_to_dict_with_id_no_blacklist(self):
def test_with_id_no_blacklist(self):
obj = MySingleSignalModel.objects.create(value=17)
self.assertEqual(object_to_dict(obj, include_id=True), {'id': obj.id, 'value': obj.value})

def test_object_to_dict_valid_fields_append(self):
obj = MySingleSignalModel.objects.create(value=17)
dummy_instance = ForeignKeyRelatedModel(single_signal=obj)

valid_data = object_to_dict(dummy_instance)

self.assertIn('single_signal_id', valid_data)
self.assertEqual(valid_data['single_signal_id'], obj.id)
13 changes: 13 additions & 0 deletions tests/test_utils_named_tuple.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,16 @@ def test_get_key_from_tuple_by_value_found(self):

def test_get_key_from_tuple_by_value_not_found(self):
self.assertEqual(get_key_from_tuple_by_value(self.MY_CHOICE_LIST, 'Something odd'), '-')

def test_get_values_case_is_instance(self):
choices = get_namedtuple_choices(
'TestChoices',
(
(0, 'zero', 'Zero'),
(1, 'one', 'One'),
([2, 3], 'two_three', 'Two Three'),
),
)

# Überprüfen, ob die Methode get_values korrekt funktioniert
self.assertEqual(choices.get_values(), [0, 1, 2, 3])
3 changes: 0 additions & 3 deletions tests/tests/mixins/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,3 @@
class PermissionModelMixinTest(TestCase):
def test_meta_managed_false(self):
self.assertFalse(MyPermissionModelMixin.Meta.managed)

def test_meta_no_default_permissions(self):
self.assertEqual(len(MyPermissionModelMixin.Meta.default_permissions), 0)
18 changes: 18 additions & 0 deletions tests/tests/test_mail_backends.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from unittest import mock

from django.core.mail import EmailMultiAlternatives
from django.core.mail.backends.smtp import EmailBackend
from django.test import TestCase, override_settings

from ambient_toolbox.mail.backends.whitelist_smtp import WhitelistEmailBackend
Expand Down Expand Up @@ -42,3 +45,18 @@ def test_process_recipients_regular(self):
message_list = backend._process_recipients([mail])
self.assertEqual(len(message_list), 1)
self.assertEqual(message_list[0].to, ['[email protected]'])

@mock.patch.object(EmailBackend, "send_messages")
@mock.patch.object(WhitelistEmailBackend, "_process_recipients")
def test_send_messages_process_recipients_called(self, mocked_process_recipients, *args):
backend = WhitelistEmailBackend()
backend.send_messages([])

mocked_process_recipients.assert_called_once_with([])

@mock.patch.object(EmailBackend, "send_messages")
def test_send_messages_super_called(self, mocked_send_messages):
backend = WhitelistEmailBackend()
backend.send_messages([])

mocked_send_messages.assert_called_once_with([])

0 comments on commit c26b7ba

Please sign in to comment.