[lxc-devel] [pylxd/master] Update the mock service to be more strict
rockstar on Github
lxc-bot at linuxcontainers.org
Tue May 31 01:57:08 UTC 2016
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 474 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20160531/3d020d05/attachment.bin>
-------------- next part --------------
From e87f17fff48b5e47da490f5e511fe306ade2471b Mon Sep 17 00:00:00 2001
From: Paul Hummer <paul at eventuallyanyway.com>
Date: Mon, 30 May 2016 19:52:23 -0600
Subject: [PATCH] Update the mock service to be more strict
---
pylxd/tests/mock_lxd.py | 55 ++++++++++++++++++++++++-------------------
pylxd/tests/test_container.py | 6 ++---
pylxd/tests/test_profile.py | 4 ++--
3 files changed, 36 insertions(+), 29 deletions(-)
diff --git a/pylxd/tests/mock_lxd.py b/pylxd/tests/mock_lxd.py
index 30ddb0c..5e2aea4 100644
--- a/pylxd/tests/mock_lxd.py
+++ b/pylxd/tests/mock_lxd.py
@@ -21,19 +21,21 @@ def profiles_POST(request, context):
return json.dumps({'metadata': {}})
+def snapshot_DELETE(request, context):
+ context.status_code = 202
+ return json.dumps({'operation': 'operation-abc'})
+
+
def profile_GET(request, context):
name = request.path.split('/')[-1]
- if name in ('an-profile', 'an-new-profile'):
- return json.dumps({
- 'metadata': {
- 'name': name,
- 'description': 'An description',
- 'config': {},
- 'devices': {},
- },
- })
- else:
- context.status_code = 404
+ return json.dumps({
+ 'metadata': {
+ 'name': name,
+ 'description': 'An description',
+ 'config': {},
+ 'devices': {},
+ },
+ })
RULES = [
@@ -63,7 +65,7 @@ def profile_GET(request, context):
'ephemeral': True,
}}),
'method': 'GET',
- 'url': r'^http://pylxd.test/1.0/containers/(?P<container_name>.*)$',
+ 'url': r'^http://pylxd.test/1.0/containers/an-container$',
},
{
'text': json.dumps({'metadata': {
@@ -71,19 +73,19 @@ def profile_GET(request, context):
'status_code': 103,
}}),
'method': 'GET',
- 'url': r'^http://pylxd.test/1.0/containers/(?P<container_name>.*)/state$', # NOQA
+ 'url': r'^http://pylxd.test/1.0/containers/an-container/state$', # NOQA
},
{
'text': json.dumps({'metadata': [
'/1.0/containers/an_container/snapshots/an-snapshot',
]}),
'method': 'GET',
- 'url': r'^http://pylxd.test/1.0/containers/(?P<container_name>.*)/snapshots$', # NOQA
+ 'url': r'^http://pylxd.test/1.0/containers/an-container/snapshots$', # NOQA
},
{
'text': json.dumps({'operation': 'operation-abc'}),
'method': 'POST',
- 'url': r'^http://pylxd.test/1.0/containers/(?P<container_name>.*)/snapshots$', # NOQA
+ 'url': r'^http://pylxd.test/1.0/containers/an-container/snapshots$', # NOQA
},
{
'text': json.dumps({'metadata': {
@@ -91,32 +93,32 @@ def profile_GET(request, context):
'stateful': False,
}}),
'method': 'GET',
- 'url': r'^http://pylxd.test/1.0/containers/(?P<container>.*)/snapshots/(?P<snapshot>.*)$', # NOQA
+ 'url': r'^http://pylxd.test/1.0/containers/an-container/snapshots/an-snapshot$', # NOQA
},
{
'text': json.dumps({'operation': 'operation-abc'}),
'method': 'POST',
- 'url': r'^http://pylxd.test/1.0/containers/(?P<container>.*)/snapshots/(?P<snapshot>.*)$', # NOQA
+ 'url': r'^http://pylxd.test/1.0/containers/an-container/snapshots/an-snapshot$', # NOQA
},
{
- 'text': json.dumps({'operation': 'operation-abc'}),
+ 'text': snapshot_DELETE,
'method': 'DELETE',
- 'url': r'^http://pylxd.test/1.0/containers/(?P<container>.*)/snapshots/(?P<snapshot>.*)$', # NOQA
+ 'url': r'^http://pylxd.test/1.0/containers/an-container/snapshots/an-snapshot$', # NOQA
},
{
'text': json.dumps({'operation': 'operation-abc'}),
'method': 'POST',
- 'url': r'^http://pylxd.test/1.0/containers/(?P<container_name>.*)$',
+ 'url': r'^http://pylxd.test/1.0/containers/an-container$',
},
{
'text': json.dumps({'operation': 'operation-abc'}),
'method': 'PUT',
- 'url': r'^http://pylxd.test/1.0/containers/(?P<container_name>.*)$',
+ 'url': r'^http://pylxd.test/1.0/containers/an-container$',
},
{
'text': container_DELETE,
'method': 'DELETE',
- 'url': r'^http://pylxd.test/1.0/containers/(?P<container_name>.*)$',
+ 'url': r'^http://pylxd.test/1.0/containers/an-container$',
},
# Images
@@ -175,13 +177,18 @@ def profile_GET(request, context):
{
'text': profile_GET,
'method': 'GET',
- 'url': r'^http://pylxd.test/1.0/profiles/(?P<container_name>.*)$',
+ 'url': r'^http://pylxd.test/1.0/profiles/(an-profile|an-new-profile)$',
},
# Operations
{
'text': '{"metadata": {"id": "operation-abc"}}',
'method': 'GET',
- 'url': r'^http://pylxd.test/1.0/operations/(?P<operation_id>.*)$',
+ 'url': r'^http://pylxd.test/1.0/operations/operation-abc$',
+ },
+ {
+ 'text': '{"metadata": {}',
+ 'method': 'GET',
+ 'url': r'^http://pylxd.test/1.0/operations/operation-abc/wait$',
},
]
diff --git a/pylxd/tests/test_container.py b/pylxd/tests/test_container.py
index ca324ae..785b67b 100644
--- a/pylxd/tests/test_container.py
+++ b/pylxd/tests/test_container.py
@@ -32,7 +32,7 @@ def not_found(request, context):
self.add_rule({
'text': not_found,
'method': 'GET',
- 'url': r'^http://pylxd.test/1.0/containers/(?P<container_name>.*)$', # NOQA
+ 'url': r'^http://pylxd.test/1.0/containers/an-missing-container$', # NOQA
})
name = 'an-missing-container'
@@ -89,7 +89,7 @@ def not_found(request, context):
self.add_rule({
'text': not_found,
'method': 'GET',
- 'url': r'^http://pylxd.test/1.0/containers/(?P<container_name>.*)$', # NOQA
+ 'url': r'^http://pylxd.test/1.0/containers/an-missing-container$', # NOQA
})
an_container = container.Container(
@@ -224,7 +224,7 @@ def not_found(request, context):
self.add_rule({
'text': not_found,
'method': 'DELETE',
- 'url': r'^http://pylxd.test/1.0/containers/(?P<container>.*)/snapshots/(?P<snapshot>.*)$', # NOQA
+ 'url': r'^http://pylxd.test/1.0/containers/an-container/snapshots/an-snapshot$', # NOQA
})
snapshot = container.Snapshot(
diff --git a/pylxd/tests/test_profile.py b/pylxd/tests/test_profile.py
index 72e0692..9abc487 100644
--- a/pylxd/tests/test_profile.py
+++ b/pylxd/tests/test_profile.py
@@ -25,7 +25,7 @@ def not_found(request, context):
self.add_rule({
'text': not_found,
'method': 'GET',
- 'url': r'^http://pylxd.test/1.0/profiles/(?P<container_name>.*)$',
+ 'url': r'^http://pylxd.test/1.0/profiles/an-profile$',
})
self.assertRaises(
@@ -99,7 +99,7 @@ def not_found(request, context):
self.add_rule({
'text': not_found,
'method': 'GET',
- 'url': r'^http://pylxd.test/1.0/profiles/(?P<container_name>.*)$',
+ 'url': r'^http://pylxd.test/1.0/profiles/an-profile$',
})
an_profile = profile.Profile(name='an-profile', _client=self.client)
More information about the lxc-devel
mailing list