Example #1
0
 def setUp(self):
     super(TestStudentListApi, self).setUp()
     Student.new_student('alice',
                         'alice smith',
                         email='*****@*****.**',
                         year=2015).key.get(use_cache=False)
     self.alice = self.new_user()
Example #2
0
    def get(self, studentId):
        """List all the files at destination to a specific student

        """
        student = Student.get_by_id(studentId)
        if not student:
            self.abort(404)

        current_user = self.login_required()
        if (
            not current_user.is_staff
            and not current_user.is_admin
            and not current_user.is_domain_admin
            and current_user.student_id != student.key.id()
        ):
            self.abort(403)
            return

        cursor_key = self.request.GET.get('cursor')

        # using cheap request and ndb entities cache
        file_keys, cursor, _ = models.Document.get_files(
            student.key, cursor_key, keys_only=True
        )
        ffiles = [k.get_async() for k in file_keys]

        self.render_json({
            'files': map(
                self.file_dict,
                [ff.get_result() for ff in ffiles]
            ),
            'cursor': cursor.urlsafe() if cursor else ''
        })
Example #3
0
    def setUp(self):
        super(TestStudentNameApi, self).setUp()

        self.bob = Student.new_student('bob',
                                       'bob smith',
                                       email='*****@*****.**',
                                       year=2015).key.get(use_cache=False)
Example #4
0
    def get(self, studentId):
        """List all the files at destination to a specific student

        """
        student = Student.get_by_id(studentId)
        if not student:
            self.abort(404)

        current_user = self.login_required()
        if (not current_user.is_staff and not current_user.is_admin
                and not current_user.is_domain_admin
                and current_user.student_id != student.key.id()):
            self.abort(403)
            return

        cursor_key = self.request.GET.get('cursor')

        # using cheap request and ndb entities cache
        file_keys, cursor, _ = models.Document.get_files(student.key,
                                                         cursor_key,
                                                         keys_only=True)
        ffiles = [k.get_async() for k in file_keys]

        self.render_json({
            'files':
            map(self.file_dict, [ff.get_result() for ff in ffiles]),
            'cursor':
            cursor.urlsafe() if cursor else ''
        })
Example #5
0
def stats_handler(data):
    pos, line = data

    if not line:
        raise StopIteration
    try:
        stats = json.loads(line)
    except (ValueError, TypeError):
        logging.error("Failed to process rosh review stats: %s", line)
        raise StopIteration

    student_email = stats.get('email', '').lower()
    student_id = User.email_to_student_id(student_email)
    if student_id is None:
        logging.error(
            "Failed to process rosh review stats: invalid student email (%s)",
            line)
        raise StopIteration

    student = Student.get_by_id(student_id)
    if student is None:
        logging.error(
            "Failed to process rosh review stats: student not found (%s)",
            line)
        raise StopIteration

    user_stats = RoshReviewUserStats.new_stats(student, stats, commit=False)
    user_topic_stats = user_stats.update_topic_stats(commit=False)

    yield op.db.Put(user_stats)
    for ts in user_topic_stats:
        yield op.db.Put(ts)

    yield op.counters.Increment('User stats', 1)
    yield op.counters.Increment('User topic stats', len(user_topic_stats))
    def test_get_list(self):
        Student.new_student(
            'bob', 'bob smith', email='*****@*****.**', year=2016
        ).key.get(use_cache=False)
        Student.new_student(
            'alice', 'alice smith', email='*****@*****.**', year=2015
        ).key.get(use_cache=False)

        headers = self.logoff()
        resp = self.app.get(
            '%s/dashboard/pgy' % api.path,
            headers=headers,
        )
        api.validate('PGYList', resp.json)
        self.assertEqual(2, len(resp.json['pgy']))
        self.assertEqual('max-age=300, public', resp.headers['Cache-Control'])
