def test_unmarshall_valid_view_model_to_consume(self):
     serializer = Serializer()
     
     expected = serializer.deserialize(Subscription(), ExampleSubscription().get_file_content_as_string(partial=True, to_consume=True))
     actual = serializer.deserialize(Subscription(), serializer.serialize(ExampleSubscription().create(partial=True, to_consume=True), partial=True))
     
     self.assertEqual(expected, actual)
Example #2
0
    def test_unmarshall_valid_view_model_to_produce(self):

        serializer = Serializer()

        expected = serializer.deserialize(MessageType(), ExampleMessageType().get_file_content_as_string(to_consume=False))
        actual = serializer.deserialize(MessageType(), Serializer().serialize(ExampleMessageType().create(to_consume=False), partial=False))

        self.assertEqual(expected, actual)
Example #3
0
    def test_unmarshall_valid_view_model_to_consume(self):

        serializer = Serializer()
        
        expected = serializer.deserialize(Channel(), ExampleChannel().get_file_content_as_string(to_consume=True))
        actual = serializer.deserialize(Channel(), serializer.serialize(ExampleChannel().create(to_consume=True), partial=True))
        
        self.assertEqual(expected, actual)
Example #4
0
    def test_unmarshall_valid_view_model_to_consume(self):
        serializer = Serializer()
        
        expected = Endpoint()
        serializer.deserialize(expected, ExampleEndpoint().get_file_content_as_string(to_consume=True))
        actual = ExampleEndpoint().create(to_consume=True)

        self.assertEqual(expected, actual)
Example #5
0
    def test_unmarshall_valid_view_model_to_produce(self):
        serializer = Serializer()

        expected = serializer.deserialize(
            Subscription(),
            ExampleSubscription().get_file_content_as_string(partial=False,
                                                             to_consume=False))
        actual = serializer.deserialize(
            Subscription(),
            serializer.serialize(ExampleSubscription().create(
                partial=False, to_consume=False),
                                 partial=False))

        self.assertEqual(expected, actual)
Example #6
0
    def test_unmarshall_then_marshall_with_two_messages(self):
        
        first = ExampleMessage().create(to_consume=False)
        second = ExampleMessage().create_alternative(to_consume=False)

        serializer = Serializer()

        first_serialized = serializer.serialize(first)
        second_serialized = serializer.serialize(second)
        
        first_deserialized = serializer.deserialize(Message(), first_serialized, force_consume=True)
        second_deserialized = serializer.deserialize(Message(), second_serialized, force_consume=True)

        self.assertEqual(first, first_deserialized)
        self.assertEqual(second, second_deserialized)
Example #7
0
 def create_from_file(self, to_consume=True, invalid=False, alternate=False):
 
     data = self.get_file_content_as_string(to_consume=to_consume, invalid=invalid, alternate=alternate)
     message_type_list = MessageTypeList()
     Serializer().deserialize(message_type_list, data)
 
     return message_type_list
Example #8
0
 def create_from_file(self, partial=False, to_consume=True, invalid=False, alternate=False, no_id=False):
 
     data = self.get_file_content_as_string(partial=partial, to_consume=to_consume, invalid=invalid, alternate=alternate)
     channel = Channel()
     Serializer().deserialize(channel, data)
 
     return channel
Example #9
0
 def create_from_file(self, partial=False, to_consume=True, invalid=False, verbose=False, no_id=False, alternate=False):
 
     data = self.get_file_content_as_string(partial=partial, to_consume=to_consume, invalid=invalid, verbose=verbose, no_id=no_id, alternate=alternate)
     list_view_model = ChannelList()
     Serializer().deserialize(list_view_model, data)
 
     return list_view_model
Example #10
0
    def update_endpoint(self, endpoint):
        """
        Update an existing endpoint

        :param endpoint:
        is the updated endpoint that the client wants to update
        """
        #Validate
        self._validate_uuid(endpoint.endpoint_id)
        self._validate_subscriber_id(endpoint.user)

        #Update the subscription
        dao = NWS_DAO()
        url = "/notification/v1/endpoint/%s" % (endpoint.endpoint_id)
        headers = {"Content-Type": "application/json"}
        if self.override_user is not None:
            headers['X_UW_ACT_AS'] = self.override_user

        put_response = dao.putURL(url, headers, Serializer().serialize(endpoint))

        #Http response code 204 No Content:
        #The server has fulfilled the request but does not need to return an entity-body
        if put_response.status != 204:
            raise DataFailureException(url, put_response.status, put_response.data)

        return put_response.status
