diff --git a/validity/tests/factories.py b/validity/tests/factories.py index 88142ac..7b05859 100644 --- a/validity/tests/factories.py +++ b/validity/tests/factories.py @@ -1,5 +1,6 @@ import datetime +import django import factory from dcim.models import DeviceRole, DeviceType, Location, Manufacturer, Platform, Site from extras.models import Tag @@ -10,6 +11,9 @@ from validity.compliance.state import StateItem +DJANGO_MAJOR_VERSION = django.VERSION[:2] + + class DataSourceFactory(DjangoModelFactory): name = factory.Sequence(lambda n: f"datasource-{n}") type = "local" @@ -30,6 +34,11 @@ class DataFileFactory(DjangoModelFactory): class Meta: model = models.VDataFile + @factory.post_generation + def to_memoryview(self, **kwargs): + if DJANGO_MAJOR_VERSION < (4, 2) and isinstance(self.data, bytes): + self.data = memoryview(self.data) + class DataSourceLinkFactory(DjangoModelFactory): data_source = factory.SubFactory(DataSourceFactory)