Ejemplo n.º 1
0
    def test_post_like(self, mock_post):
        j = Like(customer=self.customer, id='id', category='category', name='name', createdTime='1994-02-11T14:05M')
        j.post()

        mock_post.assert_called_with(self.base_url_customer +'/' + self.customer.id + '/likes',
                                    headers=self.headers_expected,
                                    json=j.attributes)
        assert self.customer.base.likes[0].attributes == j.attributes, (self.customer.base.likes[0].attributes
                                                                       ,j.attributes)
Ejemplo n.º 2
0
    def test_post_like_create_base(self, mock_post):
        c = Customer(node=self.node, default_attributes={}, id='01')
        j = Like(customer=c, id='id', category='category', name='name', createdTime='1994-02-11T14:05M')
        j.post()

        mock_post.assert_called_with(self.base_url_customer +'/' + c.id + '/likes',
                                    headers=self.headers_expected,
                                     json=j.attributes)
        assert c.base.likes[0].attributes == j.attributes, (c.base.likes[0].attributes, j.attributes)
 def test_update_like(self, mock_put, mock_get):
     now = datetime.now()
     now_s = now.strftime("%Y-%m-%dT%H:%M:%SZ")
     l1 = Like(name='name',
               category='category1',
               createdTime=now,
               id='01',
               customer=Customer(node=self.node, id='123'))
     l = self.node.update_like(customer_id='123', **l1.to_dict())
     assert isinstance(l, Like), type(l)
     assert l.name == 'name', l.name
     mock_put.assert_called_with(self.base_url + '/123/likes/01',
                                 headers=self.headers_expected,
                                 json=dict(name='name',
                                           category='category1',
                                           createdTime=now_s))
Ejemplo n.º 4
0
    def test_set_like_customer_add(self):
        self.customers[0].base.likes[0].name = 'name1'
        self.customers[0].base.likes += [Like(customer=self.customers[0], id='01')]

        mute_res = {'base': {'likes': [
            {'name': 'name1',
             'category': 'category',
             'id': 'id',
             'createdTime': '1994-02-11 14:05'},
            {u'id': u'01'}
        ]
        }
        }
        mute = {'base.likes': [
            {'name': 'name1',
             'category': 'category',
             'id': 'id',
             'createdTime': '1994-02-11 14:05'},
            {u'id': u'01'}
        ]
        }

        assert self.customers[0].mute == mute, self.customers[0].mute
        res = resolve_mutation_tracker(self.customers[0].mute)
        assert res == mute_res, res
Ejemplo n.º 5
0
 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.like = Like(customer=cls.customer, **{'id': 'id'})
Ejemplo n.º 6
0
 def test_put_no_like(self, mock_post):
     self.customer.base.likes = [self.like]
     like = Like(customer=self.customer, id='03')
     like.name = 'name'
     like.category = 'category'
     like.cratedTime = '1994-02-11T14:05M'
     try:
         like.put()
     except ValueError as e:
         assert 'Like' in str(e)
Ejemplo n.º 7
0
    def add_like(self, customer_id, **attributes):
        """
        Insert a new Like for the given Customer

        :param customer_id: the id of the customer for adding the Like
        :param attributes: the attributes representing the new Like to add
        :return: a Like object representing the added Like
        """
        entity_attrs = self.customer_api_manager.post(body=attributes,
                                                      urls_extra=customer_id +
                                                      '/likes')
        return Like(customer=self.get_customer(id=customer_id), **entity_attrs)
Ejemplo n.º 8
0
    def get_customer_like(self, customer_id, like_id):
        """
        Get a like associated to a customer by its ID

        :param like_id: the unique id of the like to get in a customer
        :param customer_id: the id of the customer for getting the like
        :return: a new Like object containing the attributes associated to the like
        """
        return Like(customer=self.get_customer(id=customer_id),
                    **self.customer_api_manager.get(_id=customer_id,
                                                    urls_extra='likes/' +
                                                    like_id))
Ejemplo n.º 9
0
    def update_like(self, customer_id, id, **attributes):
        """
        Update the given Like of the given customer with new specified attributes

        :param customer_id: the id of the customer associated to the Like to update
        :param id: the id of the Like to update
        :param attributes: the attributes for update the Like
        :return: a Like object representing the updated Like
        """
        entity_attrs = self.customer_api_manager.put(_id=customer_id,
                                                     body=attributes,
                                                     urls_extra='likes/' + id)
        return Like(customer=self.get_customer(id=customer_id), **entity_attrs)
Ejemplo n.º 10
0
 def test_from_dict_no_attr(self):
     e = Like.from_dict(customer=self.customer)
     assert e.attributes == {}, e.attributes
Ejemplo n.º 11
0
 def test_delete(self, mock_post):
     j = Like(customer=self.customer, id='id')
     j.delete()
     mock_post.assert_called_with(self.base_url_customer +'/' +self.customer.id + '/likes/id',
                                 headers=self.headers_expected)