class CourseSpiderTest(unittest.TestCase):

    def setUp(self):
        self.spider = CourseSpiderNew()
        self.department_list_page = os.path.join(data_dir(), 'DTU_Coursebase.html')
        self.department_27_page = os.path.join(data_dir(), 'Department27.html')
        self.course_27002_page = os.path.join(data_dir(), '27002.html')
        self.course_27002_info_page = os.path.join(data_dir(), '27002_information.html')
        self.course_27002_course_run_page = os.path.join(data_dir(), '27002_course_run_summer_2010.html')
        self.course_27002_evaluation_page = os.path.join(data_dir(), '27002_evaluation.html')

    def _check_departments(self, results):
        expected = [
            DepartmentItem(code = '27', title_en = 'Department of Systems Biology'),
            DepartmentItem(code = '11', title_en = 'Department of Civil Engineering'),
        ]
        departments = [item.meta['department'] for item in results]
        self.assertEqual(expected, departments)

    def test_parse(self):
        results = self.spider.parse(fake_response_from_file(self.department_list_page))
        result_list = list(results)
        assert_that(result_list, has_length(21))
        #assert_that(result_list, has_length(1))

    def test_parse_department_page(self):
        response = fake_response_from_file(self.department_27_page)
        response.meta['department'] = DepartmentItem()
        results = self.spider.parse_department_page(response)
        result_list = list(results)
        self.assertEqual(len(result_list), 64)

    def test_parse_course(self):
        response = fake_response_from_file(self.course_27002_page)
        response.meta['department'] = DepartmentItem()
        actual = self.spider.parse_course(response)

        self.assertEqual(u'27002', actual['code'])
        self.assertEqual(u'Danish', actual['language'])
        self.assertEqual(u'Life Science', actual['title_en'])
        self.assertEqual(u'Biovidenskab', actual['title_da'])
        self.assertEqual(u'7 step scale', actual['evaluation_type'])
        self.assertEqual(5.0, actual['ects_credits'])
        self.assertEqual(u'BSc', actual['course_type'])

    @unittest.skip("skipping unimplemented method test")
    def test_parse_course_information_page(self):
        response = fake_response_from_file(self.course_27002_info_page)
        response.meta['course'] = CourseItem()
        response.meta['department'] = DepartmentItem()
        results = self.spider.parse_course_information_page(response)
        self.assertEqual(len(list(results)), 17 + 5)
 def setUp(self):
     self.spider = CourseSpiderNew()
     self.department_list_page = os.path.join(data_dir(), 'DTU_Coursebase.html')
     self.department_27_page = os.path.join(data_dir(), 'Department27.html')
     self.course_27002_page = os.path.join(data_dir(), '27002.html')
     self.course_27002_info_page = os.path.join(data_dir(), '27002_information.html')
     self.course_27002_course_run_page = os.path.join(data_dir(), '27002_course_run_summer_2010.html')
     self.course_27002_evaluation_page = os.path.join(data_dir(), '27002_evaluation.html')