--- a/test.py Tue Jul 19 17:44:31 2016 +0800
+++ b/test.py Tue Jul 19 17:51:59 2016 +0800
class ResourceTestCase(BaseTestCase):
- 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)
resource_id = data.pop('_id')
- self.assertDictEqual(self.new_resource, data)
+ self.assertDictEqual(new_resource, data)
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):
class ProjectsTestCase(ResourceTestCase):
- 'name': 'Test Project',
- 'name': 'Renamed Project'
resource_type = 'project'
list_url = '/%s/projects/'
item_url = '/%s/projects/%s/'
- project_id = self.create_resource()
+ project_id = self.create_resource({
+ 'name': 'Test Project',
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):
- 'name': 'Renamed Task',
item_url = '/%s/tasks/%s/'
- task_id = self.create_resource()
+ task_id = self.create_resource({
self.read_resource(task_id)
- self.update_resource(task_id)
+ self.update_resource(task_id, {
+ 'name': 'Renamed Task',
self.delete_resource(task_id)