def test_content_exporter_export(self):
     """
     ``ContentMetadataExporter``'s ``export`` produces a JSON dump of the course data.
     """
     exporter = ContentMetadataExporter('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):
     """
     ``ContentMetadataExporter``'s ``export`` raises an exception when DATA_TRANSFORM_MAPPING is invalid.
     """
     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_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
Beispiel #4
0
 def get_content_metadata_exporter(self, user):
     """
     Returns a class that can retrieve and transform content metadata to the schema
     expected by the integrated channel.
     """
     return ContentMetadataExporter(user, self)