Skip to content

Commit

Permalink
More passing tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
cyli committed May 1, 2015
1 parent 65252bd commit 3952d93
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
8 changes: 6 additions & 2 deletions mimic/model/nova_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,8 +560,7 @@ def request_list(self, http_get_request, include_details, absolutize_url,
Pagination behavior verified against Rackspace Nova as of 2015-04-29.
"""
to_be_listed = [server for server in self.servers
if name in server.server_name]
to_be_listed = self.servers

# marker can be passed without limit, in which case the whole server
# list, after the server that matches the marker, is returned
Expand All @@ -578,6 +577,11 @@ def request_list(self, http_get_request, include_details, absolutize_url,
last_seen = last_seen[0]
to_be_listed = to_be_listed[last_seen + 1:]

# A valid marker is an ID in the entire server list. It does not
# have to be for a server that matches the given name.
to_be_listed = [server for server in to_be_listed
if name in server.server_name]

if limit is not None:
try:
limit = int(limit)
Expand Down
27 changes: 17 additions & 10 deletions mimic/test/test_nova.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@ def list_servers(self, path, params=None, code=200):

resp, body = self.successResultOf(
json_request(self, self.root, "GET", url))

self.assertEqual(resp.code, code)
return body

Expand All @@ -468,6 +469,7 @@ def match_body_with_links(self, result, expected_servers, expected_path,
Given the result from listing servers, matches it against an expected
value that includes the next page links.
"""
self.assertEqual(expected_servers, result['servers'])
expected_matcher = MatchesDict({
'servers': Equals(expected_servers),
'servers_links': MatchesListwise([
Expand All @@ -479,8 +481,9 @@ def match_body_with_links(self, result, expected_servers, expected_path,
])
})
mismatch = expected_matcher.match(result)
self.assertEqual(None, mismatch,
"Great" if mismatch is None else mismatch.describe())
if mismatch is not None:
self.fail(mismatch.describe())

link = result['servers_links'][0]['href']
query_string = link.split('?', 1)[-1]
self.assertEqual(expected_query_params, parse_qs(query_string))
Expand All @@ -499,12 +502,12 @@ def test_with_invalid_marker(self):
combo['marker'] = '9000'
error_body = self.list_servers(path, combo, code=400)
self.assertEqual(
json.dumps({
{
"badRequest": {
"message": "marker [9000] not found",
"code": 400
}
}),
},
error_body)

def test_with_invalid_limit(self):
Expand All @@ -524,12 +527,12 @@ def test_with_invalid_limit(self):
combo['limit'] = 'a'
error_body = self.list_servers(path, combo, code=400)
self.assertEqual(
json.dumps({
{
"badRequest": {
"message": "limit param must be an integer",
"code": 400
}
}),
},
error_body)

def test_with_limit_as_0(self):
Expand Down Expand Up @@ -614,7 +617,7 @@ def test_with_limit_eq_servers_only(self):
with_params = self.list_servers(path, {'limit': 5})
self.match_body_with_links(
with_params,
expected_servers=[servers[0]],
expected_servers=servers,
expected_path=path,
expected_query_params={
'limit': ['1'], 'marker': [servers[0]['id']]
Expand Down Expand Up @@ -655,7 +658,9 @@ def test_with_limit_lt_servers_with_name(self):
expected_servers=[servers[1]],
expected_path=path,
expected_query_params={
'limit': ['1'], 'marker': [servers[1]['id']]
'limit': ['1'],
'marker': [servers[1]['id']],
'name': ['1']
}
)

Expand Down Expand Up @@ -716,7 +721,7 @@ def test_with_limit_lt_servers_with_marker(self):
path, {'limit': 1, 'marker': servers[0]['id']})
self.match_body_with_links(
with_params,
expected_servers=servers[1:],
expected_servers=[servers[1]],
expected_path=path,
expected_query_params={
'limit': ['1'], 'marker': [servers[1]['id']]
Expand Down Expand Up @@ -784,7 +789,9 @@ def test_with_limit_lt_servers_with_marker_and_name(self):
expected_servers=[servers[3]],
expected_path=path,
expected_query_params={
'limit': ['1'], 'marker': [servers[3]['id']]
'limit': ['1'],
'marker': [servers[3]['id']],
'name': ['1']
}
)

Expand Down

0 comments on commit 3952d93

Please sign in to comment.