def test_course_list(self, mock_get_content_metadata): """ Test courses list view produces desired json """ mock_get_content_metadata.return_value = get_fake_content_metadata() url = '{path}?ciid={customer_uuid}'.format( path=self.course_list_url, customer_uuid=self.enterprise_customer_catalog.enterprise_customer. uuid) response = self.client.get(url) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(len(response.data), 3) keys = {key for item in response.data for key in item.keys()} expected_keys = [ "ID", "URL", "IsActive", "LastModifiedUTC", "Title", "Description", "Thumbnail", "Owners", "Languages", "Subjects", ] for key in expected_keys: self.assertIn(key, keys) # required fields should not be empty required_keys = ["Owners", "Languages", "Subjects"] for item in response.data: for key in required_keys: self.assertTrue(item[key])
def test_course_list_with_skip_key_if_none_false( self, mock_get_content_metadata): """ Test courses list view produces desired json when SKIP_KEY_IF_NONE is set to False """ mock_get_content_metadata.return_value = get_fake_content_metadata() url = '{path}?ciid={customer_uuid}'.format( path=self.course_list_url, customer_uuid=self.enterprise_customer_catalog.enterprise_customer. uuid) with mock.patch( 'integrated_channels.cornerstone.models.CornerstoneContentMetadataExporter.SKIP_KEY_IF_NONE', new_callable=mock.PropertyMock) as mock_skip_key_if_none: mock_skip_key_if_none.return_value = False response = self.client.get(url) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(len(response.data), 3) keys = {key for item in response.data for key in item.keys()} expected_keys = [ "ID", "URL", "IsActive", "LastModifiedUTC", "Title", "Description", "Thumbnail", "Duration", "Owners", "Languages", "Subjects", ] for key in expected_keys: self.assertIn(key, keys)
def test_content_exporter_export(self, mock_get_content_metadata): """ ``DegreedContentMetadataExporter``'s ``export`` produces the expected export. """ mock_get_content_metadata.return_value = get_fake_content_metadata() exporter = DegreedContentMetadataExporter('fake-user', self.config) content_items = exporter.export() assert sorted(list(content_items.keys())) == sorted([ 'edX+DemoX', 'course-v1:edX+DemoX+Demo_Course', FAKE_UUIDS[3], ])
def test_content_exporter_bad_data_transform_mapping(self, mock_api_client): """ ``ContentMetadataExporter``'s ``export`` raises an exception when DATA_TRANSFORM_MAPPING is invalid. """ mock_api_client.return_value.get_content_metadata.return_value = get_fake_content_metadata() ContentMetadataExporter.DATA_TRANSFORM_MAPPING['fake-key'] = 'fake-value' exporter = ContentMetadataExporter('fake-user', self.config) with LogCapture(level=logging.ERROR) as log_capture: exporter.export() expected_message = 'Failed to transform content metadata item field [{}] for [{}]'.format( 'fake-value', self.enterprise_customer_catalog.enterprise_customer.name ) assert expected_message in log_capture.records[0].getMessage()
def test_content_exporter_export(self, mock_get_content_metadata): """ ``MoodleContentMetadataExporter``'s ``export`` produces the expected export. """ mock_get_content_metadata.return_value = get_fake_content_metadata() exporter = MoodleContentMetadataExporter('fake-user', self.config) content_items = exporter.export() assert sorted(list(content_items.keys())) == sorted([ 'edX+DemoX', 'course-v1:edX+DemoX+Demo_Course', FAKE_UUIDS[3], ]) for item in content_items.values(): self.assertTrue( set(['categoryid', 'summary']).issubset(set(item.channel_metadata.keys())))
def test_content_exporter_export(self, mock_get_content_metadata): """ ``CanvasContentMetadataExporter``'s ``export`` produces the expected export. """ mock_get_content_metadata.return_value = get_fake_content_metadata() exporter = CanvasContentMetadataExporter('fake-user', self.config) content_items = exporter.export() assert sorted(list(content_items.keys())) == sorted([ 'edX+DemoX', 'course-v1:edX+DemoX+Demo_Course', FAKE_UUIDS[3], ]) for item in content_items.values(): self.assertTrue( set(['syllabus_body', 'default_view', 'name']).issubset(set(item.channel_metadata.keys())))
def test_export_with_catalogs_to_transmit(self, mock_get_content_metadata): """ ``ContentMetadataExporter``'s ``export`` produces a JSON dump of the course data. """ mock_get_content_metadata.return_value = get_fake_content_metadata() exporter = ContentMetadataExporter('fake-user', self.config) exporter.export() assert mock_get_content_metadata.called assert mock_get_content_metadata.call_args[0][0] == self.enterprise_customer_catalog.enterprise_customer # 'catalogs_to_transmit' argument was empty list so all the catalogs will be transmitted. assert mock_get_content_metadata.call_args[1]['enterprise_catalogs'] == [] self.config.catalogs_to_transmit = str(self.enterprise_customer_catalog.uuid) self.config.save() exporter.export() assert mock_get_content_metadata.called assert mock_get_content_metadata.call_args[0][0] == self.enterprise_customer_catalog.enterprise_customer # 'catalogs_to_transmit' argument has valid uuid so only that catalog will be transmitted. assert mock_get_content_metadata.call_args[1]['enterprise_catalogs'].first().uuid == \ self.config.customer_catalogs_to_transmit.first().uuid