Raise NotImplementedError when unknown model is passed

This commit is contained in:
2020-05-21 18:43:05 +02:00
parent 019adcba56
commit 2e1c7e7165
2 changed files with 18 additions and 0 deletions

View File

@@ -28,6 +28,8 @@ def create(model: Type[T], **kwargs) -> T:
if model is models.Upload:
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:
"""

View 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)