Using
- Django: 1.11
- Python 3.6
- DRF: 3.7
- DREST (aka dynamic rest): 1.8
I have a serializer written like this:
class SubProjectAsFKWithAttachedFieldsSerializer(DynamicModelSerializer):
# attached_fields = AttachedFieldSerializer(embed=True, many=True)
try:
scope_object = UgField.objects.get(dotted_path='global.scope')
scopes = DynamicRelationField(
AttachedFieldWithDirectValuesSerializer,
source='attached_fields',
many=True,
embed=True,
read_only=True,
queryset=AttachedField.objects.filter(ug_field=scope_object)
)
except ObjectDoesNotExist:
scopes = DynamicRelationField(AttachedFieldWithDirectValuesSerializer,
source='attached_fields',
many=True,
read_only=True,
embed=True)
Currently, in almost all my tests.py
in the setUp method, I have
self.global_scope_field = UgFieldFactory(dotted_path='global.scope', name='Scope')
For some reason, this line
scope_object = UgField.objects.get(dotted_path='global.scope')
keeps failing despite that I have "instantiated" using a DjangoModelFactory
What should I do to ensure that line always passes when I run tests?
UPDATE
- Just to point out I actually have a UgField record which has the string
global.scope
as the value for the fielddotted_path
. - Only when I run
python manage.py test
do I face this issue. - When I run the app proper, there's no issue.
I have also tried setting
(self.global_scope_field, created) = UgField.objects.get_or_create(dotted_path='global.scope', name='Scope')
in my setUp
method.
but then I get the same issue