def test_update_subscription(self, mock_post, mock_get): s1 = Subscription(name='name', kind='SERVICE', id='01', customer=Customer(node=self.node, id='123')) s = self.node.update_subscription(customer_id='123', **s1.to_dict()) assert isinstance(s, Subscription), type(s) assert s.id == '01', s.id mock_post.assert_called_with(self.base_url + '/123/subscriptions/01', headers=self.headers_expected, json=dict(name='name', kind='SERVICE'))
def test_post_job(self, mock_post): s = Subscription(customer=self.customer, id='01', name='name', type='type', kind='SERVICE', subscribed=True, startDate='1994-10-06', endDate='1994-10-10', subscriberId='subscriberId', preferences=[{'key': 'key', 'value': 'value'}]) s.post() mock_post.assert_called_with(self.base_url_customer + '/' + self.customer.id + '/subscriptions', headers=self.headers_expected, json=s.attributes) assert self.customer.base.subscriptions[0].attributes == s.attributes, \ (self.customer.base.subscriptions[0].attributes, s.attributes)
def test_post_job_create_base(self, mock_post): c = Customer(node=self.node, default_attributes={}, id='01') s = Subscription(customer=c, id='01', name='name', type='type', kind='SERVICE', subscribed=True, startDate='1994-10-06', endDate='1994-10-10', subscriberId='subscriberId', preferences=[{'key': 'key', 'value': 'value'}]) s.post() mock_post.assert_called_with(self.base_url_customer + '/' + c.id + '/subscriptions', headers=self.headers_expected, json=s.attributes) assert c.base.subscriptions[0].attributes == s.attributes, (c.base.subscriptions[0].attributes, s.attributes)
def setUp(cls, mock_get_customers): w = Workspace(workspace_id="123", token="456") cls.node = w.get_node("123") cls.customers = cls.node.get_customers() cls.headers_expected = {'Authorization': 'Bearer 456', 'Content-Type': 'application/json'} cls.base_url_customer = 'https://api.contactlab.it/hub/v1/workspaces/123/customers' cls.customer = Customer(id='01', node=cls.node) cls.subscription = Subscription(customer=cls.customer, **{'id': '01'})
def test_set_subscription_customer_add(self): self.customers[0].base.subscriptions[0].name = 'name1' self.customers[0].base.subscriptions += [Subscription(customer=self.customers[0], id='02')] mute = {'base.subscriptions': [{'id': '01', 'name': 'name1', 'type': 'type', 'kind': 'SERVICE', 'subscribed': True, 'startDate': '1994-10-06', 'endDate': '1994-10-10', 'subscriberId': 'subscriberId', 'registeredAt': '1994-10-06', 'updatedAt': '1994-10-06', 'preferences': [{'key': 'key', 'value': 'value'}], 'a': ['a']}, {'id': '02'}]} assert self.customers[0].mute == mute, self.customers[0].mute
def update_subscription(self, customer_id, id, **attributes): """ Update the given Subscription of the given customer with new specified attributes :param customer_id: the id of the customer associated to the Subscription to update :param id: the id of the Subscription to update :param attributes: the attributes for update the Subscription :return: a Subscription object representing the updated Subscription """ entity_attrs = self.customer_api_manager.put( _id=customer_id, body=attributes, urls_extra='subscriptions/' + id) return Subscription(customer=self.get_customer(id=customer_id), **entity_attrs)
def add_subscription(self, customer_id, **attributes): """ Insert a new Subscription for the given Customer :param customer_id: the id of the customer for adding the Subscription :param attributes: the attributes representing the new Subscription to add :return: a Subscription object representing the added Subscription """ entity_attrs = self.customer_api_manager.post(body=attributes, urls_extra=customer_id + '/subscriptions') return Subscription(customer=self.get_customer(id=customer_id), **entity_attrs)
def get_customer_subscription(self, customer_id, subscription_id): """ Get an subscription associated to a customer by its ID :param subscription_id: the unique id of the subscription to get in a customer :param customer_id: the id of the customer for getting the subscription :return: a new Subscription object containing the attributes associated to the subscription """ return Subscription(customer=self.get_customer(id=customer_id), properties_class=Properties, **self.customer_api_manager.get( _id=customer_id, urls_extra='subscriptions/' + subscription_id))
def test_get_list(self): s = Subscription(customer=self.customer, **{'id': '01'}) s.preferences = ['a'] assert s.preferences == ['a'], s.preferences
def test_from_dict_no_attr(self): e = Subscription.from_dict(customer=self.customer) assert e.attributes == {}, e.attributes
def test_put_no(self, mock_post): self.customer.base.subscriptions = [self.subscription] subscription = Subscription(customer=self.customer, id='03') subscription.name = 'name' subscription.type = 'type' subscription.kind = 'kind' subscription.subscriberId = 'subscriberId' subscription.startDate = '1994-10-06' subscription.endDate = '1994-10-10' subscription.subscribed = True subscription.preferences = [{'key': 'key', 'value': 'value'}] try: subscription.put() except ValueError as e: assert 'Subscription' in str(e)
def test_delete(self, mock_post): s = Subscription(customer=self.customer, id='01') s.delete() mock_post.assert_called_with(self.base_url_customer + '/' + self.customer.id + '/subscriptions/01', headers=self.headers_expected)