Example #7
0
def row_handler(line_details):
    year = context.get().mapreduce_spec.mapper.params.get('student_year')
    pos, line = line_details

    if not pos:
        # skip header
        raise StopIteration()

    if not year:
        logging.error('Failed to create a new student. The year is missing')
        raise StopIteration()
    row = csv.reader(StringIO.StringIO(line)).next()

    if len(row) < 4:
        logging.error(
            'Failed to create a new student. Some fields are missing: %s',
            line)
        raise StopIteration()

    _, surname, name, email = row[0:4]
    try:
        entity = Student.new_student(surname,
                                     name,
                                     email=email,
                                     year=year,
                                     commit=False)
    except (ValueError, TypeError, ValidationError) as e:
        logging.error(
            'Failed to create a new student. wrong fields: %s.\n'
            'Error: %s', line, e)
        raise StopIteration

    yield op.db.Put(entity)
    yield op.counters.Increment('student added/updated', 1)
    def test_list_stats(self):
        student = Student.new_student(
            'bob', 'bob smith', email='*****@*****.**', year=2015
        ).key.get(use_cache=False)
        roshreview.RoshReviewUserStats.new_stats(
            student,
            {
                "email": "*****@*****.**",
                "training_level": "Resident",
                "pgy": -5,
                "percentage_complete": 0,
                "cumulative_performance": 0,
                "category_performances": {}
            }
        ).key.get(use_cache=False)

        alice = self.new_user(is_staff=True)
        headers = self.login(user=alice)

        resp = self.app.get(
            '%s/dashboard/roshreview/stats' % api.path,
            headers=headers
        ).json
        api.validate('RoshReviewUserStatsList', resp)
        self.assertEqual(1, len(resp['stats']))
        self.assertEqual(0, resp['stats'][0]['performance'])
Example #9
0
 def test_delete_student(self):
     alice = self.new_user(is_staff=True)
     headers = self.login(user=alice)
     self.app.delete('%s/dashboard/students/%s' %
                     (api.path, self.bob.key.id()),
                     headers=headers)
     self.assertIsNone(Student.get_by_id(self.bob.key.id(),
                                         use_cache=False))
Example #10
0
 def test_delete_student_logged_off(self):
     headers = self.logoff()
     self.app.delete('%s/dashboard/students/%s' %
                     (api.path, self.bob.key.id()),
                     headers=headers,
                     status=401)
     self.assertIsNotNone(
         Student.get_by_id(self.bob.key.id(), use_cache=False))
Example #11
0
 def add_student(data):
     display_name, email, year = data
     given_name = display_name.split(' ', 1)[0]
     student = Student.new_student(
         given_name, display_name, email=email, year=year, commit=False
     )
     student.put_async()
     return student
Example #12
0
    def test_get_list(self):
        Student.new_student('bob',
                            'bob smith',
                            email='*****@*****.**',
                            year=2016).key.get(use_cache=False)
        Student.new_student('alice',
                            'alice smith',
                            email='*****@*****.**',
                            year=2015).key.get(use_cache=False)

        headers = self.logoff()
        resp = self.app.get(
            '%s/dashboard/pgy' % api.path,
            headers=headers,
        )
        api.validate('PGYList', resp.json)
        self.assertEqual(2, len(resp.json['pgy']))
        self.assertEqual('max-age=300, public', resp.headers['Cache-Control'])
 def test_delete_student(self):
     alice = self.new_user(is_staff=True)
     headers = self.login(user=alice)
     self.app.delete(
         '%s/dashboard/students/%s' % (api.path, self.bob.key.id()),
         headers=headers
     )
     self.assertIsNone(
         Student.get_by_id(self.bob.key.id(), use_cache=False)
     )
 def test_delete_student_logged_off(self):
     headers = self.logoff()
     self.app.delete(
         '%s/dashboard/students/%s' % (api.path, self.bob.key.id()),
         headers=headers,
         status=401
     )
     self.assertIsNotNone(
         Student.get_by_id(self.bob.key.id(), use_cache=False)
     )
Example #15
0
    def setUp(self):
        super(TestRoshReviewUserStats, self).setUp()

        services.config.ROSH_REVIEW_API_URL_PATTERN = (
            'http://example.com/%s/subscriber_details?'
        )
        services.config.ROSH_REVIEW_API_KEY = 'api-key'

        self.student = Student.new_student(
            'bob', 'bob smith', email='*****@*****.**', year=2015
        ).key.get(use_cache=False)
