def setUp(self):
        """ Create variables for testing """

        # Create a user to be used for testing
        self.user, self.info = Factory.create_user()
        Factory.create_session(self.info.organization, self.user)

        # Create some organizations and sessions
        self.org1 = Factory.create_organization(self.user)
        self.session1 = Factory.create_session(self.org1, self.user)
Ejemplo n.º 2
0
    def setUp(self):
        """ Set up a user for testing """

        self.user, self.info = Factory.create_user()
        self.user.is_staff = True
        self.user.save()

        Factory.create_set_of_submissions(self.user)

        # Login
        self.client.login(username=self.user.username, password=Factory.default_password)
 def setUp(self):
     """ Password - Set up.
         Set up a user account for testing.
     """
     self.user, self.info = Factory.create_user()
     self.organization = self.info.organization
     self.session = self.info.session
    def testViewLoadsWithLogin(self):
        """ Account Settings - View loads with login.
            Verify that the view loads when logged in
            and that all the provided information is
            present and correct.
        """

        # Log in
        self.client.login(username = self.user.username, password = Factory.default_password)

        # Make the GET request
        response = self.client.get('/account-settings', follow = True)

        # Verify the correct template was used
        self.assertTemplateUsed(response, 'user/settings.html')

        # Verify both the epxected forms were passed to the template
        self.assertTrue('user_form' in response.context)
        self.assertTrue('info_form' in response.context)

        # Expected form values
        settings_form = Factory.create_user_settings_post_dict(self.user, self.info)

        # Validate field values in user_form
        user_form = response.context['user_form']
        self.validate_form(user_form, settings_form, ())

        # Validate field values in info_form
        info_form = response.context['info_form']
        self.validate_form(info_form, settings_form, ())
Ejemplo n.º 5
0
    def testUserInfoNotValid_UsernameNotUnique(self):
        """ Attempt to register with a taken username.
            Verify that submission via POST with a
            username that is already in use rerenders
            the template and shows an error without
            creating the user account
        """

        # Get the POST dict
        registration_form = Factory.create_user_registration_post_dict(self.organization)
        registration_form['username'] = self.user.username

        # Make the post request
        response = self.client.post('/register/{}'.format(self.info.session.uuid),
            registration_form, follow = True)

        # Verify that the register page was rendered
        self.assertTemplateUsed(response, 'user/register.html')

        # Verify both forms are included in the response
        self.assertTrue('user_form' in response.context)
        self.assertTrue('info_form' in response.context)

        # Verify form fields retain their set values
        user_form = response.context['user_form']
        info_form = response.context['info_form']

        # Validate
        self.validate_form(user_form, registration_form, ('username'))
        self.validate_form(info_form, registration_form, ())
Ejemplo n.º 6
0
    def testUserInfoNotValid_PasswordConfirmationFailed(self):
        """
        Verify that submission via POST with a
        failed password confirmation rerenders
        the template and shows an error without
        creating the user account
        """

        # Get the POST dict
        registration_form = Factory.create_user_registration_post_dict(self.organization)
        registration_form['password2'] = 'incorrect'

        # Make the post request
        response = self.client.post('/register/{}'.format(self.info.session.uuid),
            registration_form, follow = True)

        # Verify that the register page was rendered
        self.assertTemplateUsed(response, 'user/register.html')

        # Verify both forms are included in the response
        self.assertTrue('user_form' in response.context)
        self.assertTrue('info_form' in response.context)

        # Verify form fields retain their set values
        user_form = response.context['user_form']
        self.validate_form(user_form, registration_form, ('password2'))

        # lead stuff
        info_form = response.context['info_form']
        self.validate_form(info_form, registration_form, ())
 def setUp(self):
     """ Set Up
         Create a user account and user info
         to be used for testing
     """
     self.user, self.info = Factory.create_user()
     self.organization = self.info.organization
     self.session = self.info.session
Ejemplo n.º 8
0
    def setUp(self):
        """
        Set up for testing by creating a user account
        and loggin in.
        """

        # Create a user account and login
        self.user, user_info = Factory.create_user()
        self.client.login(username = self.user.username, password = Factory.default_password)
Ejemplo n.º 9
0
    def testLogout(self):
        # Create an account and log in
        user, user_info = Factory.create_user()
        self.client.login(username = user.username, password = Factory.default_password)

        # Make the get reqeust
        response = self.client.get('/logout', follow = True)

        # Verify redirect
        self.assertRedirects(response, '/login')
    def testUsernameNotUnique(self):
        """ Account Settings - Username not unique.
            Verify that attempting to change to a username
            already in use rerenders the page with a form
            error.
        """

        # Create a second user
        user2, user2_info = Factory.create_user()

        # Log in as the first user
        self.client.login(username = self.user, password = Factory.default_password)

        # Get the post info and change username
        settings_form = Factory.create_user_settings_post_dict(self.user, self.info)
        settings_form['username'] = user2.username

        # Make the POST request
        response = self.client.post('/account-settings', settings_form, follow = True)

        # Verify the correct template was used
        self.assertTemplateUsed(response, 'user/settings.html')

        # Verify both the epxected forms were passed to the template
        self.assertTrue('user_form' in response.context)
        self.assertTrue('info_form' in response.context)

        # Validate field values in user_form
        user_form = response.context['user_form']
        self.validate_form(user_form, settings_form, ('username'))

        # Validate field values in info_form
        info_form = response.context['info_form']
        self.validate_form(info_form, settings_form, ())

        self.assertTrue('organization' in response.context)
        self.assertEqual(response.context['organization'].name, self.organization.name)

        self.assertTrue('session' in response.context)
        self.assertEqual(response.context['session'].name, self.session.name)
Ejemplo n.º 11
0
    def handle(self, **options):
        # Delete what was there before so we have a clean start
        User.objects.filter(username='******').delete()
        User.objects.filter(username__startswith='testuser').delete()

        admin = Factory.create_admin()

        # Typical-case organization
        chess = Factory.create_organization(admin, name='UNC Chess Club')
        chess_session = Factory.create_session(chess, admin, name='Fall 2016')
        self.add_users(chess_session, 10)

        # Orgainization with two sessions
        strawhats = Factory.create_organization(admin, name='Strawhats')
        strawhats_session1 = Factory.create_session(strawhats, admin,
            name='East Blue')
        self.add_users(strawhats_session1, 9)
        strawhats_session2 = Factory.create_session(strawhats, admin,
            name='Grand Line')
        self.add_users(strawhats_session2, 11)

        # Organization where not everyone has completed all of the inventories
        incomplete = Factory.create_organization(admin, name='Incompletionists')
        incomplete_session = Factory.create_session(incomplete, admin, name='Fall 2016')

        for i in range(10):
            # Everyone completes BigFive
            inventory_cls_list = [BigFive]

            # 9 users complete CoreSelf
            if i != 9:
                inventory_cls_list.append(CoreSelf)

            # 2 users complete CareerCommitment
            if i < 2:
                inventory_cls_list.append(CareerCommitment)

            # 1 user completes Ambiguity and Via
            if i == 0:
                inventory_cls_list.append(Ambiguity)
                inventory_cls_list.append(Via)

            # No one completes FIRO-B or Via

            self.add_user(incomplete_session, inventory_cls_list)

        print()
Ejemplo n.º 12
0
    def testPageNotFound(self):
        """
        Verify the correct templage is rendered
        when logged in
        """

        # Create an account and log in
        user, user_info = Factory.create_user()
        self.client.login(username = user.username, password = Factory.default_password)

        # Make the GET request
        response = self.client.get('/unsupportedpage', follow = True)

        # Verify template
        self.assertTemplateUsed(response, 'page_not_found.html')
    def setUp(self):
        """ Set up submission data in an organization for testing """

        # Admin account without leaduserinfo
        self.admin = Factory.create_admin()

        # Create an organization with three sessions
        self.org = Factory.create_organization(self.admin)
        self.session1 = Factory.create_session(self.org, self.admin)
        self.session2 = Factory.create_session(self.org, self.admin)
        self.session3 = Factory.create_session(self.org, self.admin)
        self.sessions = [self.session1, self.session2, self.session3]

        # Attach an explicit, non staff user, to the organization
        self.user, self.info = Factory.create_user(self.session1)

        # Generate data (3 sets of submissions) for each session
        for session in self.sessions:
            for i in range(0, 3):
                user, info = Factory.create_user(session)
                Factory.create_set_of_submissions(user)
