Пример #1
0
    def test_post_job(self, mock_post):
        j = Job(customer=self.customer, id='01', companyIndustry='companyIndustry', startDate=u'1994-10-06',
                endDate=u'1994-10-06', companyName='companyName', jobTitle='jobTitle',
                isCurrent=True)
        j.post()

        mock_post.assert_called_with(self.base_url_customer + '/' + self.customer.id + '/jobs',
                                    headers=self.headers_expected,
                                    json=j.attributes)
        assert self.customer.base.jobs[0].attributes == j.attributes, (self.customer.base.jobs[0].attributes
                                                                       ,j.attributes)
Пример #2
0
    def test_post_job_create_base(self, mock_post):
        c = Customer(node=self.node, default_attributes={}, id='01')
        j = Job(customer=c, id='01', companyIndustry='companyIndustry', startDate=u'1994-10-06',
                endDate=u'1994-10-06', companyName='companyName', jobTitle='jobTitle',
                isCurrent=True)
        j.post()

        mock_post.assert_called_with(self.base_url_customer + '/' + c.id + '/jobs',
                                    headers=self.headers_expected,
                                    json=j.attributes)
        assert c.base.jobs[0].attributes == j.attributes, (c.base.jobs[0].attributes, j.attributes)
Пример #3
0
 def test_put_no_job(self, mock_post):
     self.customer.base.jobs = [self.job]
     job = Job(customer=self.customer, id='03')
     job.companyIndustry = 'companyIndustry'
     job.companyName = 'companyName'
     job.jobTitle = 'jobTitle'
     job.startDate = '1994-10-06'
     job.endDate = '1994-10-06'
     job.isCurrent = True
     try:
         job.put()
     except ValueError as e:
         assert 'Job' in str(e)
Пример #4
0
    def test_set_job_customer_add(self):
        self.customers[0].base.jobs[0].isCurrent = False
        self.customers[0].base.jobs += [Job(customer=self.customers[0], id='01')]

        mute = {'base.jobs': [
            {u'companyIndustry': u'companyIndustry',
             u'companyName': u'companyName',
             u'startDate': u'1994-10-06',
             u'endDate': u'1994-10-06',
             u'jobTitle': u'jobTitle',
             u'isCurrent': False},
            {u'id': u'01'}
        ]
        }
        mute_res = {'base': {'jobs': [
            {u'companyIndustry': u'companyIndustry',
             u'companyName': u'companyName',
             u'startDate': u'1994-10-06',
             u'endDate': u'1994-10-06',
             u'jobTitle': u'jobTitle',
             u'isCurrent': False},
            {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
Пример #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.job = Job(customer=cls.customer, **{'id': '01'})
 def test_update_job(self, mock_post, mock_get):
     j1 = Job(jobTitle='jobTitle1',
              companyName='companyName',
              companyIndustry='companyIndustry1',
              isCurrent=True,
              id='01',
              startDate='1994-10-06',
              endDate='1994-10-06',
              customer=Customer(node=self.node, id='123'))
     j = self.node.update_job(customer_id='123', **j1.to_dict())
     assert isinstance(j, Job), type(j)
     assert j.isCurrent, j.isCurrent
     mock_post.assert_called_with(self.base_url + '/123/jobs/01',
                                  headers=self.headers_expected,
                                  json=dict(
                                      jobTitle='jobTitle1',
                                      companyName='companyName',
                                      companyIndustry='companyIndustry1',
                                      isCurrent=True,
                                      startDate='1994-10-06',
                                      endDate='1994-10-06'))
Пример #7
0
    def add_job(self, customer_id, **attributes):
        """
        Insert a new Job for the given Customer

        :param customer_id: the id of the customer for adding the job
        :param attributes: the attributes representing the new job to add
        :return: a Job object representing the added Job
        """
        entity_attrs = self.customer_api_manager.post(body=attributes,
                                                      urls_extra=customer_id +
                                                      '/jobs')
        return Job(customer=self.get_customer(id=customer_id), **entity_attrs)
Пример #8
0
    def get_customer_job(self, customer_id, job_id):
        """
        Get a job associated to a customer by its ID

        :param job_id: the unique id of the job to get in a customer
        :param customer_id: the id of the customer for getting the job
        :return: a new Job object containing the attributes associated to the job
        """
        return Job(customer=self.get_customer(id=customer_id),
                   **self.customer_api_manager.get(_id=customer_id,
                                                   urls_extra='jobs/' +
                                                   job_id))
Пример #9
0
    def update_job(self, customer_id, id, **attributes):
        """
        Update the given job of the given customer with new specified attributes

        :param customer_id: the id of the customer associated to the job to update
        :param id: the id of the job to update
        :param attributes: the attributes for update the job
        :return: a Job object representing the updated Job
        """
        entity_attrs = self.customer_api_manager.put(_id=customer_id,
                                                     body=attributes,
                                                     urls_extra='jobs/' + id)
        return Job(customer=self.get_customer(id=customer_id), **entity_attrs)
Пример #10
0
 def test_from_dict_no_attr(self):
     e = Job.from_dict(customer=self.customer)
     assert e.attributes == {}, e.attributes
Пример #11
0
 def test_create_job_new_c(self):
     j = Job(customer=Customer(node=self.node), a='b')
     try:
         j.post()
     except AttributeError as e:
         assert "Customer object has no attribute 'id'" in str(e), str(e)
Пример #12
0
 def test_delete(self, mock_post):
     j = Job(customer=self.customer, id='01')
     j.delete()
     mock_post.assert_called_with(self.base_url_customer + '/' + self.customer.id + '/jobs/01',
                                 headers=self.headers_expected)