Example #16
0
    def setUp(self):
        super(TestRoshReviewUserStats, self).setUp()

        services.config.ROSH_REVIEW_API_URL_PATTERN = (
            'http://example.com/%s/subscriber_details?')
        services.config.ROSH_REVIEW_API_KEY = 'api-key'

        self.student = Student.new_student('bob',
                                           'bob smith',
                                           email='*****@*****.**',
                                           year=2015).key.get(use_cache=False)
Example #17
0
    def delete(self, studentId, fileId):
        """Delete a document.

        """
        self.admin_required()

        student = Student.get_by_id(studentId)
        document = models.Document.get_by_id(fileId)
        if (not student or not document
                or document.dest_ref.id() != student.key.id()):
            self.abort(404)

        document.delete()
        self.render_json({'success': True})
Example #18
0
    def new_file(cls, dest_id, blob_info, doc_type, sender=None, name=None):
        dest = Student.get_by_id(dest_id)
        if dest is None:
            raise ValueError("Couldn't find the student to send the file to.")

        data = {
            "name": name if name else blob_info.filename,
            "type": doc_type,
            "sender": sender.display_name if sender else "System",
            "dest": dest.display_name,
            "lastDownloadAt": "",
        }
        doc = cls(id=str(blob_info.key()), data=data, sender_ref=sender.key if sender else None, dest_ref=dest.key)
        doc.put()
        return doc
Example #19
0
    def _get_exams_by_student_id(self, student_id):
        student = Student.get_by_id(student_id)
        if not student:
            self.abort(404, 'User not found')

        current_user = self.login_required()
        if (not current_user.is_staff and not current_user.is_admin
                and not current_user.is_domain_admin
                and student.key.id() != current_user.student_id):
            self.abort(403)

        exams = models.AssessmentExam.get_by_student_id(student.key.id())
        self.render_json({
            'cursor': '',
            'exams': [e.summary() for e in exams],
            'student': student.summary()
        })
Example #20
0
    def delete(self, studentId, fileId):
        """Delete a document.

        """
        self.admin_required()

        student = Student.get_by_id(studentId)
        document = models.Document.get_by_id(fileId)
        if (
            not student
            or not document
            or document.dest_ref.id() != student.key.id()
        ):
            self.abort(404)

        document.delete()
        self.render_json({'success': True})
    def setUp(self):
        super(TestRoshReviewUserStatsApi, self).setUp()

        student = Student.new_student(
            'bob', 'bob smith', email='*****@*****.**', year=2015
        ).key.get(use_cache=False)
        roshreview.RoshReviewUserStats.new_stats(
            student,
            {
                "email": "*****@*****.**",
                "training_level": "Resident",
                "pgy": -5,
                "percentage_complete": 0,
                "cumulative_performance": 0,
                "category_performances": {
                    "FOO": 0
                }
            }
        ).key.get(use_cache=False)
Example #22
0
    def new_file(cls, dest_id, blob_info, doc_type, sender=None, name=None):
        dest = Student.get_by_id(dest_id)
        if dest is None:
            raise ValueError("Couldn't find the student to send the file to.")

        data = {
            'name': name if name else blob_info.filename,
            'type': doc_type,
            'sender': sender.display_name if sender else 'System',
            'dest': dest.display_name,
            'lastDownloadAt': ''
        }
        doc = cls(
            id=str(blob_info.key()),
            data=data,
            sender_ref=sender.key if sender else None,
            dest_ref=dest.key
        )
        doc.put()
        return doc
