Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
postmon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Matheus Horstmann
postmon
Commits
7eabba09
Commit
7eabba09
authored
10 years ago
by
Iuri de Silvio
Browse files
Options
Downloads
Patches
Plain Diff
_get_info_from_source não precisa lançar ValueError. A própria rota
de CEP já trata o caso de CEP não existir. Isso não é um erro.
parent
37bded07
Branches
fix-404
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
PostmonServer.py
+2
-8
2 additions, 8 deletions
PostmonServer.py
test/postmon_test.py
+2
-2
2 additions, 2 deletions
test/postmon_test.py
with
4 additions
and
10 deletions
PostmonServer.py
+
2
−
8
View file @
7eabba09
...
...
@@ -7,7 +7,7 @@ import xmltodict
from
bottle
import
route
,
run
,
response
,
template
,
HTTPResponse
from
CepTracker
import
CepTracker
import
requests
from
packtrack
import
Correios
,
Royal
from
packtrack
import
Correios
from
database
import
MongoDb
as
Database
...
...
@@ -33,10 +33,7 @@ def expired(record_date):
def
_get_info_from_source
(
cep
):
tracker
=
CepTracker
()
info
=
tracker
.
track
(
cep
)
if
len
(
info
)
==
0
:
raise
ValueError
(
'
CEP %s nao encontrado
'
%
cep
)
return
info
return
tracker
.
track
(
cep
)
def
format_result
(
result
):
...
...
@@ -100,9 +97,6 @@ def verifica_cep(cep):
result
=
None
try
:
info
=
_get_info_from_source
(
cep
)
except
ValueError
:
message
=
'
404 CEP %s nao encontrado
'
%
cep
logger
.
exception
(
message
)
except
requests
.
exceptions
.
RequestException
:
message
=
'
503 Servico Temporariamente Indisponivel
'
logger
.
exception
(
message
)
...
...
This diff is collapsed.
Click to expand it.
test/postmon_test.py
+
2
−
2
View file @
7eabba09
...
...
@@ -212,7 +212,7 @@ class PostmonErrors(unittest.TestCase):
@mock.patch
(
'
PostmonServer._get_info_from_source
'
)
def
test_404_status
(
self
,
_mock
):
_mock
.
side_effect
=
ValueError
(
'
test
'
)
_mock
.
return_value
=
[]
response
=
self
.
get_cep
(
'
99999999
'
,
expect_errors
=
True
)
self
.
assertEqual
(
"
404 CEP 99999999 nao encontrado
"
,
response
.
status
)
self
.
assertEqual
(
'
application/json
'
,
response
.
headers
[
'
Content-Type
'
])
...
...
@@ -220,7 +220,7 @@ class PostmonErrors(unittest.TestCase):
@mock.patch
(
'
PostmonServer._get_info_from_source
'
)
def
test_404_status_with_xml_format
(
self
,
_mock
):
_mock
.
side_effect
=
ValueError
(
'
test
'
)
_mock
.
return_value
=
[]
response
=
self
.
get_cep
(
'
99999999
'
,
format
=
'
xml
'
,
expect_errors
=
True
)
self
.
assertEqual
(
"
404 CEP 99999999 nao encontrado
"
,
response
.
status
)
self
.
assertEqual
(
'
application/xml
'
,
response
.
headers
[
'
Content-Type
'
])
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment