Exemple #1
0
    def test_upsert_oai_identifier_raises_exception_if_save_failed(
            self, mock_save):
        # Arrange
        mock_save.side_effect = Exception()

        # Act + Assert
        with self.assertRaises(Exception):
            oai_identify_api.upsert(self.oai_identify)
def _upsert_identify_for_registry(identify, registry):
    """ Adds or updates an identify object for a registry.

    Args:
        identify: OaiIdentify instance.
        registry: OaiRegistry instance.

    """
    try:
        identify_db = oai_identify_api.get_by_registry_id(registry.id)
        identify.id = identify_db.id
    except exceptions.DoesNotExist:
        pass

    identify.registry = registry
    api_oai_identify.upsert(identify)
Exemple #3
0
    def test_upsert_oai_identify_with_raw_return_object(self, mock_create):
        # Arrange
        mock_create.return_value = self.oai_identify

        # Act
        result = oai_identify_api.upsert(self.oai_identify)

        # Assert
        self.assertIsInstance(result, OaiIdentify)
Exemple #4
0
    def test_upsert_oai_identify_invalid_raw_return_object(self, mock_create):
        # Arrange
        self.oai_identify.raw = '<root?</root>'

        mock_create.return_value = self.oai_identify

        # Act
        result = oai_identify_api.upsert(self.oai_identify)

        # Act + Assert
        self.assertIsInstance(result, OaiIdentify)
Exemple #5
0
    def test_upsert_oai_identify_no_exception_if_raw_not_string(
            self, mock_create):
        # Arrange
        self.oai_identify.raw = OrderedDict([(u'test', u'Hello')])

        mock_create.return_value = self.oai_identify

        # Act
        result = oai_identify_api.upsert(self.oai_identify)

        # Assert
        self.assertIsInstance(result, OaiIdentify)
Exemple #6
0
    def test_upsert_oai_identify_invalid_raw_return_empty_raw(
            self, mock_create):
        # Arrange
        self.oai_identify.raw = '<root?</root>'

        mock_create.return_value = self.oai_identify

        # Act
        result = oai_identify_api.upsert(self.oai_identify)

        # Act + Assert
        self.assertEquals(result.raw, {})