Raise NotImplementedError when unknown model is passed
This commit is contained in:
@@ -28,6 +28,8 @@ def create(model: Type[T], **kwargs) -> T:
|
|||||||
if model is models.Upload:
|
if model is models.Upload:
|
||||||
return _create_with_defaults(models.Upload, kwargs, file=SimpleUploadedFile('some_file.txt', b'some contents'))
|
return _create_with_defaults(models.Upload, kwargs, file=SimpleUploadedFile('some_file.txt', b'some contents'))
|
||||||
|
|
||||||
|
raise NotImplementedError('Factory for %s not implemented' % model)
|
||||||
|
|
||||||
|
|
||||||
def _create_with_defaults(model: Type[T], kwargs: dict, **defaults) -> T:
|
def _create_with_defaults(model: Type[T], kwargs: dict, **defaults) -> T:
|
||||||
"""
|
"""
|
||||||
|
|||||||
16
tests/videodinges/test_factories/test_create.py
Normal file
16
tests/videodinges/test_factories/test_create.py
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
from django.db import models
|
||||||
|
|
||||||
|
from tests.videodinges import factories
|
||||||
|
from django.test import TestCase
|
||||||
|
|
||||||
|
class CreateTestCase(TestCase):
|
||||||
|
|
||||||
|
def test_factory_returns_model(self):
|
||||||
|
|
||||||
|
class NotImplementedModel(models.Model):
|
||||||
|
class Meta:
|
||||||
|
app_label = 'some_test_label'
|
||||||
|
|
||||||
|
with self.assertRaises(NotImplementedError):
|
||||||
|
factories.create(NotImplementedModel)
|
||||||
|
|
||||||
Reference in New Issue
Block a user