Example #1
0
 def setUp(self):
     super(ReviewStepTest, self).setUp()
     self.reviewee_email = '*****@*****.**'
     self.reviewee_key = models.Student(key_name=self.reviewee_email).put()
     self.reviewer_email = '*****@*****.**'
     self.reviewer_key = models.Student(key_name=self.reviewer_email).put()
     self.unit_id = 'unit_id'
     self.submission_key = student_work.Submission(
         reviewee_key=self.reviewee_key, unit_id=self.unit_id).put()
     self.review_key = student_work.Review(reviewee_key=self.reviewee_key,
                                           reviewer_key=self.reviewer_key,
                                           unit_id=self.unit_id).put()
     self.review_summary_key = peer.ReviewSummary(
         reviewee_key=self.reviewee_key,
         submission_key=self.submission_key,
         unit_id=self.unit_id).put()
     self.step = peer.ReviewStep(assigner_kind=domain.ASSIGNER_KIND_AUTO,
                                 review_key=self.review_key,
                                 review_summary_key=self.review_summary_key,
                                 reviewee_key=self.reviewee_key,
                                 reviewer_key=self.reviewer_key,
                                 state=domain.REVIEW_STATE_ASSIGNED,
                                 submission_key=self.submission_key,
                                 unit_id=self.unit_id)
     self.step_key = self.step.put()
 def setUp(self):
     super(ReviewTest, self).setUp()
     self.reviewee_email = '*****@*****.**'
     self.reviewer_email = '*****@*****.**'
     self.unit_id = 'unit_id'
     self.reviewee = models.Student(key_name=self.reviewee_email)
     self.reviewee_key = self.reviewee.put()
     self.reviewer = models.Student(key_name=self.reviewer_email)
     self.reviewer_key = self.reviewer.put()
     self.review = student_work.Review(reviewee_key=self.reviewee_key,
                                       reviewer_key=self.reviewer_key,
                                       unit_id=self.unit_id)
     self.review_key = self.review.put()
 def test_constructor_sets_key_name(self):
     """Tests construction of key_name, put of entity with key_name set."""
     unit_id = 'unit_id'
     reviewee_key = models.Student(key_name='*****@*****.**').put()
     reviewer_key = models.Student(key_name='*****@*****.**').put()
     submission_key = student_work.Submission(
         reviewee_key=reviewee_key, unit_id=unit_id).put()
     step_key = peer.ReviewStep(
         assigner_kind=domain.ASSIGNER_KIND_AUTO,
         reviewee_key=reviewee_key, reviewer_key=reviewer_key,
         state=domain.REVIEW_STATE_ASSIGNED,
         submission_key=submission_key, unit_id=unit_id).put()
     self.assertEqual(
         peer.ReviewStep.key_name(submission_key, reviewer_key),
         step_key.name())
 def test_modified_blacklist_contents(self):
     save_blacklist = models.Student._PROPERTY_EXPORT_BLACKLIST
     models.Student._PROPERTY_EXPORT_BLACKLIST = [
         'name',
         'additional_fields.age',
         'additional_fields.gender',
     ]
     blacklisted = [
         {'name': 'age', 'value': '22'},
         {'name': 'gender', 'value': 'female'},
     ]
     permitted = [
         {'name': 'goal', 'value': 'complete_course'},
         {'name': 'timezone', 'value': 'America/Los_Angeles'},
     ]
     additional_fields = transforms.dumps(
         [[x['name'], x['value']] for x in blacklisted + permitted])
     with utils.Namespace('ns_test'):
         models.Student(
             user_id='123456', additional_fields=additional_fields).put()
         response = transforms.loads(self.get(
             '/test/rest/data/students/items').body)
     self.assertEquals(permitted,
                       response['data'][0]['additional_fields'])
     models.Student._PROPERTY_EXPORT_BLACKLIST = save_blacklist
