Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from django.test import TestCase
- from django.test.utils import override_settings, modify_settings
- from django.core.management import call_command
- from django.db.models import loading
- from oscarapi import serializers
- from sandbox.models import CustomUser # noqa
- @modify_settings(INSTALLED_APPS={'append': 'sandbox'})
- @override_settings(AUTH_USER_MODEL='sandbox.CustomUser')
- class CustomUserTestCase(TestCase):
- def _pre_setup(self):
- # make sure the migrations are run for our sandbox app including the
- # custom user model
- loading.cache.loaded = False
- call_command('migrate', interactive=False, verbosity=0)
- # reload the login serializer so it works with our custom user
- # objects
- reload(serializers.login)
- # Call the original method that does the fixtures etc.
- super(CustomUserTestCase, self)._pre_setup()
- def setUp(self):
- user = CustomUser.objects.create_user(
- email='customuser@example.org',
- password='customuser',
- )
- user.save()
- def tearDown(self):
- CustomUser.objects.get(email='customuser@example.org').delete()
- def test_loginserializer(self):
- """The login serializer should be fine with our custom user model"""
- ser = serializers.LoginSerializer(data={
- 'username': 'customuser@example.org',
- 'password': 'customuser',
- })
- self.assertTrue(ser.is_valid())
- self.assertTrue(isinstance(ser.instance, CustomUser))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement