Download:
child 102:325b3b4ce18b
parent 100:6b89941c4273
101:c9a81d64b0c3
Anton Shestakov <av6@dwimlabs.net>, Tue, 19 Jul 2016 17:51:59 +0800
tests: pass data to create_resource() and update_resource() explicitly

1 файлов изменено, 23 вставок(+), 29 удалений(-) [+]
test.py file | annotate | diff | comparison | revisions
--- a/test.py Tue Jul 19 17:44:31 2016 +0800
+++ b/test.py Tue Jul 19 17:51:59 2016 +0800
@@ -23,16 +23,14 @@
class ResourceTestCase(BaseTestCase):
- new_resource = {}
- resource_update = {}
resource_type = ''
list_url = ''
item_url = ''
all_url = '/%s/all/'
- def create_resource(self):
+ def create_resource(self, new_resource):
url = self.list_url % self.workspace
- response = self.c.post(url, content_type='application/json', data=json.dumps(self.new_resource))
+ response = self.c.post(url, content_type='application/json', data=json.dumps(new_resource))
data = json.loads(response.data)
self.assertIn('_t', data)
@@ -43,7 +41,7 @@
resource_id = data.pop('_id')
data.pop('_rev')
- self.assertDictEqual(self.new_resource, data)
+ self.assertDictEqual(new_resource, data)
return resource_id
@@ -67,13 +65,13 @@
self.assertIn(resource_id, [resource['_id'] for resource in combined])
- def update_resource(self, resource_id):
+ def update_resource(self, resource_id, resource_update):
url = self.item_url % (self.workspace, resource_id)
- response = self.c.put(url, content_type='application/json', data=json.dumps(self.resource_update))
+ response = self.c.put(url, content_type='application/json', data=json.dumps(resource_update))
data = json.loads(response.data)
self.assertEqual(data['_id'], resource_id)
- for key, value in self.resource_update.items():
+ for key, value in resource_update.items():
self.assertEqual(data[key], value)
def delete_resource(self, resource_id):
@@ -87,43 +85,39 @@
class ProjectsTestCase(ResourceTestCase):
- new_resource = {
- 'name': 'Test Project',
- 'color': 'success'
- }
- resource_update = {
- 'name': 'Renamed Project'
- }
resource_type = 'project'
list_url = '/%s/projects/'
item_url = '/%s/projects/%s/'
def test_project(self):
- project_id = self.create_resource()
+ project_id = self.create_resource({
+ 'name': 'Test Project',
+ 'color': 'success'
+ })
self.read_resource(project_id)
- self.update_resource(project_id)
+ self.update_resource(project_id, {
+ 'name': 'Renamed Project'
+ })
self.delete_resource(project_id)
class TasksTestCase(ResourceTestCase):
- new_resource = {
- 'name': 'Test Task',
- 'note': 'test',
- 'done': False,
- 'project_id': 'fake'
- }
- resource_update = {
- 'name': 'Renamed Task',
- 'note': 'the note'
- }
resource_type = 'task'
list_url = '/%s/tasks/'
item_url = '/%s/tasks/%s/'
def test_task(self):
- task_id = self.create_resource()
+ task_id = self.create_resource({
+ 'name': 'Test Task',
+ 'note': 'test',
+ 'done': False,
+ 'project_id': 'fake'
+ })
self.read_resource(task_id)
- self.update_resource(task_id)
+ self.update_resource(task_id, {
+ 'name': 'Renamed Task',
+ 'note': 'the note'
+ })
self.delete_resource(task_id)