Example #5
0
 def test_modified_blacklist_contents(self):
     # pylint: disable-msg=protected-access
     save_blacklist = models.Student._PROPERTY_EXPORT_BLACKLIST
     models.Student._PROPERTY_EXPORT_BLACKLIST = [
         'name',
         'additional_fields.age',
         'additional_fields.gender',
     ]
     blacklisted_fields = [
         ['age', 22],
         ['gender', 'female'],
     ]
     permitted_fields = [['goal', 'complete_course'],
                         ['timezone', 'America/Los_Angeles']]
     additional_fields = transforms.dumps(blacklisted_fields +
                                          permitted_fields)
     with utils.Namespace('ns_test'):
         models.Student(user_id='123456',
                        additional_fields=additional_fields).put()
         response = transforms.loads(
             self.get('/test/rest/data/students/items').body)
     self.assertEquals({k: v
                        for k, v in permitted_fields},
                       response['data'][0]['additional_fields'])
     models.Student._PROPERTY_EXPORT_BLACKLIST = save_blacklist
Example #6
0
    def test_federated_email_returns_and_caches_data_from_custom_resolver(
            self):
        class Resolver(users.FederatedEmailResolver):
            @classmethod
            def get(cls, unused_user_id):
                return '*****@*****.**'

        class UsersService(users.AbstractUsersService):
            @classmethod
            def get_federated_email_resolver_class(cls):
                return Resolver

        users.UsersServiceManager.set(UsersService)

        student = models.Student(user_id='1')

        # Check backing value starts at None, uncached. On access of the public
        # computed property, check the backing value is now set and cached.
        self.assertIsNone(student._federated_email_value)
        self.assertFalse(student._federated_email_cached)

        self.assertEquals('*****@*****.**', student.federated_email)

        self.assertEquals('*****@*****.**',
                          student._federated_email_value)
        self.assertTrue(student._federated_email_cached)
Example #7
0
    def test_send_welcome_notification_enqueues_and_sends(self):
        nick_name = 'No Body'
        email = '*****@*****.**'
        sender = '*****@*****.**'
        title = 'title'
        student = models.Student(key_name=email, name=nick_name)
        student.put()
        self.swap(services.notifications, 'enabled', lambda: True)
        self.swap(services.unsubscribe, 'enabled', lambda: True)
        handler = actions.MockHandler(app_context=actions.MockAppContext(
            environ={
                'course': {
                    'send_welcome_notifications': True,
                    'title': title,
                    'welcome_notifications_sender': sender,
                },
            }))
        models.StudentProfileDAO._send_welcome_notification(handler, student)
        self.execute_all_deferred_tasks()
        notification = notifications.Notification.all().get()
        payload = notifications.Payload.all().get()
        audit_trail = notification.audit_trail

        self.assertEqual(title, audit_trail['course_title'])
        self.assertEqual('http://mycourse.appspot.com/slug/',
                         audit_trail['course_url'])
        self.assertTrue(audit_trail['unsubscribe_url'].startswith(
            'http://mycourse.appspot.com/slug/modules/unsubscribe'))
        self.assertTrue(notification._done_date)
        self.assertEqual(email, notification.to)
        self.assertEqual(sender, notification.sender)
        self.assertEqual('Welcome to ' + title, notification.subject)
        self.assertTrue(payload)
Example #8
0
    def tests_returns_302_and_updates_if_student_email_changed(self):
        service = self._get_gitkit_service(self.gitkit_user)
        headers = self._make_token_headers('token')
        old_email = 'old_' + self.email
        models.Student(key_name=self.user_id,
                       email=old_email,
                       user_id=self.user_id).put()
        gitkit.EmailMapping.create_or_update(old_email, self.user_id)

        # When there's a student with a different email in the mapping, a change
        # event fires with the old and new values.
        with _Environment(self.config_yaml, self.properties, service=service):
            response = self.testapp.get(gitkit._SIGN_IN_URL, headers=headers)
            event = models.EventEntity.all().get()
            mapping = gitkit.EmailMapping.all().get()

            self.assertEquals(self.email, mapping.email)
            self.assertEquals(
                transforms.dumps({
                    'from': 'old_' + self.email,
                    'to': self.email,
                }), event.data)

            self.assertEquals(302, response.status_code)
            self.assertTrue(
                response.location.endswith(gitkit._SIGN_IN_CONTINUE_URL))
Example #9
0
 def test_constructor_sets_key_name(self):
     """Tests construction of key_name, put of entity with key_name set."""
     unit_id = 'unit_id'
     reviewer_key = models.Student(key_name='*****@*****.**').put()
     review_key = student_work.Review(reviewer_key=reviewer_key,
                                      unit_id=unit_id).put()
     self.assertEqual(student_work.Review.key_name(unit_id, reviewer_key),
                      review_key.name())
