예제 #1
0
 def test_external_api_attributes(self):
     """
     Validate that the :obj:`IExternalAPIMock` object.
     """
     self.assertTrue(IExternalAPIMock.providedBy(self.eeapi))
     self.assertIsInstance(self.eeapi.name_key, text_type)
     self.assertEqual(self.eeapi.name_key, self.eeapi_name)
예제 #2
0
 def test_external_api_attributes(self):
     """
     Validate that the :obj:`IExternalAPIMock` object.
     """
     self.assertTrue(IExternalAPIMock.providedBy(self.eeapi))
     self.assertIsInstance(self.eeapi.name_key, text_type)
     self.assertEqual(self.eeapi.name_key, self.eeapi_name)
예제 #3
0
파일: core.py 프로젝트: pratikmallya/mimic
    def add_api(self, api):
        """
        Add a new API to the listing.

        :param object api: An object implementing either the
            :obj:`IAPIMock` or :obj:`IExternalAPIMock` interfaces.
        :raises: TypeError if the object does not implement the
            correct interfaces.
        """
        # Gate check the API to make sure it implements one of the
        # supported interfaces
        if IExternalAPIMock.providedBy(api):
            this_api_id = ((api.name_key) + '-' +
                           random_hex_generator(3))
            self._uuid_to_api_external[this_api_id] = api
        elif IAPIMock.providedBy(api):
            this_api_id = ((api.__class__.__name__) + '-' +
                           random_hex_generator(3))
            self._uuid_to_api_internal[this_api_id] = api
        else:
            raise TypeError(
                api.__class__.__module__ + '/' +
                api.__class__.__name__ +
                " does not implement IAPIMock or IExternalAPIMock"
            )
예제 #4
0
파일: core.py 프로젝트: BenjamenMeyer/mimic
    def add_api(self, api):
        """
        Add a new API to the listing.

        :param object api: An object implementing either the
            :obj:`IAPIMock` or :obj:`IExternalAPIMock` interfaces.
        :raises: TypeError if the object does not implement the
            correct interfaces.
        """
        # Gate check the API to make sure it implements one of the
        # supported interfaces
        if IExternalAPIMock.providedBy(api):
            # External APIs need to be able to be easily managed by
            # the same object so long as they have the same uuid
            this_api_id = api.uuid_key

            if this_api_id in self._uuid_to_api_external:
                raise ServiceIdExists(
                    'An Existing API already exists with the given UUID'
                )

            for existing_api in self._uuid_to_api_external.values():
                if existing_api.name_key == api.name_key:
                    raise ServiceNameExists(
                        'An Existing API with UUID ' + existing_api.uuid_key +
                        ' is already using that name'
                    )
            self._uuid_to_api_external[this_api_id] = api
        elif IAPIMock.providedBy(api):
            # Internal APIs can be added easily on the fly since
            # they also provide the resource for implementing the API
            this_api_id = ((api.__class__.__name__) + '-' +
                           random_hex_generator(3))
            self._uuid_to_api_internal[this_api_id] = api
        else:
            raise ServiceBadInterface(
                api.__class__.__module__ + '/' +
                api.__class__.__name__ +
                " does not implement IAPIMock or IExternalAPIMock"
            )
예제 #5
0
    def add_api(self, api):
        """
        Add a new API to the listing.

        :param object api: An object implementing either the
            :obj:`IAPIMock` or :obj:`IExternalAPIMock` interfaces.
        :raises: TypeError if the object does not implement the
            correct interfaces.
        """
        # Gate check the API to make sure it implements one of the
        # supported interfaces
        if IExternalAPIMock.providedBy(api):
            # External APIs need to be able to be easily managed by
            # the same object so long as they have the same uuid
            this_api_id = api.uuid_key

            if this_api_id in self._uuid_to_api_external:
                raise ServiceIdExists(
                    'An Existing API already exists with the given UUID')

            for existing_api in self._uuid_to_api_external.values():
                if existing_api.name_key == api.name_key:
                    raise ServiceNameExists('An Existing API with UUID ' +
                                            existing_api.uuid_key +
                                            ' is already using that name')
            self._uuid_to_api_external[this_api_id] = api
        elif IAPIMock.providedBy(api):
            # Internal APIs can be added easily on the fly since
            # they also provide the resource for implementing the API
            this_api_id = ((api.__class__.__name__) + '-' +
                           random_hex_generator(3))
            self._uuid_to_api_internal[this_api_id] = api
        else:
            raise ServiceBadInterface(
                api.__class__.__module__ + '/' + api.__class__.__name__ +
                " does not implement IAPIMock or IExternalAPIMock")