示例#1
0
    def test_init(self):
        """ Verify the constructor requires a non-empty string for the ID. """
        msg = 'Course ID cannot be empty or None.'

        with self.assertRaisesRegex(ValueError, msg):
            Course(None)

        with self.assertRaisesRegex(ValueError, msg):
            Course('')
示例#2
0
    def test_eq(self):
        """ Verify the __eq__ method returns True if two Course objects have the same `id`. """
        course = CourseFactory()

        # Both objects must be of type Course
        self.assertNotEqual(course, 1)

        # A Course should be equal to itself
        self.assertEqual(course, course)

        # Two Courses are equal if their id attributes match
        self.assertEqual(course, Course(id=course.id, body=course.body))
示例#3
0
    def test_save(self):
        """ Verify the method creates and/or updates new courses. """
        course_id = 'TestX/Saving/4T2015'
        body = {'id': course_id, 'name': 'Save Me!'}

        self.assertFalse(
            self.es.exists(index=self.index,
                           doc_type=Course.doc_type,
                           id=course_id))
        Course(course_id, body).save()
        self.refresh_index()

        self.assertTrue(
            self.es.exists(index=self.index,
                           doc_type=Course.doc_type,
                           id=course_id))
        course = Course.get(course_id)
        self.assertEqual(course.id, course_id)
        self.assertEqual(course.body, body)
示例#4
0
 def test_name(self):
     """ Verify the method returns the course name. """
     name = 'ABC Course'
     course = Course('a/b/c', {'name': name})
     self.assertEqual(course.name, name)