Ejemplo n.º 14
0
    def testOrganizationCodeInvalid(self):
        """ Verify an invalid organization sends an error """

        # Get the POST dict
        registration_form = Factory.create_user_registration_post_dict(self.organization)
        registration_form['organization_code'] = 'invalid'

        # Make the post request
        response = self.client.post('/register/{}'.format(self.info.session.uuid),
            registration_form, follow = True)

        # Get the forms
        user_form = response.context['user_form']
        self.validate_form(user_form, registration_form, ())

        info_form = response.context['info_form']
        self.validate_form(info_form, registration_form, ('organization_code'))
    def setUp(self):
        # Create a user account and login
        self.user, user_info = Factory.create_user()
        self.client.login(username = self.user.username, password = Factory.default_password)

        # Create an inventory
        self.client.post('/inventory/take/0', {
                '1': '1',
                '2': '1',
                '3': '1',
                '4': '1',
                '5': '1',
                '6': '1',
                '7': '1',
                '8': '1',
                '9': '1',
                '10': '1',
            }, follow = True)
    def test_partial_excludes(self):
        """ Data is only supposed to be generated for non staff users
            for inventories that have 10 submissions. Previous tests
            checked for all inventories at this boundary. Test that if
            some inventories have 10 submissions and some have less,
            only the ones which meet the requirement are returned
            within the data set.
        """

        # Create a submission for Big Five, Ambiguity, and Via
        Factory.create_submission(self.user, BigFive)
        Factory.create_submission(self.user, Ambiguity)
        Factory.create_submission(self.user, Via)

        # List of inventory id's a valid submission may have
        valid_submissions = [BigFive.inventory_id, Ambiguity.inventory_id, Via.inventory_id]

        # Grab the data
        data = generate_data_from_sessions(self.sessions, self.user)

        # A count of all submissions exists
        self.assertEqual(6, len(data['submission_counts']))

        # Verify the submission count is correct
        for submission in data['submission_counts']:
            correct_count = Submission.objects.filter(inventory_id=submission['inventory_id']).count()
            self.assertEqual(submission['count'], correct_count)

        # Non admin does not have analysis
        self.assertNotIn('metrics_analysis', data)

        # Verify that the user data is correct
        for user in data['users']:
            # The correct number of submissions has been attached
            self.assertEqual(len(user.submissions), len(valid_submissions))

            # For each user submission
            for submission in user.submissions:
                # The submission belongs to the user
                self.assertEqual(user, submission.user)

                # The submission is valid
                self.assertIn(submission.inventory_id, valid_submissions)

                # The correct metrics exist in the submission
                num_metrics = Metric.objects.filter(submission=submission).count()
                self.assertEqual(len(submission.metrics), num_metrics)

                # For each submission metric
                for metric in submission.metrics:
                    # The metric belongs to the submission
                    self.assertEqual(submission, metric.submission)
Ejemplo n.º 17
0
    def testValidInfo(self):
        """
        Verify that submission of valid information
        creates the user account, the lead info,
        logs the user in, sets a success message,
        and redirects to the dashboard view
        """

        # Get the POST dict
        registration_form = Factory.create_user_registration_post_dict(self.organization)

        # Make the post request
        response = self.client.post('/register/{}'.format(self.info.session.uuid),
            registration_form, follow = True)

        # Verify the user account is created with correct attributes
        user = User.objects.get(username = registration_form['username'])
        info = LeadUserInfo.objects.get(user = user)

        self.assertTrue(user is not None)
        self.assertEqual(user.username, registration_form['username'])
        self.assertEqual(user.email, registration_form['email'])
        self.assertNotEqual(user.password, registration_form['password1']) # Password should be hashed
        self.assertEqual(user.first_name, registration_form['first_name'])
        self.assertEqual(user.last_name, registration_form['last_name'])

        self.assertTrue(info is not None)
        self.assertEqual(info.user, user)
        self.assertEqual(info.gender, registration_form['gender'])
        self.assertEqual(info.major, registration_form['major'])
        self.assertEqual(info.organization, self.organization)

        # Verify success message set
        messages = response.context['messages']
        self.assertEqual(len(messages), 1)
        for message in messages:
            self.assertEqual(message.message, "User account created successfully.")

        # Verify the user is redirected to the dashboard
        self.assertTemplateUsed(response, 'dashboard.html')
    def testGenderNotValid(self):
        """ Account Settings - Gender not valid.
            Verify that submitting a POST request with an
            invalid gender choice rerenders the page with
            a form error.
        """

        # Log in
        self.client.login(username = self.user.username, password = Factory.default_password)

        # Get the post dict and change gender choice
        settings_form = Factory.create_user_settings_post_dict(self.user, self.info)
        settings_form['gender'] = 'i'

        # Make the POST request
        response = self.client.post('/account-settings', settings_form, follow = True)

        # Verify the correct template was used
        self.assertTemplateUsed(response, 'user/settings.html')

        # Verify both the epxected forms were passed to the template
        self.assertTrue('user_form' in response.context)
        self.assertTrue('info_form' in response.context)

        # Validate field values in user_form
        user_form = response.context['user_form']
        self.validate_form(user_form, settings_form, ())

        # Validate field values in info_form
        info_form = response.context['info_form']
        self.validate_form(info_form, settings_form, ('gender'))

        self.assertTrue('organization' in response.context)
        self.assertEqual(response.context['organization'].name, self.organization.name)

        self.assertTrue('session' in response.context)
        self.assertEqual(response.context['session'].name, self.session.name)
    def testGradDateNotValid(self):
        """ Account Settings - graduation_date not valid.
            Verify that submitting an invalid graduation_date
            kicks back an error
        """

        # Log in
        self.client.login(username = self.user.username, password = Factory.default_password)

        # Create the post dict and set graduation_date
        settings_form = Factory.create_user_settings_post_dict(self.user, self.info)
        settings_form['graduation_date'] = -1

        # Make the POST request
        response = self.client.post('/account-settings', settings_form, follow = True)

        # Verify the correct template was used
        self.assertTemplateUsed(response, 'user/settings.html')

        # Verify both the epxected forms were passed to the template
        self.assertTrue('user_form' in response.context)
        self.assertTrue('info_form' in response.context)

        # Validate field values in user_form
        user_form = response.context['user_form']
        self.validate_form(user_form, settings_form, ())

        # Validate field values in info_form
        info_form = response.context['info_form']
        self.validate_form(info_form, settings_form, ('graduation_date'))

        self.assertTrue('organization' in response.context)
        self.assertEqual(response.context['organization'].name, self.organization.name)

        self.assertTrue('session' in response.context)
        self.assertEqual(response.context['session'].name, self.session.name)
