コード例 #1
0
def track_pack(provider, track):
    if provider == 'ect':
        try:
            encomenda = Correios.track(track)

            resposta = dict()
            result = []

            for status in encomenda.status:
                historico = dict()
                historico['data'] = status.data
                historico['local'] = status.local
                historico['situacao'] = status.situacao
                historico['detalhes'] = status.detalhes

                result.append(historico)

            resposta['servico'] = provider
            resposta['codigo'] = track
            resposta['historico'] = result

            return format_result(resposta)

        except AttributeError:
            message = "404 Pacote %s nao encontrado" % track
            logger.exception(message)
    else:
        message = '404 Servico %s nao encontrado' % provider
        logger.warning(message)
    return make_error(message)
コード例 #2
0
    def test_should_use_repository_to_get_encomenda(self):
        encomenda_repository_mock = Mock()
        when(encomenda_repository_mock).get('123').thenReturn('encomenda123')

        Correios._backends[None] = encomenda_repository_mock

        assert Correios.track('123') == 'encomenda123'
コード例 #3
0
    def test_should_use_repository_to_get_encomenda(self):
        encomenda_repository_mock = Mock()
        when(encomenda_repository_mock).get('123', auth=None) \
            .thenReturn('encomenda123')

        Correios._backends[None] = encomenda_repository_mock

        assert Correios.track('123') == 'encomenda123'
コード例 #4
0
    def test_service_should_receive_auth(self):
        auth = ('mi', 'mimi')
        encomenda_repository_mock = Mock()
        when(encomenda_repository_mock).get('123', auth=auth) \
            .thenReturn('encomenda123')

        Correios._backends['service'] = encomenda_repository_mock

        assert Correios.track(
            '123', backend='service', auth=auth) == 'encomenda123'