Example #10
0
 def test_safe_key_transforms_name(self):
     student_key = models.Student(key_name='name').put()
     answers = models.StudentAnswersEntity(key_name=student_key.name())
     answers_key = answers.put()
     self.assertEqual(
         'transformed_name',
         models.StudentAnswersEntity.safe_key(answers_key,
                                              self.transform).name())
 def setUp(self):
     super(SubmissionTest, self).setUp()
     self.reviewee_email = '*****@*****.**'
     self.unit_id = 'unit_id'
     self.reviewee = models.Student(key_name=self.reviewee_email)
     self.reviewee_key = self.reviewee.put()
     self.submission = student_work.Submission(
         reviewee_key=self.reviewee_key, unit_id=self.unit_id)
     self.submission_key = self.submission.put()
 def test_constructor_sets_key_name(self):
     unit_id = 'unit_id'
     reviewee_key = models.Student(key_name='*****@*****.**').put()
     submission_key = student_work.Submission(
         reviewee_key=reviewee_key, unit_id=unit_id).put()
     summary_key = peer.ReviewSummary(
         reviewee_key=reviewee_key, submission_key=submission_key,
         unit_id=unit_id).put()
     self.assertEqual(
         peer.ReviewSummary.key_name(submission_key), summary_key.name())
 def test_two_students_partial_scores(self):
     s1_scores = '{"1": 20}'
     s2_scores = '{"1": 10, "2": 40}'
     with utils.Namespace('ns_test'):
         a1 = self._course.add_assessment()
         a1.title = 'A1'
         a1.weight = 1
         a2 = self._course.add_assessment()
         a2.title = 'A2'
         a2.weight = 2
         self._course.save()
         models.Student(user_id='1', scores=s1_scores).put()
         models.Student(user_id='2', scores=s2_scores).put()
     response = transforms.loads(self.get(
         '/test/rest/data/assessment_scores/items').body)
     self.assertItemsEqual([self._score_data('1', 'A1', 1, 20, 0),
                            self._score_data('1', 'A1', 1, 10, 0),
                            self._score_data('2', 'A2', 2, 40, 1)],
                           response['data'])
Example #14
0
    def test_rest_handler_discretely_does_not_mail_registered_users(self):
        # To reduce spam the service should NOT email registered users, but for
        # privacy reasons should report to the requestor that it did.
        registered_student = '*****@*****.**'
        models.Student(key_name=registered_student, is_enrolled=True).put()

        response = self._do_valid_email_list_post([registered_student])
        self.assertEquals(200, response['status'])
        self.assertEquals('OK, 1 messages sent', response['message'])
        self.assertEqual(0, self.send_async_count)
 def test_one_student_one_score(self):
     scores = '{"1": 20}'
     with utils.Namespace('ns_test'):
         self._course.add_assessment()
         self._course.save()
         models.Student(user_id='123456', scores=scores).put()
     response = transforms.loads(self.get(
         '/test/rest/data/assessment_scores/items').body)
     self.assertItemsEqual(
         [self._score_data('1', 'New Assessment', 1, 20, 0)],
         response['data'])
Example #16
0
 def test_safe_key_transforms_user_id_component(self):
     user_id = 'user_id'
     student = models.Student(key_name='*****@*****.**', user_id=user_id)
     student.put()
     property_name = 'property-name'
     student_property_key = models.StudentPropertyEntity.create(
         student, property_name).put()
     self.assertEqual(
         'transformed_%s-%s' % (user_id, property_name),
         models.StudentPropertyEntity.safe_key(student_property_key,
                                               self.transform).name())
