def test_separate_children(self): """ Test that a course's modules list endpoint doesn't contain modules from other courses. """ m1 = ModuleFactory.create() m2 = ModuleFactory.create() # Different courses self.assertNotEqual(m1.course, m2.course) resp = self.client.get(reverse('module-list', args=(m1.course.uuid,))) payload = json.loads(resp.content.decode('utf-8')) assert payload == [module_detail_dict(m1)]
def handle(self, *args, **options): record_count = 0 try: bi = BackingInstance.objects.get(instance_url='https://edx.org') except BackingInstance.DoesNotExist: bi = BackingInstanceFactory.create(instance_url='https://edx.org') for _ in range(int(options['courses'])): course = CourseFactory.create(edx_instance=bi) record_count += 1 module_range = range(randint(1, int(options['modules']))) for _ in module_range: record_count += 1 ModuleFactory.create(course=course) self.stdout.write("Wrote {} records.".format(record_count))
def handle(self, *args, **options): try: bi = BackingInstance.objects.get(instance_url='https://edx.org') except BackingInstance.DoesNotExist: bi = BackingInstanceFactory.create(instance_url='https://edx.org') course_title = 'Advanced Introductory Classical Mechanics' try: c = Course.objects.get(title=course_title) for m in c.module_set.all(): m.delete() except Course.DoesNotExist: c = CourseFactory.create( edx_instance=bi, title=course_title, author_name='David E. Prichard', description='Mechanics ReView presents a college-level introductory mechanics ' 'class using a strategic problem-solving approach.', overview='For more information, see <a href="#">edx.org</a>', image_url='https://www.edx.org/sites/default/files/styles/course_video_banner' '/public/course/image/featured-card/8.mechcx-378x225.jpg', ) module_names = """0: Introduction 1: Newton's Laws of Motion 2: Interactions and Forces 3: Applying Newton's Laws 4: Kinematics, the Mathematical Description of Motion 5: Models of 1D Motion 6: Applying SIM to Problems in Planar Dynamics 7: System of Particles---Linear Momentum and Impulse 8: Energy and Work 9: Potential Energy and Mechanical Energy 10: Torque and Rotation about a Fixed Axis 11: Describing Rotational and Translational Motion 12: Angular Momentum and Its Conservation 13: Universal Gravity and Orbital Motion 14: Simple Harmonic Oscillation 15: Drag Forces Final Exam and Survey Optional Unit: Review for the AP Exam""" for i, module in enumerate(module_names.split('\n')): ModuleFactory.create(course=c, title=module.strip(), order=i) self.stdout.write("Done.")
def test_illegal_methods(self): """ Assert that we are not using certain HTTP methods. """ module = ModuleFactory.create() course_list = reverse('course-list') course_detail = reverse('course-detail', kwargs={"uuid": module.course.uuid}) module_list = reverse('module-list', kwargs={"uuid_uuid": module.course.uuid}) module_detail = reverse('module-detail', kwargs={ "uuid_uuid": module.course.uuid, "uuid": module.uuid }) for url in (course_list, course_detail, module_list, module_detail): assert self.client.patch(url).status_code == 405 assert self.client.put(url).status_code == 405 assert self.client.delete(url).status_code == 405 for url in (course_detail, module_list, module_detail): assert self.client.post(url).status_code == 405
def test_get_module_detail(self): """ The module detail API should show information about a specific module. """ module = ModuleFactory.create() resp = self.client.get(reverse('module-detail', kwargs={ "uuid_uuid": module.course.uuid, "uuid": module.uuid })) assert resp.status_code == 200, resp.content.decode('utf-8') payload = json.loads(resp.content.decode('utf-8')) assert payload == module_detail_dict(module) # Make sure users not logged in can't list courses self.client.logout() resp = self.client.get(reverse('module-detail', kwargs={ "uuid_uuid": module.course.uuid, "uuid": module.uuid })) assert resp.status_code == 401, resp.content.decode('utf-8')