122:e46f050f6b7a
Anton Shestakov <av6@dwimlabs.net>, Thu, 11 Aug 2016 13:03:42 +0800
pipelines: write valid yaml Pipelines don't yet support multiple steps, but let's see what happens.

previous change 120:d3d03451dfc0

test.py

Permissions: -rwxr-xr-x

Other formats: Feeds:
#!/usr/bin/env python
import json
from itertools import chain
from unittest import TestCase, main
from app import app
class BaseTestCase(TestCase):
workspace = 'TESTING'
def setUp(self):
self.c = app.test_client()
class IndexTestCase(BaseTestCase):
def test_index(self):
response = self.c.get('/')
self.assertIn('Fruitbar Todo', response.data)
bundle_re = 'bundles/fruitbar\.[0-9a-f]+\.js'
self.assertRegexpMatches(response.data, bundle_re)
class ResourceTestCase(BaseTestCase):
resource_type = ''
list_url = ''
item_url = ''
all_url = '/%s/all/'
def json_payload(self, data):
return {'content_type': 'application/json', 'data': json.dumps(data)}
def create_resource(self, new_resource):
url = self.list_url % self.workspace
response = self.c.post(url, **self.json_payload(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')
data.pop('_rev')
self.assertDictEqual(new_resource, data)
return resource_id
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)
self.assertIn('_rev', data)
url = self.list_url % self.workspace
response = self.c.get(url)
data = json.loads(response.data)
self.assertIn(resource_id, [resource['_id'] for resource in data])
url = self.all_url % self.workspace
response = self.c.get(url)
data = json.loads(response.data)
combined = chain(*data.values())
self.assertIn(resource_id, [resource['_id'] for resource in combined])
def update_resource(self, resource_id, resource_update):
url = self.item_url % (self.workspace, resource_id)
response = self.c.put(url, **self.json_payload(resource_update))
data = json.loads(response.data)
self.assertEqual(data['_id'], resource_id)
for key, value in 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):
resource_type = 'project'
list_url = '/%s/projects/'
item_url = '/%s/projects/%s/'
def test_project(self):
project_id = self.create_resource({
'name': 'Test Project',
'color': 'success'
})
self.read_resource(project_id)
self.update_resource(project_id, {
'name': 'Renamed Project'
})
self.delete_resource(project_id)
class TasksTestCase(ResourceTestCase):
resource_type = 'task'
list_url = '/%s/tasks/'
item_url = '/%s/tasks/%s/'
def test_task(self):
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, {
'name': 'Renamed Task',
'note': 'the note'
})
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'
main()