Example #17
0
 def setUp(self):
     super(TextFileUploadHandlerTestCase, self).setUp()
     self.contents = 'contents'
     self.email = '*****@*****.**'
     self.headers = {'referer': 'http://localhost/path?query=value#fragment'}
     self.unit_id = '1'
     self.user_id = '2'
     self.student = models.Student(
         is_enrolled=True, key_name=self.email, user_id=self.user_id)
     self.student.put()
     self.xsrf_token = utils.XsrfTokenManager.create_xsrf_token(
         upload._XSRF_TOKEN_NAME)
 def setUp(self):
     super(ReviewSummaryTest, self).setUp()
     self.unit_id = 'unit_id'
     self.reviewee_email = '*****@*****.**'
     self.reviewee_key = models.Student(
         key_name='*****@*****.**').put()
     self.submission_key = student_work.Submission(
         reviewee_key=self.reviewee_key, unit_id=self.unit_id).put()
     self.summary = peer.ReviewSummary(
         reviewee_key=self.reviewee_key, submission_key=self.submission_key,
         unit_id=self.unit_id)
     self.summary_key = self.summary.put()
    def test_update_last_seen_on_does_not_update_when_last_seen_too_new(self):
        now = datetime.datetime.utcnow()
        student = models.Student(last_seen_on=now, user_id='1')
        key = student.put()
        too_new = now + datetime.timedelta(
            seconds=models.STUDENT_LAST_SEEN_ON_UPDATE_SEC)

        self.assertEquals(now, student.last_seen_on)

        student.update_last_seen_on(now=now, value=too_new)
        student = db.get(key)

        self.assertEquals(now, student.last_seen_on)
    def test_update_last_seen_on_updates_when_last_seen_on_is_old_enough(self):
        now = datetime.datetime.utcnow()
        student = models.Student(last_seen_on=now, user_id='1')
        key = student.put()
        old_enough = now + datetime.timedelta(
            seconds=models.STUDENT_LAST_SEEN_ON_UPDATE_SEC + 1)

        self.assertEquals(now, student.last_seen_on)

        student.update_last_seen_on(now=now, value=old_enough)
        student = db.get(key)

        self.assertEquals(old_enough, student.last_seen_on)
    def test_for_export_transforms_correctly(self):
        user_id = '1'
        student = models.Student(key_name='name', user_id='1', is_enrolled=True)
        key = student.put()
        exported = student.for_export(self.transform)

        self.assert_blacklisted_properties_removed(student, exported)
        self.assertTrue(exported.is_enrolled)
        self.assertEqual('transformed_1', exported.user_id)
        self.assertEqual(
            'transformed_' + user_id, exported.key_by_user_id.name())
        self.assertEqual(
            models.Student.safe_key(key, self.transform), exported.safe_key)
Example #22
0
    def test_federated_email_returns_none_for_legacy_users_sans_user_id(self):
        student = models.Student()

        # Check backing value starts at None, uncached. On access of the public
        # computed property, check the backing value is still None (since the
        # expected value is None in this case), but that the None value is now
        # cached.
        self.assertIsNone(student._federated_email_value)
        self.assertFalse(student._federated_email_cached)

        self.assertIsNone(student.federated_email)

        self.assertIsNone(student._federated_email_value)
        self.assertTrue(student._federated_email_cached)
    def test_update_last_seen_on_updates_when_last_seen_on_is_none_noarg(self):
        now = datetime.datetime.utcnow()
        student = models.Student(last_seen_on=None, user_id='1')
        key = student.put()
        # Must be too new to otherwise update.
        too_new = now + datetime.timedelta(
            seconds=models.STUDENT_LAST_SEEN_ON_UPDATE_SEC)

        self.assertIsNone(student.last_seen_on)

        student.update_last_seen_on()
        student = db.get(key)

        self.assertTrue(isinstance(student.last_seen_on, datetime.datetime))
 def setUp(self):
     super(TextFileUploadHandlerTestCase, self).setUp()
     self.contents = 'contents'
     self.email = '*****@*****.**'
     self.headers = {
         'referer': 'http://localhost/path?query=value#fragment'
     }
     self.unit_id = '1'
     actions.login(self.email)
     user = users.get_current_user()
     actions.logout()
     self.user_id = user.user_id()
     self.student = models.Student(is_enrolled=True,
                                   key_name=self.email,
                                   user_id=self.user_id)
     self.student.put()
     # Allow protected access for tests. pylint: disable=protected-access
     self.xsrf_token = utils.XsrfTokenManager.create_xsrf_token(
         upload._XSRF_TOKEN_NAME)
Example #25
0
    def tests_returns_302_if_student_with_same_email(self):
        service = self._get_gitkit_service(self.gitkit_user)
        headers = self._make_token_headers('token')
        models.Student(key_name=self.user_id,
                       email=self.email,
                       user_id=self.user_id).put()
        gitkit.EmailMapping.create_or_update(self.email, self.user_id)

        # When there's a student but no email change, no event fires. Check to
        # see the mapping still has the same value.
        with _Environment(self.config_yaml, self.properties, service=service):
            response = self.testapp.get(gitkit._SIGN_IN_URL, headers=headers)
            mapping = gitkit.EmailMapping.all().get()

            self.assertIsNone(models.EventEntity.all().get())
            self.assertEquals(self.email, mapping.email)

            self.assertEquals(302, response.status_code)
            self.assertTrue(
                response.location.endswith(gitkit._SIGN_IN_CONTINUE_URL))
    def test_one_student(self):
        expected_enrolled_on = datetime.datetime.utcnow()
        user_id = '123456'
        is_enrolled = True
        with utils.Namespace('ns_test'):
            models.Student(user_id=user_id, is_enrolled=is_enrolled).put()

        response = transforms.loads(self.get(
            '/test/rest/data/students/items').body)
        self.assertEquals('None', response['data'][0]['user_id'])
        self.assertEquals(is_enrolled, response['data'][0]['is_enrolled'])
        # expected/actual enrolled_on timestamp may be _slightly_ off
        # since it's automatically set on creation by DB internals.
        # Allow for this.
        actual_enrolled_on = datetime.datetime.strptime(
            response['data'][0]['enrolled_on'],
            transforms.ISO_8601_DATETIME_FORMAT)
        self.assertAlmostEqual(
            0,
            abs((expected_enrolled_on - actual_enrolled_on).total_seconds()), 1)
Example #27
0
    def _submit_review(self, assessment):
        """Submits a review by the current student.

        Creates a new user that completes the assessment as well,
        so that the student can review it.

        Args:
            assessment: The assessment to review.
        """

        reviewer_key = self.student.get_key()
        reviewee = models.Student(key_name='*****@*****.**')
        reviewee_key = reviewee.put()

        submission_key = db.Key.from_path(
            student_work.Submission.kind(),
            student_work.Submission.key_name(reviewee_key=reviewee_key,
                                             unit_id=str(assessment.unit_id)))
        summary_key = peer.ReviewSummary(assigned_count=1,
                                         reviewee_key=reviewee_key,
                                         submission_key=submission_key,
                                         unit_id=str(
                                             assessment.unit_id)).put()
        review_key = student_work.Review(contents='old_contents',
                                         reviewee_key=reviewee_key,
                                         reviewer_key=reviewer_key,
                                         unit_id=str(
                                             assessment.unit_id)).put()
        step_key = peer.ReviewStep(assigner_kind=domain.ASSIGNER_KIND_HUMAN,
                                   review_key=review_key,
                                   review_summary_key=summary_key,
                                   reviewee_key=reviewee_key,
                                   reviewer_key=reviewer_key,
                                   submission_key=submission_key,
                                   state=domain.REVIEW_STATE_ASSIGNED,
                                   unit_id=str(assessment.unit_id)).put()
        updated_step_key = review_module.Manager.write_review(
            step_key, 'new_contents')

        self.assertEqual(step_key, updated_step_key)
def insert():
    if request.method == 'POST':
        group = models.Group(**{
            'group_name': f'{request.form.get("group_name")}'
        }).save()
        curator = models.Curator(
            **{
                'curator_name': f'{request.form.get("curator_name")}'
            }).save()
        faculty = models.Faculty(
            **{
                'faculty_name': f'{request.form.get("faculty_name")}'
            }).save()

        dict_student = {
            'name': f'{request.form.get("name")}',
            'group_name': [group],
            'curator_name': [curator],
            'faculty_name': [faculty]
        }
        models.Student(**dict_student).save()

        return redirect(url_for('index'))
Example #29
0
 def test_safe_key_transforms_name(self):
     key = models.Student(key_name='name').put()
     self.assertEqual('transformed_name',
                      models.Student.safe_key(key, self.transform).name())
Example #30
0
 def test_get_key_does_not_transform_by_default(self):
     user_id = 'user_id'
     student = models.Student(key_name='name', user_id=user_id)
     student.put()
     self.assertEqual(user_id, student.get_key().name())