Example #11
0
 def create_from_file(self, to_consume=True, invalid=False, active=False):
 
     data = self.get_file_content_as_string(to_consume, invalid, active)
     endpoint = EndpointList()
     Serializer().deserialize(endpoint, data)
 
     return endpoint
Example #12
0
    def _get_subscriptions_from_nws(self, *args, **kwargs):
        """
        Search for all subscriptions by a parameter
        """
        url = "/notification/v1/subscription" #?subscriber_id=%s" % (subscriber_id)

        number_of_args = len(kwargs)
        if number_of_args > 0:
            url += '?'
            for k,v in kwargs.iteritems():
                if k is not None and v is not None:
                    url += k + '=' + v
                    if number_of_args > 1:
                        url += '&'
                    number_of_args -= 1

        dao = NWS_DAO()
        response = dao.getURL(url, {"Accept": "application/json"})

        if response.status != 200:
            raise DataFailureException(url, response.status, response.data)

        subscriptions = SubscriptionList()
        Serializer().deserialize(subscriptions, response.data)

        return subscriptions.view_models
Example #13
0
    def update_subscription(self, subscription):
        """
        Update an existing subscription on a given channel

        :param subscription:
        is the updated subscription that the client wants to update
        """
        #Validate
        if subscription.get_channel() is not None:
            self._validate_uuid(subscription.get_channel().get_channel_id())
        if subscription.get_endpoint() is not None:
            if subscription.get_endpoint().get_endpoint_id() is not None:
                self._validate_uuid(subscription.get_endpoint().get_endpoint_id())
            self._validate_subscriber_id(subscription.get_endpoint().get_user_net_id())

        #Update the subscription
        dao = NWS_DAO()
        url = "/notification/v1/subscription/%s" % (subscription.subscription_id)
        headers = {"Content-Type": "application/json"}
        if self.override_user is not None:
            headers['X_UW_ACT_AS'] = self.override_user

        put_response = dao.putURL(url, headers, Serializer().serialize(subscription))

        #Http response code 204 No Content:
        #The server has fulfilled the request but does not need to return an entity-body
        if put_response.status != 204:
            raise DataFailureException(url, put_response.status, put_response.data)

        return put_response.status
Example #14
0
    def create_from_file(self, to_consume=True, invalid=False, active=False):

        data = self.get_file_content_as_string(to_consume, invalid, active)
        person = PersonList()
        Serializer().deserialize(person, data)

        return person
Example #15
0
    def create_new_person(self, person):
        """
        Create a new person

        :param person:
        is the new person that the client wants to crete
        """
        #Validate input
        self._validate_subscriber_id(person.surrogate_id)

        #Create new person
        dao = NWS_DAO()
        url = "/notification/v1/person"
        headers = {"Content-Type": "application/json"}
        if self.override_user is not None:
            headers['X_UW_ACT_AS'] = self.override_user

        post_response = dao.postURL(url, headers, Serializer().serialize(person))

        #HTTP Status Code 201 Created: The request has been fulfilled and resulted
        #in a new resource being created
        if post_response.status != 201:
            raise DataFailureException(url, post_response.status, post_response.data)

        return post_response.status
Example #16
0
    def get_person_by_uwregid(self, uwregid):
        url = "/notification/v1/person/%s" % (uwregid)

        dao = NWS_DAO()
        response = dao.getURL(url, {"Accept": "application/json"})

        if response.status != 200:
            raise DataFailureException(url, response.status, response.data)

        person = Person()
        Serializer().deserialize(person, response.data)
        return person
Example #17
0
    def execute_job(self, job):
        url = "/notification/v1/job"

        data = Serializer().serialize(job)

        dao = NWS_DAO()
        post_response = dao.postURL(url, {"Content-Type": "application/json"}, data)

        if post_response.status != 201:
            raise DataFailureException(url, post_response.status, post_response.data)

        return post_response.status
Example #18
0
    def test_marshall_view_model_to_consume(self):
        
        serializer = Serializer()
        
        expected = serializer.deserialize(MessageType(), serializer.serialize(ExampleMessageType().create(to_consume=True), partial=True))
        actual = serializer.deserialize(MessageType(), serializer.serialize(ExampleMessageType().create_from_file(to_consume=True), partial=True))

        self.assertEqual(expected, actual)
Example #19
0
    def create_from_file(self,
                         partial=True,
                         to_consume=True,
                         invalid=False,
                         alternate=False):

        data = self.get_file_content_as_string(partial=partial,
                                               to_consume=to_consume,
                                               invalid=invalid,
                                               alternate=alternate)
        subscription = Subscription()
        Serializer().deserialize(subscription, data)

        return subscription
Example #20
0
    def get_person_by_surrogate_id(self, surrogate_id):
        #Validate input
        self._validate_subscriber_id(surrogate_id)

        url = "/notification/v1/person/%s" % (surrogate_id)

        dao = NWS_DAO()
        response = dao.getURL(url, {"Accept": "application/json"})

        if response.status != 200:
            raise DataFailureException(url, response.status, response.data)

        person = Person()
        Serializer().deserialize(person, response.data)
        return person
Example #21
0
    def get_channels(self, first_result = 1, max_results = 10):
        """
        Search for all channels
        """
        url = "/notification/v1/channel?first_result=%s&max_results=%s" % (first_result, max_results)

        dao = NWS_DAO()
        response = dao.getURL(url, {"Accept": "application/json"})

        if response.status != 200:
            raise DataFailureException(url, response.status, response.data)

        channel_list = ChannelList()
        Serializer().deserialize(channel_list, response.data)

        return channel_list.view_models
Example #22
0
    def get_channels_by_sln_year_quarter(self, channel_type, sln, year, quarter):
        """
        Search for all channels by sln, year and quarter
        """
        url = "/notification/v1/channel?type=%s&tag_sln=%s&tag_year=%s&tag_quarter=%s" % (channel_type, sln, year, quarter)

        dao = NWS_DAO()
        response = dao.getURL(url, {"Accept": "application/json"})

        if response.status != 200:
            raise DataFailureException(url, response.status, response.data)

        channel_list = ChannelList()
        Serializer().deserialize(channel_list, response.data)

        return channel_list.view_models
Example #23
0
    def get_channel_by_surrogate_id(self, channel_type, surrogate_id):
        """
        Get a channel by surrogate id
        """
        key = "%s|%s" % (channel_type, surrogate_id)
        url = "/notification/v1/channel/%s" % (quote(key))

        dao = NWS_DAO()
        response = dao.getURL(url, {"Accept": "application/json"})

        if response.status != 200:
            raise DataFailureException(url, response.status, response.data)

        channel = Channel()
        Serializer().deserialize(channel, response.data)

        return channel
Example #24
0
    def create_from_file(self,
                         partial=False,
                         to_consume=True,
                         invalid=False,
                         alternate=False,
                         no_id=False,
                         sent=False):

        data = self.get_file_content_as_string(partial=partial,
                                               to_consume=to_consume,
                                               invalid=invalid,
                                               alternate=alternate,
                                               sent=sent)
        message = Message()
        Serializer().deserialize(message, data)

        return message
Example #25
0
    def get_endpoint_by_endpoint_id(self, endpoint_id):
        """
        Get an endpoint by endpoint id
        """
        #Validate the channel_id
        self._validate_uuid(endpoint_id)

        url = "/notification/v1/endpoint/%s" % (endpoint_id)

        dao = NWS_DAO()
        response = dao.getURL(url, {"Accept": "application/json"})

        if response.status != 200:
            raise DataFailureException(url, response.status, response.data)

        endpoint = Endpoint()
        Serializer().deserialize(endpoint, response.data)

        return endpoint
Example #26
0
    def get_endpoints_by_subscriber_id(self, subscriber_id):
        """
        Search for all endpoints by a given subscriber
        """
        #Validate input
        self._validate_subscriber_id(subscriber_id)

        url = "/notification/v1/endpoint?subscriber_id=%s" % (subscriber_id)

        dao = NWS_DAO()
        response = dao.getURL(url, {"Accept": "application/json"})

        if response.status != 200:
            raise DataFailureException(url, response.status, response.data)

        endpoint_list = EndpointList()
        Serializer().deserialize(endpoint_list, response.data)

        return endpoint_list.view_models
Example #27
0
    def test_unmarshall_then_marshall_with_two_endpoints(self):
        
        first = ExampleEndpoint().create(to_consume=False)
        second = ExampleEndpoint().create_alternative(to_consume=False)

        serializer = Serializer()

        first_serialized = serializer.serialize(first)
        second_serialized = serializer.serialize(second)
        
        first_deserialized = serializer.deserialize(Endpoint(), first_serialized)
        second_deserialized = serializer.deserialize(Endpoint(), second_serialized)

        self.assertEqual(first, first_deserialized)
        self.assertEqual(second, second_deserialized)

        first_reserialized = serializer.serialize(first_deserialized)
        second_reserialized = serializer.serialize(second_deserialized)
        
        self.assertEqual(first_serialized, first_reserialized)
        self.assertEqual(second_serialized, second_reserialized)
Example #28
0
    def create_new_channel(self, channel):
        """
        Create a new channel

        :param channel:
        is the new channel that the client wants to create
        """
        #Create new channel
        dao = NWS_DAO()
        url = "/notification/v1/channel"

        post_response = dao.postURL(url, {"Content-Type": "application/json"}, Serializer().serialize(channel))

        #HTTP Status Code 201 Created: The request has been fulfilled and resulted
        #in a new resource being created
        if post_response.status != 201:
            raise DataFailureException(url, post_response.status, post_response.data)

        return post_response.status
Example #29
0
    def update_channel(self, channel):
        """
        Update an existing channel

        :param channel:
        is the updated channel that the client wants to update
        """
        #Update the channel
        dao = NWS_DAO()
        url = "/notification/v1/channel/%s" % (channel.channel_id)

        put_response = dao.putURL(url, {"Content-Type": "application/json"}, Serializer().serialize(channel))

        #Http response code 204 No Content:
        #The server has fulfilled the request but does not need to return an entity-body
        if put_response.status != 204:
            raise DataFailureException(url, put_response.status, put_response.data)

        return put_response.status
Example #30
0
    def get_channel_by_channel_id(self, channel_id):
        """
        Get a channel by channel id
        """
        #Validate the channel_id
        self._validate_uuid(channel_id)

        url = "/notification/v1/channel/%s" % (channel_id)

        dao = NWS_DAO()
        response = dao.getURL(url, {"Accept": "application/json"})

        if response.status != 200:
            raise DataFailureException(url, response.status, response.data)

        channel = Channel()
        Serializer().deserialize(channel, response.data)

        return channel
Example #31
0
    def create_new_message(self, dispatch):
        """
        Create a new dispatch

        :param dispatch:
        is the new dispatch that the client wants to create
        """

        #Create new dispatch
        dao = NWS_DAO()
        url = "/notification/v1/dispatch"

        data = Serializer().serialize(dispatch)

        post_response = dao.postURL(url, {"Content-Type": "application/json"}, data)

        if post_response.status != 200:
            raise DataFailureException(url, post_response.status, post_response.data)

        return post_response.status
Example #32
0
    def update_person(self, person):
        """
        Update an existing person

        :param person:
        is the updated person that the client wants to update
        """
        #Validate
        self._validate_regid(person.person_id)
        self._validate_subscriber_id(person.surrogate_id)

        attributes = person.get_attributes()
        person.attributes = None

        for attribute in attributes:
            if attribute.name in MANAGED_ATTRIBUTES:
                continue

            person.add_attribute(attribute.name, attribute.value, None, None)
        #    ATTRIBUTE_TYPE_EMAIL_DISPATCHED_COUNT = 'DispatchedEmailCount'
        #    ATTRIBUTE_TYPE_SMS_DISPATCHED_COUNT = 'DispatchedTextMessageCount'
        #        ATTRIBUTE_TYPE_SMS_SENT_COUNT = 'SentTextMessageCount'
        #            ATTRIBUTE_TYPE_SUBSCRIPTION_COUNT = 'SubscriptionCount'

        dao = NWS_DAO()
        url = "/notification/v1/person/%s" % (person.person_id)
        headers = {"Content-Type": "application/json"}
        if self.override_user is not None:
            headers['X_UW_ACT_AS'] = self.override_user

        put_response = dao.putURL(url, headers, Serializer().serialize(person))

        #Http response code 204 No Content:
        #The server has fulfilled the request but does not need to return an entity-body
        if put_response.status != 204:
            raise DataFailureException(url, put_response.status, put_response.data)

        return put_response.status