Anton Shestakov <av6@dwimlabs.net>, Fri, 27 May 2016 18:37:01 +0800
docs: add release dates
test.py
Permissions: -rwxr-xr-x
from itertools import chain from unittest import TestCase, main class BaseTestCase(TestCase): self.c = app.test_client() class IndexTestCase(BaseTestCase): response = self.c.get('/') self.assertIn('Fruit Bar', response.data) self.assertRegexpMatches(response.data, 'bundles/fruitbar\.[0-9a-f]+\.js') class ResourceTestCase(BaseTestCase): def create_resource(self): url = self.list_url % self.workspace response = self.c.post(url, content_type='application/json', data=json.dumps(self.new_resource)) data = json.loads(response.data) self.assertIn('_t', data) self.assertEqual(data.pop('_t'), self.resource_type) self.assertIn('workspace', data) self.assertEqual(data.pop('workspace'), self.workspace) resource_id = data.pop('_id') self.assertDictEqual(self.new_resource, data) def read_resource(self, resource_id): url = self.item_url % (self.workspace, resource_id) response = self.c.get(url) data = json.loads(response.data) self.assertEqual(data['_id'], resource_id) url = self.list_url % self.workspace response = self.c.get(url) data = json.loads(response.data) self.assertTrue(any(resource.get('_id', None) == resource_id for resource in data)) url = self.all_url % self.workspace response = self.c.get(url) data = json.loads(response.data) self.assertTrue(any(resource.get('_id', None) == resource_id for resource in chain(*data.values()))) def update_resource(self, resource_id): url = self.item_url % (self.workspace, resource_id) response = self.c.put(url, content_type='application/json', data=json.dumps(self.resource_update)) data = json.loads(response.data) self.assertEqual(data['_id'], resource_id) for key, value in self.resource_update.items(): self.assertEqual(data[key], value) def delete_resource(self, resource_id): url = self.item_url % (self.workspace, resource_id) response = self.c.delete(url) data = json.loads(response.data) self.assertEqual(data, '') response = self.c.get(url) self.assertEqual(response.status_code, 404) class ProjectsTestCase(ResourceTestCase): 'name': 'Renamed Project' resource_type = 'project' list_url = '/%s/projects/' item_url = '/%s/projects/%s/' project_id = self.create_resource() self.read_resource(project_id) self.update_resource(project_id) self.delete_resource(project_id) class TasksTestCase(ResourceTestCase): item_url = '/%s/tasks/%s/' task_id = self.create_resource() self.read_resource(task_id) self.update_resource(task_id) self.delete_resource(task_id) if __name__ == '__main__': app.config['DEBUG'] = False app.config['ASSETS_DEBUG'] = False app.config['TESTING'] = True app.config['DATABASE'] = 'test_db'