Esempio n. 1
0
 def test_parse(self):
     """
     Tests parsing for datetime from JSON string.
     """
     parsed_items = parse(LEAD)
     self.assertEqual(parsed_items["date_updated"],
                      datetime.datetime(2013, 2, 6, 20, 53, 1, 977000, tzinfo=tzutc()))
     self.assertEqual(parsed_items["custom"]["time_of_death"], datetime.time(1))
     self.assertEqual(parsed_items["custom"]["date_of_death"], datetime.date(1988, 11, 19))
     self.assertEqual(parsed_items["custom"]["foo"], "bar")
     p_gen = parse(x for x in range(10))
     is_gen = (x for x in range(10))
     self.assertIsNot(parse(is_gen), is_gen)
     self.assertEqual(list(p_gen), [x for x in range(10)])
     self.assertIsInstance(p_gen, types.GeneratorType)
Esempio n. 2
0
    def test_create_lead(self, client):
        with open(os.path.join(FIXTURE_DIR, 'lead.json')) as f:
            lead = utils.parse(json.load(f))
            response = client.create_lead(lead)
            assert all(False for k in lead if k not in response), dict(response)

            client.delete_lead(response['id'])  # Clean up
Esempio n. 3
0
 def test_create_activity_email(self, client, lead):
     with open(os.path.join(FIXTURE_DIR, 'email.json')) as f:
         call = utils.parse(json.load(f))
         call.update({
             'lead_id': lead['id'],
         })
         response = client.create_activity_email(**call)
         assert all(False for k in call if k not in response), dict(response)
Esempio n. 4
0
 def opportunity(self, client, lead):
     with open(os.path.join(FIXTURE_DIR, 'opportunity.json')) as f:
         opportunity = utils.parse(json.load(f))
         opportunity.update({
             'lead_id': lead['id'],
         })
         response = client.create_opportunity(opportunity)
         yield response
         client.delete_opportunity(response['id'])
Esempio n. 5
0
    def test_create_opportunity(self, client, lead):
        with open(os.path.join(FIXTURE_DIR, 'opportunity.json')) as f:
            opportunity = utils.parse(json.load(f))
            opportunity.update({
                'lead_id': lead['id'],
            })
            response = client.create_opportunity(opportunity)
            assert all(False for k in opportunity if k not in response), dict(response)

            client.delete_opportunity(response['id'])  # Clean up
Esempio n. 6
0
 def test_create_task(self, client, lead, _date):
     with open(os.path.join(FIXTURE_DIR, 'task.json')) as f:
         task = utils.parse(json.load(f))
         task.update({
             'lead_id': lead['id'],
             'assigned_to': client.me()['id'],
             'due_date': _date
         })
         response = client.create_task(**task)
         assert all(False for k in task if k not in response), dict(response)
Esempio n. 7
0
    def test_delete_activity_call(self, client, lead):
        with open(os.path.join(FIXTURE_DIR, 'call.json')) as f:
            call = utils.parse(json.load(f))
            call.update({
                'lead_id': lead['id'],
            })
            response = client.create_activity_call(**call)
            activity_id = response['id']

            response = client.delete_activity_call(activity_id)
            assert response is True

            assert list(client.get_activity_call(lead['id'])) == []
Esempio n. 8
0
    def lead(self, client):

        def wait_for_index(name):
            query = 'name:{}'.format(name)
            i = 0
            while not list(client.get_leads(query)):
                i += 1
                if i == 3:
                    raise RuntimeWarning("Lead wasn't indexed within 15 seconds")
                time.sleep(5)

        with open(os.path.join(FIXTURE_DIR, 'lead.json')) as f:
            lead = utils.parse(json.load(f))
            response = client.create_lead(lead)
            wait_for_index(response['name'])
            yield response
            client.delete_lead(response['id'])
Esempio n. 9
0
    def task(self, client, lead):
        with open(os.path.join(FIXTURE_DIR, 'task.json')) as f:
            def wait_for_index(lead_id):
                query = {'lead_id': lead_id}
                i = 0
                while not list(client.get_tasks(**query)):
                    i += 1
                    if i == 10:
                        raise RuntimeWarning("Lead wasn't indexed within 10 seconds")
                    time.sleep(1)

            task = utils.parse(json.load(f))
            task.update({
                'lead_id': lead['id'],
                'assigned_to': client.me()['id'],
            })
            response = client.create_task(**task)
            wait_for_index(response['lead_id'])
            yield response
Esempio n. 10
0
    def post(self, request, *args, **kwargs):
        try:
            query = json.loads(force_text(request.body))
        except (ValueError, TypeError):
            logger.exception("CloseIO webhook request could not be parsed.")
            return HttpResponseBadRequest()

        try:
            event = query['event']
            model = query['model']
            data = utils.parse(query['data'])
        except KeyError:
            logger.exception("CloseIO webhook request could not be dispatched.")
            return HttpResponseBadRequest()

        data_to_send = dict(
            instance=data
        )

        if event == 'create':
            signals.closeio_create.send(
                sender=self.__class__,
                model=model,
                **data_to_send
            )

        elif event == 'update':
            signals.closeio_update.send(
                sender=self.__class__,
                model=model,
                **data_to_send
            )

        elif event == 'delete':
            data_to_send = dict(
                instance_id=data.get('id', '')
            )
            signals.closeio_delete.send(
                sender=self.__class__,
                model=model,
                **data_to_send
            )

        elif event == 'merge':
            data_to_send = dict(
                source_id=data.get('source_id', ''),
                destination_id=data.get('destination_id', ''),
            )
            signals.closeio_merge.send(
                sender=self.__class__,
                model=model,
                **data_to_send
            )

        expl_signal_name = '%s_%s' % (model, event)

        if hasattr(signals, expl_signal_name):
            signal = getattr(signals, expl_signal_name)
            signal.send(
                sender=self.__class__,
                **data_to_send
            )

        signals.closeio_event.send(
            sender=self.__class__,
            model=model,
            event=event,
            instance=data,
        )

        return HttpResponse()
Esempio n. 11
0
 def test_convert_full(self):
     assert LEAD == convert(parse(LEAD))