Ejemplo n.º 20
0
 def setUp(self):
     """
     Set up user account for testing
     """
     self.user, user_info = Factory.create_user()
Ejemplo n.º 21
0
    def add_user(self, session, inventory_cls_list):
        user, info = Factory.create_user(session)
        Factory.create_set_of_submissions(user, inventory_cls_list)

        print('.', end='')
        sys.stdout.flush()
Ejemplo n.º 22
0
 def setUp(self):
     """ Set Up """
     self.user, user_info = Factory.create_user()
    def test_enough_data(self):
        """ Metrics are returned correctly if enough data exists
            Independent of whether or not user is staff.
        """

        # Generate the 10th set of data
        Factory.create_set_of_submissions(self.user)

        # Generate the data for a non staff
        data = generate_data_from_sessions(self.sessions, self.user)

        # Verify non staff do not have access to analysis
        self.assertIn('submission_counts', data)
        self.assertNotIn('metrics_analysis', data)
        self.assertIn('users', data)

        # Set staff to check for analysis
        self.user.is_staff = True
        self.user.save()

        # Load the data
        data = generate_data_from_sessions(self.sessions, self.user)

        # Verify staff have all data
        self.assertIn('submission_counts', data)
        self.assertIn('metrics_analysis', data)
        self.assertIn('users', data)

        # Verify each submission has a submission count
        self.assertEqual(6, len(data['submission_counts']))

        # Verify the submission count is correct
        for submission in data['submission_counts']:
            correct_count = Submission.objects.filter(inventory_id=submission['inventory_id']).count()
            self.assertEqual(submission['count'], correct_count)

        # Verify that there is a metric analysis for each metric
        # That does not belong to Via.
        correct_count = Metric.objects.exclude(
            submission__inventory_id=Via.inventory_id
        ).distinct('key', 'submission__inventory_id').count()
        self.assertEqual(len(data['metrics_analysis']), correct_count)

        # Verify that the metric analysis for each inventory is correct
        for analysis in data['metrics_analysis']:
            correct_analysis = Metric.objects.filter(
                key=analysis['key'],
                submission__inventory_id=analysis['submission__inventory_id']
            ).values(
                'key', 'submission__inventory_id'
            ).annotate(
                min=Min('value'),
                max=Max('value'),
                mean=Avg('value'),
                standard_deviation=StdDev('value')
            )

            self.assertDictEqual(analysis, correct_analysis[0])

        # Verify that the user data is correct
        for user in data['users']:
            # The correct number of submissions has been attached
            num_submissions = Submission.objects.filter(user=user).count()
            self.assertEqual(len(user.submissions), num_submissions)

            # For each user submission
            for submission in user.submissions:
                # The submission belongs to the user
                self.assertEqual(user, submission.user)

                # The correct metrics exist in the submission
                num_metrics = Metric.objects.filter(submission=submission).count()
                self.assertEqual(len(submission.metrics), num_metrics)

                # For each submission metric
                for metric in submission.metrics:
                    # The metric belongs to the submission
                    self.assertEqual(submission, metric.submission)
Ejemplo n.º 24
0
 def setUp(self):
     """ Create a user for testing """
     self.user, self.info = Factory.create_user()
Ejemplo n.º 25
0
 def setUp(self):
     """
     Create a superuser that lacks LeadUserInfo.
     """
     admin = Factory.create_admin()
     self.admin = admin
Ejemplo n.º 26
0
 def setUp(self):
     """ Create user account for testing """
     self.user, self.info = Factory.create_user()
     self.organization = self.info.organization
     self.session = self.info.session