Skip to content

Commit

Permalink
Add more comprehensive tests for hitting the meta endpoint, using ETa…
Browse files Browse the repository at this point in the history
…g headers
  • Loading branch information
Jeff Knupp committed May 1, 2014
1 parent 8aa4e67 commit 6da13b7
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions tests/test_sandman.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,17 @@ def test_get_attribute(self):
response = self.get_response('/artists/1/Name', 200)
assert json.loads(response.get_data(as_text=True))[u'Name'] == 'AC/DC'

def test_get_meta(self):
"""Test simple HTTP GET"""
response = self.get_response('/', 200)
assert 'meta' in json.loads(response.get_data())['artists']

def test_get_root(self):
"""Test simple HTTP GET"""
response = self.get_response('/artists/meta', 200)
assert 'Name' in json.loads(response.get_data())['Artist']


def test_get_object_attribute(self):
"""Test simple HTTP GET"""
response = self.get_response('/tracks/347', 200)
Expand All @@ -110,6 +121,19 @@ def test_get_expanded_resource(self):
response = self.get_response('/tracks/1', 200, params={'expand': 1})
assert 'album' in json.loads(response.get_data(as_text=True))

def test_get_etag_header(self):
"""Does GETing a resource with the ETag header return a 304?"""
response = self.get_response('/tracks/1', 200)
assert 'ETag' in response.headers
etag_value = response.headers['ETag']
cached_response = self.get_response('/tracks/1', 304, headers={'If-None-Match': etag_value}, has_data=False)

def test_get_etag_no_match(self):
"""Does GETing a resource return the 'Link' header field?"""
response = self.get_response('/tracks/1', 200)
assert 'ETag' in response.headers
cached_response = self.get_response('/tracks/1', 412, headers={'If-Match': 'foo'}, has_data=False)

def test_post(self):
"""Test simple HTTP POST"""
response = self.post_response()
Expand Down Expand Up @@ -151,6 +175,8 @@ def test_patch_new_resource(self):
assert json.loads(response.get_data(as_text=True))['Name'] == u'Jeff Knupp'
assert json.loads(response.get_data(as_text=True))['self'] == '/artists/276'



def test_patch_existing_resource(self):
"""Send HTTP PATCH for an existing resource (should be updated)."""
response = self.app.patch('/artists/275',
Expand Down Expand Up @@ -313,6 +339,11 @@ def test_get_html_non_existant_resource(self):
headers={'Accept': 'text/html'})
assert self.is_html_response(response)

def test_get_meta_html(self):
"""Test simple HTTP GET"""
response = self.get_response('/', 200, headers={'Accept': 'text/html'})
assert 'meta' in response.get_data()


def test_get_html_collection(self):
"""Test getting HTML version of a collection rather than JSON."""
Expand Down

0 comments on commit 6da13b7

Please sign in to comment.