Esempio n. 1
0
    def test_post_education(self, mock_post):
        e = Education(customer=self.customer, id='01', schoolType='COLLEGE', startYear=1994, endYear=2000,
                      schoolName='schoolName', schoolConcentration='schoolConcentration', isCurrent=True)
        e.post()

        mock_post.asser_called_with(self.base_url_customer + '/' + self.customer.id +'/educations',
                                    headers=self.headers_expected,
                                    json=e.attributes)
        assert self.customer.base.educations[0].attributes == e.attributes, self.customer.attributes
Esempio n. 2
0
    def test_post_education_create_base(self, mock_post):
        c = Customer(node=self.node, default_attributes={}, id='01')
        e = Education(customer=c, id='01', schoolType='COLLEGE', startYear=1994, endYear=2000,
                      schoolName='schoolName', schoolConcentration='schoolConcentration', isCurrent=True)

        e.post()

        mock_post.assert_called_with(self.base_url_customer + '/' + c.id + '/educations',
                                    headers=self.headers_expected,
                                    json=e.attributes)
        assert c.base.educations[0].attributes == e.attributes, c.customer.attributes
Esempio n. 3
0
 def test_put_no_education(self, mock_post):
     self.customer.base.educations = [self.education]
     education = Education(customer=self.customer, id='03')
     education.schoolType = 'COLLEGE'
     education.startYear = 1994
     education.endYear = 2000
     education.schoolConcentration = 'schoolConcentration'
     education.schoolName = 'schoolName'
     education.isCurrent = True
     try:
         education.put()
     except ValueError as e:
         assert 'Education' in str(e)
Esempio n. 4
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.education = Education(customer=cls.customer, **{'id': '01'})
 def test_update_education(self, mock_post, mock_get):
     e1 = Education(schoolType='schoolType1',
                    schoolName='schoolName1',
                    schoolConcentration='schoolConcentration1',
                    isCurrent=True,
                    id='01',
                    startYear='1994',
                    endYear='2000',
                    customer=Customer(node=self.node, id='123'))
     e = self.node.update_education(customer_id='123', **e1.to_dict())
     assert isinstance(e, Education), type(e)
     assert e.isCurrent, e.isCurrent
     mock_post.assert_called_with(
         self.base_url + '/123/educations/01',
         headers=self.headers_expected,
         json=dict(schoolType='schoolType1',
                   schoolName='schoolName1',
                   schoolConcentration='schoolConcentration1',
                   isCurrent=True,
                   startYear='1994',
                   endYear='2000'))
Esempio n. 6
0
    def get_customer_education(self, customer_id, education_id):
        """
        Get an education associated to a customer by its ID

        :param education_id: the unique id of the education to get in a customer
        :param customer_id: the id of the customer for getting the education
        :return: a new Education object containing the attributes associated to the education
        """
        return Education(customer=self.get_customer(id=customer_id),
                         **self.customer_api_manager.get(
                             _id=customer_id,
                             urls_extra='educations/' + education_id))
Esempio n. 7
0
    def add_education(self, customer_id, **attributes):
        """
        Insert a new Education for the given Customer

        :param customer_id: the id of the customer for adding the Education
        :param attributes: the attributes representing the new Education to add
        :return: a Education object representing the added Education
        """
        entity_attrs = self.customer_api_manager.post(body=attributes,
                                                      urls_extra=customer_id +
                                                      '/educations')
        return Education(customer=self.get_customer(id=customer_id),
                         **entity_attrs)
Esempio n. 8
0
    def update_education(self, customer_id, id, **attributes):
        """
        Update the given Education of the given customer with new specified attributes

        :param customer_id: the id of the customer associated to the Education to update
        :param id: the id of the Education to update
        :param attributes: the attributes for update the Education
        :return: a Education object representing the updated Education
        """
        entity_attrs = self.customer_api_manager.put(_id=customer_id,
                                                     body=attributes,
                                                     urls_extra='educations/' +
                                                     id)
        return Education(customer=self.get_customer(id=customer_id),
                         **entity_attrs)
Esempio n. 9
0
    def test_set_education_customer_add(self):
        self.customers[0].base.educations[0].isCurrent = False
        self.customers[0].base.educations += [Education(customer=self.customers[0], id='01')]

        mute = {'base.educations': [
            {u'schoolType': 'COLLEGE',
             u'startYear': 1994,
             u'schoolName': u'schoolName',
             u'schoolConcentration': u'schoolConcentration',
             u'endYear': 2000,
             u'isCurrent': False},
            {u'id': u'01'}
        ]
        }

        assert self.customers[0].mute == mute, self.customers[0].mute
Esempio n. 10
0
 def test_delete(self, mock_post):
     e = Education(customer=self.customer, id='01')
     e.delete()
     mock_post.assert_called_with(self.base_url_customer + '/' + self.customer.id + '/educations/01',
                                 headers=self.headers_expected)
Esempio n. 11
0
 def test_from_dict_no_attr(self):
     e = Education.from_dict(customer=self.customer)
     assert e.attributes == {}, e.attributes