Beispiel #1
0
    def test_transmit_create_failure(self):
        """
        Test unsuccessful creation of content metadata during transmission.
        """
        content_id = 'course:DemoX'
        channel_metadata = {'update': True}
        payload = {
            content_id:
            ContentMetadataItemExport(
                {
                    'key': content_id,
                    ContentType.METADATA_KEY: ContentType.COURSE,
                },
                channel_metadata,
            )
        }
        self.create_content_metadata_mock.side_effect = ClientError(
            'error occurred')
        transmitter = ContentMetadataTransmitter(self.enterprise_config)
        transmitter.transmit(payload)

        self.create_content_metadata_mock.assert_called()
        self.update_content_metadata_mock.assert_not_called()
        self.delete_content_metadata_mock.assert_not_called()

        assert not ContentMetadataItemTransmission.objects.filter(
            enterprise_customer=self.enterprise_config.enterprise_customer,
            integrated_channel_code=self.enterprise_config.channel_code(),
            content_id=content_id,
        )
Beispiel #2
0
    def test_transmit_create_success(self):
        """
        Test successful creation of content metadata during transmission.
        """
        content_id = 'course:DemoX'
        channel_metadata = {'update': True}
        payload = {
            content_id:
            ContentMetadataItemExport(
                {
                    'key': content_id,
                    ContentType.METADATA_KEY: ContentType.COURSE
                },
                channel_metadata,
            )
        }
        self.create_content_metadata_mock.return_value = (200,
                                                          '{"success":"true"}')
        transmitter = ContentMetadataTransmitter(self.enterprise_config)
        transmitter.transmit(payload)

        self.create_content_metadata_mock.assert_called()
        self.update_content_metadata_mock.assert_not_called()
        self.delete_content_metadata_mock.assert_not_called()

        created_transmission = ContentMetadataItemTransmission.objects.get(
            enterprise_customer=self.enterprise_config.enterprise_customer,
            integrated_channel_code=self.enterprise_config.channel_code(),
            content_id=content_id,
        )

        assert created_transmission.channel_metadata == channel_metadata
Beispiel #3
0
    def test_transmit_delete_failure(self):
        """
        Test successful deletion of content metadata during transmission.
        """
        content_id = 'course:DemoX'
        channel_metadata = {'update': True}
        ContentMetadataItemTransmission(
            enterprise_customer=self.enterprise_config.enterprise_customer,
            integrated_channel_code=self.enterprise_config.channel_code(),
            content_id=content_id,
            channel_metadata=channel_metadata).save()
        payload = {}
        self.delete_content_metadata_mock.side_effect = ClientError(
            'error occurred')
        transmitter = ContentMetadataTransmitter(self.enterprise_config)
        transmitter.transmit(payload)

        self.create_content_metadata_mock.assert_not_called()
        self.update_content_metadata_mock.assert_not_called()
        self.delete_content_metadata_mock.assert_called()

        assert ContentMetadataItemTransmission.objects.filter(
            enterprise_customer=self.enterprise_config.enterprise_customer,
            integrated_channel_code=self.enterprise_config.channel_code(),
            content_id=content_id,
        )
Beispiel #4
0
    def test_transmit_delete_success(self):
        """
        Test successful deletion of content metadata during transmission.
        """
        content_id = 'course:DemoX'
        channel_metadata = {'update': True}
        ContentMetadataItemTransmission(
            enterprise_customer=self.enterprise_config.enterprise_customer,
            integrated_channel_code=self.enterprise_config.channel_code(),
            content_id=content_id,
            channel_metadata=channel_metadata).save()
        payload = {}
        self.delete_content_metadata_mock.return_value = (200,
                                                          '{"success":"true"}')
        transmitter = ContentMetadataTransmitter(self.enterprise_config)
        transmitter.transmit(payload)

        self.create_content_metadata_mock.assert_not_called()
        self.update_content_metadata_mock.assert_not_called()
        self.delete_content_metadata_mock.assert_called()

        assert not ContentMetadataItemTransmission.objects.filter(
            enterprise_customer=self.enterprise_config.enterprise_customer,
            integrated_channel_code=self.enterprise_config.channel_code(),
            content_id=content_id,
        )
Beispiel #5
0
    def test_transmit_update_not_needed(self):
        """
        Test successful update of content metadata during transmission.
        """
        content_id = 'course:DemoX'
        channel_metadata = {'update': True}
        ContentMetadataItemTransmission(
            enterprise_customer=self.enterprise_config.enterprise_customer,
            integrated_channel_code=self.enterprise_config.channel_code(),
            content_id=content_id,
            channel_metadata=channel_metadata).save()
        payload = {
            content_id:
            ContentMetadataItemExport(
                {
                    'key': content_id,
                    ContentType.METADATA_KEY: ContentType.COURSE
                },
                channel_metadata,
            )
        }
        transmitter = ContentMetadataTransmitter(self.enterprise_config)
        transmitter.transmit(payload)

        self.create_content_metadata_mock.assert_not_called()
        self.update_content_metadata_mock.assert_not_called()
        self.delete_content_metadata_mock.assert_not_called()
Beispiel #6
0
    def test_transmit_update_failure(self):
        """
        Test unsuccessful update of content metadata during transmission.
        """
        content_id = 'course:DemoX'
        channel_metadata = {'update': True}
        ContentMetadataItemTransmission(
            enterprise_customer=self.enterprise_config.enterprise_customer,
            integrated_channel_code=self.enterprise_config.channel_code(),
            content_id=content_id,
            channel_metadata={}).save()
        payload = {
            content_id:
            ContentMetadataItemExport(
                {
                    'key': content_id,
                    'content_type': 'course'
                }, channel_metadata)
        }
        self.update_content_metadata_mock.side_effect = ClientError(
            'error occurred')
        transmitter = ContentMetadataTransmitter(self.enterprise_config)
        transmitter.transmit(payload)

        self.create_content_metadata_mock.assert_not_called()
        self.update_content_metadata_mock.assert_called()
        self.delete_content_metadata_mock.assert_not_called()

        updated_transmission = ContentMetadataItemTransmission.objects.get(
            enterprise_customer=self.enterprise_config.enterprise_customer,
            integrated_channel_code=self.enterprise_config.channel_code(),
            content_id=content_id,
        )

        assert updated_transmission.channel_metadata == {}
Beispiel #7
0
 def get_content_metadata_transmitter(self):
     """
     Returns a class that can transmit the content metadata to the integrated channel.
     """
     return ContentMetadataTransmitter(self)