from django.test import TestCase
from django.core import management

from users.models import User, Role


class ImportUsersTestCase(TestCase):
    def test_import(self):
        Role.objects.create_default_roles()

        management.call_command('import_users', 'Benutzer.sample.csv')

        self.assertEqual(User.objects.count(), 8)

        michael = User.objects.get(email='michael@dundermifflin.com')
        self.assertEqual(michael.first_name, 'Michael')
        self.assertEqual(michael.school_classes.count(), 2)
        self.assertTrue(michael.has_perm('users.can_manage_school_class_content'))