Example #23
0
    def _get_exams_by_student_id(self, student_id):
        student = Student.get_by_id(student_id)
        if not student:
            self.abort(404, 'User not found')

        current_user = self.login_required()
        if (
            not current_user.is_staff
            and not current_user.is_admin
            and not current_user.is_domain_admin
            and student.key.id() != current_user.student_id
        ):
            self.abort(403)

        exams = models.AssessmentExam.get_by_student_id(student.key.id())
        self.render_json({
            'cursor': '',
            'exams': [e.summary() for e in exams],
            'student': student.summary()
        })
    def setUp(self):
        super(TestRepositoryDocumentApi, self).setUp()

        self.admin = self.new_user(is_admin=True)
        self.student = Student.new_student(
            'bob', 'bob smith', email='*****@*****.**', year=2015
        ).key.get(use_cache=False)

        file_name = files.blobstore.create(mime_type='text/plain')
        with files.open(file_name, 'a') as f:
            f.write('test')
        files.finalize(file_name)
        blob_key = files.blobstore.get_blob_key(file_name)

        self.document = models.Document.new_file(
            self.student.key.id(),
            BlobInfo.get(blob_key),
            'SHELF',
            sender=self.admin,
            name='test'
        ).key.get(use_cache=False)
    def test_archive_year(self):
        Student.new_student(
            'bob', 'bob smith', email='*****@*****.**', year=2016
        ).key.get(use_cache=False)
        Student.new_student(
            'alice', 'alice smith', email='*****@*****.**', year=2015
        ).key.get(use_cache=False)

        bob = self.new_user(is_staff=True)
        headers = self.login(user=bob)
        self.app.delete(
            '%s/dashboard/pgy/2016' % api.path,
            headers=headers,
        )
        self.assertTrue(Student.get_by_id('A0002', use_cache=False).is_active)
        self.assertFalse(Student.get_by_id('A0001', use_cache=False).is_active)
Example #26
0
def stats_handler(data):
    pos, line = data

    if not line:
        raise StopIteration
    try:
        stats = json.loads(line)
    except (ValueError, TypeError):
        logging.error("Failed to process rosh review stats: %s", line)
        raise StopIteration

    student_email = stats.get('email', '').lower()
    student_id = User.email_to_student_id(student_email)
    if student_id is None:
        logging.error(
            "Failed to process rosh review stats: invalid student email (%s)",
            line
        )
        raise StopIteration

    student = Student.get_by_id(student_id)
    if student is None:
        logging.error(
            "Failed to process rosh review stats: student not found (%s)",
            line
        )
        raise StopIteration

    user_stats = RoshReviewUserStats.new_stats(
        student, stats, commit=False
    )
    user_topic_stats = user_stats.update_topic_stats(commit=False)

    yield op.db.Put(user_stats)
    for ts in user_topic_stats:
        yield op.db.Put(ts)

    yield op.counters.Increment('User stats', 1)
    yield op.counters.Increment('User topic stats', len(user_topic_stats))
Example #27
0
    def test_archive_year(self):
        Student.new_student('bob',
                            'bob smith',
                            email='*****@*****.**',
                            year=2016).key.get(use_cache=False)
        Student.new_student('alice',
                            'alice smith',
                            email='*****@*****.**',
                            year=2015).key.get(use_cache=False)

        bob = self.new_user(is_staff=True)
        headers = self.login(user=bob)
        self.app.delete(
            '%s/dashboard/pgy/2016' % api.path,
            headers=headers,
        )
        self.assertTrue(Student.get_by_id('A0002', use_cache=False).is_active)
        self.assertFalse(Student.get_by_id('A0001', use_cache=False).is_active)
 def setUp(self):
     super(TestAssessmentExamListApi, self).setUp()
     Student.new_student(
         'alice', 'alice smith', email='*****@*****.**', year=2015
     ).key.get(use_cache=False)
     self.alice = self.new_user(student_id='A0001')
    def setUp(self):
        super(TestStudentNameApi, self).setUp()

        self.bob = Student.new_student(
            'bob', 'bob smith', email='*****@*****.**', year=2015
        ).key.get(use_cache=False)
Example #30
0
 def setUp(self):
     super(TestFirstAidUserStats, self).setUp()
     self.student = Student.new_student(
         'bob', 'bob smith', email='*****@*****.**', year=2015
     ).key.get(use_cache=False)
Example #31
0
 def setUp(self):
     super(TestFirstAidUserStats, self).setUp()
     self.student = Student.new_student('bob',
                                        'bob smith',
                                        email='*****@*****.**',
                                        year=2015).key.get(use_cache=False)