Example #1
0
    def test_list_all_users_may_list_them(self):
        UserFactory.create_batch(5)

        url = reverse('user-list')
        response = self.client.get(url)

        expected_users_number = User.objects.count()
        self.assertEqual(status.HTTP_200_OK, response.status_code)
        self.assertEqual(expected_users_number, len(response.data['results']))
Example #2
0
    def handle(self, *args, **options):
        """Automatically called when the sampledata command is given."""
        if settings.DEPLOYMENT_TYPE == 'prod' and not settings.DEBUG:
            raise management.base.CommandError(
                'This command can only be executed in DEBUG mode on non-production website.'
            )

        # Clear all data
        print(LOG_HEADER.format('Wipe database'))
        management.call_command('flush', interactive=False)
        print('Database wiped.')

        management.call_command('load_user_types')
        print(LOG_HEADER.format('Create sample users'))
        User = get_user_model()
        # Create admin account
        admin = User.objects.create_superuser(
            'admin',
            '*****@*****.**',
            password=settings.SAMPLE_DATA_ADMIN_PASSWORD,
            first_name='Admin',
            last_name='Account',
            user_type=UserType.objects.get(slug='teacher'))
        EmailAddress.objects.create(user=admin,
                                    email=admin.email,
                                    primary=True,
                                    verified=True)
        print('Admin created.')

        # Create user account
        user = User.objects.create_user(
            'user',
            '*****@*****.**',
            password=settings.SAMPLE_DATA_USER_PASSWORD,
            first_name='Alex',
            last_name='Doe',
            user_type=UserType.objects.get(slug='student'))
        EmailAddress.objects.create(user=user,
                                    email=user.email,
                                    primary=True,
                                    verified=True)
        UserFactory.create_batch(size=100)
        print('Users created.')

        # Codewof
        management.call_command('load_questions')
        print('Programming questions loaded.')

        # Research
        StudyFactory.create_batch(size=5)
        StudyGroupFactory.create_batch(size=15)
        print('Research studies loaded.')
Example #3
0
    def handle(self, *args, **options):
        """Automatically called when the sampledata command is given."""
        if settings.PRODUCTION_ENVIRONMENT:
            raise management.base.CommandError(
                'This command can only be executed on a non-production website.'
            )

        skip = options['skip_backdate']

        # Clear all data
        print(LOG_HEADER.format('Wipe database'))
        management.call_command('flush', interactive=False)
        print('Database wiped.')

        # Update data
        management.call_command('update_data')

        print(LOG_HEADER.format('Create sample users'))

        # Create admin account
        management.call_command('create_admin')

        # Create user account
        User = get_user_model()  # noqa N806
        user = User.objects.create_user(
            'user',
            '*****@*****.**',
            password=settings.SAMPLE_DATA_USER_PASSWORD,
            first_name='Alex',
            last_name='Doe',
            user_type=UserType.objects.get(slug='student'))
        EmailAddress.objects.create(user=user,
                                    email=user.email,
                                    primary=True,
                                    verified=True)

        UserFactory.create_batch(size=100)
        print('Users created.\n')

        # Attempts
        AttemptFactory.create_batch(size=50)
        print('Attempts loaded.\n')

        # Award points and achievements
        if not skip:
            management.call_command('backdate_points_and_achievements')
        else:
            print('Ignoring backdate step as requested.\n')