Skip to content

Admin

Admin for activity package.

ActivityTypeAdmin

Bases: ModelAdmin

Admin page for Activity Type model

Factories

Test factories for activity package.

ActivityTypeFactory

Bases: DjangoModelFactory

Factory class for activity type models.

generate_unique_name

generate_unique_name(activity_list)

Return activity name

Source code in django_project/activity/factories.py
def generate_unique_name(activity_list) -> str:
    """Return activity name"""
    while True:
        name = random.choice(activity_list)
        if not ActivityType.objects.filter(name=name).exists():
            return name

Forms

ActivityTypeForm

Bases: ModelForm

Activity Type form.

Models

Models for activity package.

ActivityType

Bases: Model

activity type model

Serializers

Serializers for activity package.

ActivityTypeSerializer

ActivityTypeSerializer(*args, **kwargs)

Bases: ModelSerializer

Survey Method Serializer

Source code in django_project/activity/serializers.py
def __init__(self, *args, **kwargs):
    remove_fields = kwargs.pop('remove_fields', None)
    super(ActivityTypeSerializer, self).__init__(*args, **kwargs)
    if remove_fields:
        for field_name in remove_fields:
            self.fields.pop(field_name)

Test Case

Test case for activity models.

ActivityTypeTestCase

Bases: TestCase

unit tests for ActivityType model

setUp

setUp()

setup test data

Source code in django_project/activity/tests.py
def setUp(self) -> None:
    """setup test data"""
    self.activity_type = ActivityTypeFactory()

test_activity_type_create

test_activity_type_create()

test activity type create

Source code in django_project/activity/tests.py
def test_activity_type_create(self):
    """test activity type create"""
    self.assertEqual(self.activity_type.recruitment, True)
    self.assertEqual(ActivityType.objects.count(), 1)

test_activity_type_delete

test_activity_type_delete()

test activity type delete

Source code in django_project/activity/tests.py
def test_activity_type_delete(self):
    """test activity type delete"""
    self.activity_type.delete()
    self.assertEqual(ActivityType.objects.count(), 0)

test_activity_type_update

test_activity_type_update()

test activity type update

Source code in django_project/activity/tests.py
def test_activity_type_update(self):
    """test activity type update"""
    self.activity_type.name = 'Planned euthanasia'
    self.activity_type.recruitment = False
    self.activity_type.save()
    self.assertEqual(self.activity_type.name, 'Planned euthanasia')
    self.assertEqual(self.activity_type.recruitment, False)

Views

ActivityTypeAPIView

Bases: APIView

Get Activity Type