def test_create_new_course_then_modify_same_course(self):
        """
        create a new course then modify it 
        """
        self.create_google_user(user_id = '123')
        author = self.create_and_return_local_user(googleID = '123')
        data = {
            'title' : 'foo', 
            'body' : 'bar', 
            'content_type' : 'course',
            }
        response = self.testapp.post('/api/curriculum', data)
        self.assertEqual(Curriculum.query().count(), 1)
        response_data = json.loads(response.body)
        course_id = response_data['id']

        # now update the title and send another request
        data['title'] = 'updated foo'
        new_response = self.testapp.post(
            '/api/curriculum/%s' % course_id, 
            data
            )
        new_response_data = json.loads(response.body)
        self.assertNotIn('error', new_response_data)
        self.assertEqual(Curriculum.query().count(), 1)
        db_course = Curriculum.query().get()
        self.assertEqual(db_course.content['title'], 'updated foo')
Пример #2
0
 def test_new_approval_request(self):
     """
     create a new approval and assert that it shows up in the database
     """
     self.create_new_approval()
     course = Curriculum.query().get()
     self.assertIn(123, course.content['pending_approval'])
Пример #3
0
 def test_new_approval_request(self):
     """
     create a new approval and assert that it shows up in the database
     """
     self.create_new_approval()
     course = Curriculum.query().get()
     self.assertIn(123, course.content['pending_approval'])
Пример #4
0
 def test_get_approved_users(self):
     """
     create a course, add a few approval requests, 
     and assert that they are retrieved correctly
     """
     self.create_several_approvals_for_course(1)
     course = Curriculum.query().get()
     self.assertEqual(
         course.content['pending_approval'],
         [1, 2, 3, 4, 5],
     )
Пример #5
0
 def test_get_approved_users(self):
     """
     create a course, add a few approval requests, 
     and assert that they are retrieved correctly
     """
     self.create_several_approvals_for_course(1)
     course = Curriculum.query().get()
     self.assertEqual(
         course.content['pending_approval'], 
         [1,2,3,4,5],
         )
Пример #6
0
    def test_get_public_course(self):
        """
        test api response for a request of a publically available course
        at /api/curriculum{{courseID}}

        we'll first create a bunch of course material, then we'll determine 
        the id of the first user and their first course that was generated
        """
        self.create_sample_course_framework(1, 1, 1)
        user_id = User.query().get().key.id()
        course_id = Curriculum.query(
            Curriculum.content_type == 'course').get().key.id()
        response = self.testapp.get('/api/curriculum/%s' % course_id)
        self.assertEqual(response.status_int, 200)

        self.assertEqual(response.content_type, 'application/json')
        data = json.loads(response.body)
        self.assertNotIn('error', data)
        self.assertEqual(data['id'], course_id)
        self.assertEqual(data['content']['title'], 'Foo Course 0')
        self.assertEqual(data['content_type'], 'course')
Пример #7
0
    def test_get_public_course(self):
        """
        test api response for a request of a publically available course
        at /api/curriculum{{courseID}}

        we'll first create a bunch of course material, then we'll determine 
        the id of the first user and their first course that was generated
        """
        self.create_sample_course_framework(1,1,1)
        user_id = User.query().get().key.id()
        course_id = Curriculum.query(
            Curriculum.content_type == 'course'
            ).get().key.id()
        response = self.testapp.get('/api/curriculum/%s' % course_id)
        self.assertEqual(response.status_int, 200)

        self.assertEqual(response.content_type, 'application/json')
        data = json.loads(response.body)
        self.assertNotIn('error', data)
        self.assertEqual(data['id'], course_id)
        self.assertEqual(data['content']['title'], 'Foo Course 0')
        self.assertEqual(data['content_type'], 'course')
Пример #8
0
    def get(self, migration_type=None):
        current_user = users.get_current_user()
        if current_user.email() != '*****@*****.**':
            abort(403)
        else:
            if migration_type == 'clear_content':
                ndb.delete_multi(Curriculum.query().fetch(keys_only=True))

            elif migration_type == 'clear_teacher_courses':
                teachers = User.query()
                for teacher in teachers:
                    logging.info('clearing courses for %s' % teacher.key.id())
                    teacher.courses = []
                    teacher.put()
                    logging.info('Completed clearing courses for %s' % teacher.key.id())

            elif migration_type == 'course':
                courses = Content.query(Content.contentType == 'course')
                for course in courses:
                    if course.listed != 'done_migrating3':
                        try:
                            logging.info("Begin course migration for %s" % course.key.id())
                            app_user = course.key.parent().get()
                            teacher = get_user_by_google_id(app_user.googleID)
                            course_data = {
                                'teacher' : teacher.key.id(),
                                'title' : course.title,
                                'body' : course.body
                            }
                            new_course_id = new_course(course_data)
                            logging.info("Saved data for Curriculum ID: %s" % new_course_id)
                            units = Content.query(Content.contentType == 'unit', ancestor=course.key)
                            for unit in units:
                                logging.info("Begin unit migration for %s" % unit.key.id())
                                unit_data = {
                                    'teacher' : teacher.key.id(),
                                    'course' : new_course_id,
                                    'title' : unit.title,
                                    'body' : unit.body
                                }
                                new_unit_id = new_unit(unit_data)
                                logging.info("Saved data for Unit ID: %s" % new_unit_id)

                                lessons = Content.query(Content.contentType == 'lesson', ancestor=unit.key)
                                for lesson in lessons:
                                    logging.info("Begin lesson migration for %s" % lesson.key.id())
                                    lesson_data = {
                                        'teacher' : teacher.key.id(),
                                        'course' : new_course_id,
                                        'unit' : new_unit_id,
                                        'title' : lesson.title,
                                        'body' : lesson.body
                                    }
                                    lesson_id = new_lesson(lesson_data)
                                    logging.info("Saved data for Lesson ID: %s" % lesson_id)

                            course.listed = 'done_migrating3'
                            course.put()
                            logging.info("Finished course migration for %s" % course.key.id())
                        except Exception as e:
                            logging.info("Error migrating course %s" % course.key.id())
                            logging.info(str(e))


            return render_template(
                'migrate.html',
                status_msg = 'migration complete'
                )