# Path: devicehive/api_response.py
# class ApiResponseError(TransportError):
#     """Api response error."""
# 
#     def __init__(self, message, transport_name, code, error):
#         message = '%s Transport: %s. Code: %s. Error: %s' % (message,
#                                                              transport_name,
#                                                              code, error)
#         super(ApiResponseError, self).__init__(message)
#         self._transport_name = transport_name
#         self._code = code
#         self._error = error
# 
#     @property
#     def transport_name(self):
#         return self._transport_name
# 
#     @property
#     def code(self):
#         return self._code
# 
#     @property
#     def error(self):
#         return self._error
# 
# Path: devicehive/network.py
# class NetworkError(ApiRequestError):
#     """Network error."""
# 
# Path: devicehive/subscription.py
# class SubscriptionError(ApiRequestError):
#     """Subscription error."""


from devicehive import NetworkError, ApiResponseError, SubscriptionError

    test.run(handle_connect, handle_notification=handle_notification)

    def handle_connect(handler):
        network_name = test.generate_id('n-s-n', test.NETWORK_ENTITY)
        description = '%s-description' % network_name
        network = handler.api.create_network(network_name, description)
        network_1 = handler.api.get_network(network.id)
        network.remove()
        try:
            network_1.subscribe_notifications()
            assert False
        except ApiResponseError as api_response_error:
            assert api_response_error.code == 404

    test.run(handle_connect)


def test_unsubscribe_notifications(test):
    test.only_admin_implementation()

    def handle_connect(handler):
        name = test.generate_id('n-u-n', test.NETWORK_ENTITY)
        description = '%s-description' % name
        network = handler.api.create_network(name, description)
        subscription = network.subscribe_notifications()
        subscription.remove()
        try:
            subscription.remove()
            assert False

# Path: devicehive/api_response.py
# class ApiResponseError(TransportError):
#     """Api response error."""
# 
#     def __init__(self, message, transport_name, code, error):
#         message = '%s Transport: %s. Code: %s. Error: %s' % (message,
#                                                              transport_name,
#                                                              code, error)
#         super(ApiResponseError, self).__init__(message)
#         self._transport_name = transport_name
#         self._code = code
#         self._error = error
# 
#     @property
#     def transport_name(self):
#         return self._transport_name
# 
#     @property
#     def code(self):
#         return self._code
# 
#     @property
#     def error(self):
#         return self._error
# 
# Path: devicehive/network.py
# class NetworkError(ApiRequestError):
#     """Network error."""
# 
# Path: devicehive/subscription.py
# class SubscriptionError(ApiRequestError):
#     """Subscription error."""


# Path: tests/test_api_network.py
from devicehive import NetworkError, ApiResponseError, SubscriptionError


    test.run(handle_connect, handle_notification=handle_notification)

    def handle_connect(handler):
        network_name = test.generate_id('n-s-n', test.NETWORK_ENTITY)
        description = '%s-description' % network_name
        network = handler.api.create_network(network_name, description)
        network_1 = handler.api.get_network(network.id)
        network.remove()
        try:
            network_1.subscribe_notifications()
            assert False
        except ApiResponseError as api_response_error:
            assert api_response_error.code == 404

    test.run(handle_connect)


def test_unsubscribe_notifications(test):
    test.only_admin_implementation()

    def handle_connect(handler):
        name = test.generate_id('n-u-n', test.NETWORK_ENTITY)
        description = '%s-description' % name
        network = handler.api.create_network(name, description)
        subscription = network.subscribe_notifications()
        subscription.remove()
        try:
            subscription.remove()
            assert False

        except SubscriptionError: