Exemplo n.º 1
0
    def test_run(self, _mock):
        _mock.return_value = [{
            "detalhes": None,
            "local": "AGF SAO PATRICIO - Sao Paulo/SP",
            "data": "19/07/2016 11:37",
            "situacao": "Postado"
        }]
        data = {
            'callback': 'http://example.com',
            'something': 'XXX',
        }
        self._post('test', data)
        changed = PackTracker.run('ect', 'test')
        self.assertTrue(changed)

        self._post('test', data)
        changed = PackTracker.run('ect', 'test')
        self.assertFalse(changed)

        _mock.return_value.append({
            "detalhes": "Encaminhado para UNIDADE DE CORREIOS/BR",
            "local": "AGF SAO PATRICIO - Sao Paulo/SP",
            "data": "20/07/2016 08:46",
            "situacao": "Encaminhado"
        })
        self._post('test', data)
        changed = PackTracker.run('ect', 'test')
        self.assertTrue(changed)

        self._post('test', data)
        changed = PackTracker.run('ect', 'test')
        self.assertFalse(changed)
Exemplo n.º 2
0
    def test_run(self, _mock):
        _mock.return_value = [{
            "detalhes": None,
            "local": "AGF SAO PATRICIO - Sao Paulo/SP",
            "data": "19/07/2016 11:37",
            "situacao": "Postado"
        }]
        data = {
            'callback': 'http://example.com',
            'something': 'XXX',
        }
        self._post('test', data)
        changed = PackTracker.run('ect', 'test')
        self.assertTrue(changed)

        self._post('test', data)
        changed = PackTracker.run('ect', 'test')
        self.assertFalse(changed)

        _mock.return_value.append({
            "detalhes": "Encaminhado para UNIDADE DE CORREIOS/BR",
            "local": "AGF SAO PATRICIO - Sao Paulo/SP",
            "data": "20/07/2016 08:46",
            "situacao": "Encaminhado"
        })
        self._post('test', data)
        changed = PackTracker.run('ect', 'test')
        self.assertTrue(changed)

        self._post('test', data)
        changed = PackTracker.run('ect', 'test')
        self.assertFalse(changed)
Exemplo n.º 3
0
def track_packs():
    logger.info('Iniciando tracking de pacotes...')
    db = Database()
    for obj in db.packtrack.get_all():
        provider = obj['servico']
        track = obj['codigo']
        changed = PackTracker.run(provider, track)
        if changed:
            PackTracker.report(provider, track)

    logger.info('Finalizou o tracking de pacotes')
Exemplo n.º 4
0
def track_packs():
    logger.info('Iniciando tracking de pacotes...')
    db = Database()
    for obj in db.packtrack.get_all():
        provider = obj['servico']
        track = obj['codigo']
        changed = PackTracker.run(provider, track)
        if changed:
            PackTracker.report(provider, track)

    logger.info('Finalizou o tracking de pacotes')
Exemplo n.º 5
0
def track_packs():
    logger.info('Iniciando tracking de pacotes...')
    db = Database()
    runTask = PackTracker.correios_check()
    print('runTask: ' + str(runTask))
    if runTask:
        for obj in db.packtrack.get_all():
            provider = obj['servico']
            track = obj['codigo']
            changed = PackTracker.run(provider, track)
            if changed:
                PackTracker.report(provider, track)

    logger.info('Finalizou o tracking de pacotes')
Exemplo n.º 6
0
    def test_report(self, _mock_requests):

        input_data = {
            'callback': 'http://example.com',
            'something': 'XXX',
        }
        response = self._post('test', input_data)
        token = response['token']

        encomenda = correios.Encomenda('track')
        status = correios.Status(
            local="AGF SAO PATRICIO - Sao Paulo/SP",
            data="19/07/2016 11:37",
            situacao="Postado",
        )
        encomenda.adicionar_status(status)
        with mock.patch('PackTracker.packtrack') as _mock_correios:
            _mock_correios.Correios.track.return_value = encomenda
            changed = PackTracker.run('ect', 'test')
        self.assertTrue(changed)

        PackTracker.report('ect', 'test')

        call = _mock_requests.call_args
        self.assertEqual(('http://example.com', ), call[0])

        data = json.loads(call[1]['data'])

        self.assertEqual(input_data, data['input'])
        self.assertEqual(token, data['token'])
        self.assertEqual([{
            u'detalhes': status.detalhes,
            u'local': status.local,
            u'situacao': status.situacao,
            u'data': status.data,
        }], data['historico'])
Exemplo n.º 7
0
    def test_report(self, _mock_requests):

        input_data = {
            'callback': 'http://example.com',
            'something': 'XXX',
        }
        response = self._post('test', input_data)
        token = response['token']

        encomenda = correios.Encomenda('track')
        status = correios.Status(
            local="AGF SAO PATRICIO - Sao Paulo/SP",
            data="19/07/2016 11:37",
            situacao="Postado",
        )
        encomenda.adicionar_status(status)
        with mock.patch('PackTracker.packtrack') as _mock_correios:
            _mock_correios.Correios.track.return_value = encomenda
            changed = PackTracker.run('ect', 'test')
        self.assertTrue(changed)

        PackTracker.report('ect', 'test')

        call = _mock_requests.call_args
        self.assertEqual(('http://example.com',), call[0])

        data = json.loads(call[1]['data'])

        self.assertEqual(input_data, data['input'])
        self.assertEqual(token, data['token'])
        self.assertEqual([{
            u'detalhes': status.detalhes,
            u'local': status.local,
            u'situacao': status.situacao,
            u'data': status.data,
        }], data['historico'])