Skip to content

Commit

Permalink
Minor error message changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
lukesneeringer committed Jul 8, 2014
1 parent a68fe76 commit 4a3a6cc
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 20 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*.egg-info
*.pyc
build/
dist/
__pycache__

# PyCharm
Expand Down
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ in your unit tests without hitting the outside world.

Install fauxquests using pip: `pip install fauxquests`.

fauxquests runs on Python 2.7 and Python 3.3. (It probably also works fine
on Python 2.6, but it's not explicitly tested against it.)
fauxquests is explicitly tested against Python 2.7, Python 3.3, and Python 3.4.
It probably also works fine on Python 2.6, but it's not explicitly tested
against it.

If you're using fauxquests with Python 2.7, you'll also need to install
`mock` using pip; if you're on Python 3.3, fauxquests will use the version
`mock` using pip; if you're on Python 3, fauxquests will use the version
in the standard library.

#### Using fauxquests
Expand Down Expand Up @@ -47,7 +48,7 @@ faux_server = fauxquests.FauxServer()

r = requests.get('http://www.google.com/') # Downloads from google.com
with faux_server as fs:
r = requests.get('http://www.google.com/') # Exception: UnregisteredURL
r = requests.get('http://www.google.com/') # Exception: UnregisteredRequest
```

The registration of a URL and response only lasts for the duration of
Expand All @@ -69,7 +70,7 @@ with faux_server as fs:

with faux_server as fs:
requests.get('http://bar/').content # My MORE awesome response.
requests.get('http://foo/').content # Exception: UnregisteredURL
requests.get('http://foo/').content # Exception: UnregisteredRequest
```

#### Mocking JSON Responses
Expand Down Expand Up @@ -111,7 +112,7 @@ with faux_server as fs:
r = requests.post('http://foo/')
r.json() # { 'spam': True }

r = requests.get('http://foo/') # UnregisteredURL
r = requests.get('http://foo/') # UnregisteredRequest
```

#### Query Strings in URLs
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.1
1.1.0.1
6 changes: 5 additions & 1 deletion fauxquests/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
class UnregisteredURL(AssertionError):
class UnregisteredRequest(AssertionError):
pass


# Deprecated.
UnregisteredURL = UnregisteredRequest
6 changes: 3 additions & 3 deletions fauxquests/messages.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
NOT_FOUND = """{request_url}
NOT_FOUND = """{request}
Registered URLs are:
- {registered_urls}
Registered requests are:
- {registered_requests}
"""
18 changes: 9 additions & 9 deletions fauxquests/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from fauxquests.exceptions import UnregisteredURL
from fauxquests.exceptions import UnregisteredRequest
from fauxquests.messages import NOT_FOUND
from requests.compat import quote
from sdict import AlphaSortedDict
Expand Down Expand Up @@ -35,23 +35,23 @@ def __getitem__(self, key):
# Nope, no match. :(
# Now, we need to raise an exception.
# First, Get a list of the registered URLs in a nice format.
registered_urls = '\n - '.join(
registered_requests = '\n - '.join(
[six.text_type(i) for i in six.iterkeys(self)],
)
if not registered_urls:
registered_urls = '(None)'
if not registered_requests:
registered_requests = '(None)'

# Raise an exception.
# UnregisteredURL inherits from AssertionError rather than KeyError,
# which should give more attractive failures in tests.
raise UnregisteredURL(NOT_FOUND.format(
registered_urls=registered_urls,
request_url=key,
raise UnregisteredRequest(NOT_FOUND.format(
registered_requests=registered_requests,
request=key,
))


class URL(object):
"""A class for holding a URL, with convenience methods
"""A class for holding a URL and method, with convenience methods
for poking at its query string separately from the main URI.
"""
def __init__(self, url, method='GET', **kwargs):
Expand Down Expand Up @@ -91,7 +91,7 @@ def __hash__(self):
return hash(str(self))

def __str__(self):
"""Return the full URL, as a string."""
"""Return the full method and URL, as a string."""

# Start with the basic URI.
answer = '%s %s' % (self.method, self.uri)
Expand Down

0 comments on commit 4a3a6cc

Please sign in to comment.