def test_load_task_done(self): create_entity(Task('title2', 'detail2', status='DONE', price=10, team=Team.query.get(1))) create_entity(Task('title1', 'detail1', status='DONE', price=10, start_time=miami.utils.now() - timedelta(days=7), team=Team.query.get(1))) rv = self.app.get('/tasks/DONE') self.assertEquals(200, rv.status_code) self.assertEquals({ "objects": [ { "title": "title2", "price": 10, "detail": "detail2", "status":'DONE', "owner": {}, "partner": {}, "team": { 'id':1, "color": "2a33d8", "name": "Log" }, "estimate": 0, 'priority': 100, 'time_slots': [], 'consuming': '0', "last_updated": "just now", 'created_time': 'just now', "id": 1 } ] }, json.loads(rv.data))
def test_task_burning(self): task = Task('title2', 'detail2', estimate=10, price=10, status='PROGRESS', start_time=datetime(2012, 11, 11, 10, 0, 0), team=Team.query.get(1)) task.owner = User.query.get(1) create_entity(task) create_entity( Task('title1', 'detail1', estimate=10, price=5, status='DONE', start_time=datetime(2012, 11, 11, 12, 0, 0), team=Team.query.get(1))) create_entity( Task('title3', 'detail3', estimate=0, price=5, status='READY', start_time=datetime(2012, 11, 10, 12, 0, 0), team=Team.query.get(1))) miami.zeroing() burning = Burning.query.get(1) self.assertEquals(datetime(2012, 11, 11, 0, 0, 0), burning.day) self.assertEquals(5, burning.burning) self.assertEquals(15, burning.remaining) self.assertEquals(Team.query.get(1), burning.team)
def setUp(self): BaseTestCase.setUp(self) when(miami.utils).now().thenReturn(datetime(2012, 11, 5, 9, 0, 0)) team = Team('Miami') team.members.append(User('Bob')) team.members.append(User.query.get(1)) task = Task('title1', 'detail', status='DONE', price=2, estimate=4, team=team, ready_time=datetime(2012, 11, 1, 10, 0, 0)) ts = TimeSlot(datetime(2012, 11, 1, 10, 0, 0), 3600, User.query.get(1)) task.time_slots.append(ts) self.create_entity(task) task = Task('title2', 'detai2', status='NEW', price=2, estimate=4, team=team, ready_time=datetime(2012, 11, 1, 10, 0, 0)) ts = TimeSlot(datetime(2012, 11, 2, 10, 0, 0), 3600, User.query.get(1), partner=User.query.get(2)) task.time_slots.append(ts) self.create_entity(task)
def create_task(): if current_user.teams.count() == 0: abort(403) jsons = json.loads(request.data) if jsons.get('id', 0): task = Task.query.get_or_404(jsons.get('id')) task.title = jsons.get('title', '') task.detail = jsons.get('detail', '') db.session.commit() return jsonify(object=task.toJSON()), 200 else: status = jsons.get('status', 'NEW') if status not in ['NEW', 'READY']: abort(403) price = jsons.get('price', 0) if status == 'READY' and price == 0: abort(403) team_id=int(jsons.get('team_id',0)) task = Task(jsons.get('title'), jsons.get( 'detail',''), priority=jsons.get('priority', 100), status=status, price=price, team=Team.query.get(team_id) if team_id else current_user.teams[0]) for category_name in jsons.get('categories', '').split(','): if not category_name: category_name=u'未分类' category = Category.query.filter(Category.name == category_name).first() if category: task.categories.append(category) else: task.categories.append(Category(category_name)) db.session.add(task) db.session.commit() return jsonify(object=task.toJSON()), 201
def test_load_task(self): create_entity(Task('title2', 'detail2', status='READY', price=10, team=Team.query.get(1))) create_entity(Task('title1', 'detail1', status='READY', price=10, team=Team('Refresh'))) rv = self.app.get('/tasks/READY') self.assertEquals(200, rv.status_code) self.assertEquals({ "objects": [ { "title": "title2", "price": 10, "detail": "detail2", "status":'READY', "owner": {}, "partner": {}, "team": { 'id':1, "color": "2a33d8", "name": "Log" }, 'time_slots': [], 'consuming': '0', 'priority': 100, "estimate": 0, 'last_updated': 'just now', 'created_time': 'just now', "id": 1 } ] }, json.loads(rv.data))
def test_leave_paired(self): task = Task('title2', 'detail2', estimate=10, price=10, status='PROGRESS', start_time=datetime(2012, 11, 11), team=Team.query.get(1)) task.owner = User.query.get(2) task.partner = User.query.get(1) create_entity(task) rv = self.app.put('/leavetask/1') self.assertEquals(200, rv.status_code) self.assertEquals({ "object": { "status": "PROGRESS", "owner": { "gravater": "91f376c4b36912e5075b6170d312eab5", "name": "Bob" }, "consuming": "1", 'priority': 100, "time_slots": [ { "partner": { "gravater": "91f376c4b36912e5075b6170d312eab5", "name": "Mike" }, "start_time": "3 months ago", "consuming_hours": "1", "user": { "gravater": "91f376c4b36912e5075b6170d312eab5", "name": "Bob" }, "bar_width": "100.00%" } ], "title": "title2", "estimate": 10, "partner": { }, "price": 10, "team": { 'id':1, "color": "2a33d8", "name": "Log" }, "id": 1, 'last_updated': 'just now', 'created_time': 'just now', "detail": "detail2" } }, json.loads(rv.data)) task = Task.query.get(1) self.assertIsNone(task.partner) self.assertEquals('PROGRESS', task.status) self.assertEquals(1, task.time_slots.count()) self.assertEquals(datetime(2012, 11, 11, 1, 0, 0), task.start_time) self.assertEquals(3600, task.time_slots[0].consuming) self.assertEquals('Bob', task.time_slots[0].user.name) self.assertEquals('Mike', task.time_slots[0].partner.name)
def test_owner_one_task(self): task = Task('title2', 'detail2', estimate=10, price=10, status='PROGRESS', start_time=datetime(2012, 11, 11)) task.owner = User.query.get(1) create_entity(task) create_entity(Task('title3', 'detail3', estimate=10, price=10, status='READY', start_time=datetime(2012, 11, 11))) rv = self.app.put('/tasks/PROGRESS/2') self.assertEquals(403, rv.status_code)
def test_task_toJSON(self): team = Team('Log') team.id = 1 task = Task('title1', 'detail', status='DONE', price=1, estimate=4, team=team) task.id = 1 task.owner = User('Mike') self.assertEquals({'id': 1, 'title': 'title1', 'detail': 'detail', 'status': 'DONE', 'price': 1, 'estimate': 4,'priority': 100,'time_slots': [], 'consuming': '0','created_time': 'just now', 'last_updated': 'just now', 'team': { 'name': 'Log', 'color': '2a33d8', 'id':1}, 'owner': {'name': 'Mike', 'gravater': '91f376c4b36912e5075b6170d312eab5'}, 'partner': {}}, task.toJSON())
def test_not_allow_to_progress(self): create_entity(User('Bob')) task = Task('title1', 'detail1', estimate=10, price=10, status='PROGRESS', start_time=datetime(2012, 11, 11)) task.partner = User.query.get(1) task.owner = User.query.get(2) create_entity(task) create_entity(Task('title2', 'detail2', estimate=10, price=10, status='READY', start_time=datetime(2012, 11, 11))) rv = self.app.put('/tasks/PROGRESS/2') self.assertEquals(403, rv.status_code)
def test_progress_to_ready(self): task = Task('title2', 'detail2', estimate=10, price=10, status='PROGRESS', start_time=datetime(2012, 11, 11), team=Team.query.get(1)) task.owner = User.query.get(1) create_entity(task) rv = self.app.put('/tasks/READY/1') self.assertEquals(200, rv.status_code) task = Task.query.get(1) self.assertEquals('READY', task.status) self.assertEquals(3600, task.consuming) self.assertEquals(1, task.time_slots[0].user.id)
def test_not_allow_join(self): create_entity(User('Bob')) task = Task('title1', 'detail1', estimate=10, price=10, status='PROGRESS', start_time=datetime(2012, 11, 11)) task.owner = User.query.get(2) create_entity(task) task = Task('title2', 'detail2', estimate=10, price=10, status='PROGRESS', start_time=datetime(2012, 11, 11)) task.owner = User.query.get(1) create_entity(task) rv = self.app.put('/jointask/1') self.assertEquals(403, rv.status_code)
def test_task_zeroing(self): task = Task('title2', 'detail2', estimate=10, price=10, status='PROGRESS', start_time=datetime(2012, 11, 11, 10, 0, 0), team=Team.query.get(1)) task.owner = User.query.get(1) create_entity(task) miami.zeroing() task = Task.query.get(1) self.assertEquals('READY', task.status) self.assertIsNone(task.partner) self.assertEquals(28800.0, task.consuming) self.assertEquals(1, task.time_slots.count())
def test_ready_to_progress_noauth(self): task = Task('title2', 'detail2', estimate=10, price=10, status='PROGRESS', start_time=datetime(2012, 11, 11)) mike = User.query.get(1) task.owner = mike task.time_slots.append(TimeSlot(task.start_time, 20, mike)) create_entity(task) create_entity(User('Bob')) self.logout() self.login('Bob', '') rv = self.app.put('/tasks/PROGRESS/1') self.assertEquals(401, rv.status_code)
def test_task_burning(self): task = Task('title2', 'detail2', estimate=10, price=10, status='PROGRESS', start_time=datetime(2012, 11, 11, 10, 0, 0), team=Team.query.get(1)) task.owner = User.query.get(1) create_entity(task) create_entity(Task('title1', 'detail1', estimate=10, price=5, status='DONE', start_time=datetime(2012, 11, 11, 12, 0, 0), team=Team.query.get(1))) create_entity(Task('title3', 'detail3', estimate=0, price=5, status='READY', start_time=datetime(2012, 11, 10, 12, 0, 0), team=Team.query.get(1))) miami.zeroing() burning = Burning.query.get(1) self.assertEquals(datetime(2012, 11, 11, 0, 0, 0),burning.day) self.assertEquals(5,burning.burning) self.assertEquals(15,burning.remaining) self.assertEquals(Team.query.get(1),burning.team)
def test_new_to_ready_without_price(self): create_entity(Task('title', 'detail')) rv = self.app.put('/tasks/READY/1') self.assertEquals(400, rv.status_code) self.assertEquals({'id': 1}, json.loads(rv.data))
def test_estimate(self): create_entity(Task('title1', 'detail1', status='READY', team=Team.query.get(1))) rv = self.app.put('/estimate/1/10') self.assertEquals('200 OK', rv.status) self.assertEquals({'object': {'detail': 'detail1', 'estimate': 10, 'id': 1, 'last_updated': 'just now', 'created_time': 'just now', 'owner': {'gravater': '91f376c4b36912e5075b6170d312eab5', 'name': 'Mike'}, 'partner': {}, 'price': 0, 'status': 'PROGRESS', 'team': {'id':1, 'color': '2a33d8', 'name': 'Log'}, 'time_slots': [], 'consuming': '0', 'priority': 100, 'title': 'title1'}}, json.loads(rv.data)) task = Task.query.get(1) self.assertEquals('PROGRESS', task.status) self.assertEquals('Mike', task.owner.name)
def test_ready_to_progress_without_estimate(self): create_entity(Task('title1', 'detail1', status='READY')) rv = self.app.put('/tasks/PROGRESS/1') self.assertEquals(400, rv.status_code) self.assertEquals({'id': 1}, json.loads(rv.data))
def test_multi_timeslots(self): create_entity(User('Bob')) task = Task('title2', 'detail2', estimate=10, price=10, status='PROGRESS', start_time=datetime(2012, 11, 11), team=Team.query.get(1)) task.time_slots.append(TimeSlot(task.start_time, 3600, User.query.get(1))) task.owner = User.query.get(2) create_entity(task) self.logout() self.login('Bob', '') rv = self.app.put('/tasks/READY/1') self.assertEquals(200, rv.status_code) task = Task.query.get(1) self.assertEquals('READY', task.status) self.assertEquals(7200, task.consuming) self.assertEquals(1, task.time_slots[0].user.id) self.assertEquals(2, task.time_slots[1].user.id)
def test_ready_to_progress_with_estimate(self): create_entity(Task('title2', 'detail2', status='READY', estimate=10, team=Team.query.get(1))) rv = self.app.put('/tasks/PROGRESS/1') self.assertEquals(200, rv.status_code) task = Task.query.get(1) self.assertEquals('PROGRESS', task.status)
def test_ready_to_progress_without_estimate_logout(self): self.logout() create_entity(Task('title1', 'detail1', status='READY')) rv = self.app.put('/tasks/PROGRESS/1') self.assertEquals(401, rv.status_code) assert '<form action="/login" method="POST" class="form-horizontal">' in rv.data
def test_new_to_ready_with_price(self): create_entity(Task('title', 'detail', price=20, team=Team.query.get(1))) rv = self.app.put('/tasks/READY/1') self.assertEquals(200, rv.status_code) task = Task.query.get(1) self.assertEquals('READY', task.status) self.assertEquals(miami.utils.now(), task.ready_time)
def test_pricing(self): create_entity(Task('title1', 'detail1', status='NEW')) rv = self.app.put('/pricing/1/10') self.assertEquals(200, rv.status_code) self.assertEquals({"id": 1}, json.loads(rv.data)) task = Task.query.get(1) self.assertEquals('READY', task.status)
def test_not_allow_to_progress(self): create_entity(User('Bob')) task = Task('title1', 'detail1', estimate=10, price=10, status='PROGRESS', start_time=datetime(2012, 11, 11)) task.partner = User.query.get(1) task.owner = User.query.get(2) create_entity(task) create_entity( Task('title2', 'detail2', estimate=10, price=10, status='READY', start_time=datetime(2012, 11, 11))) rv = self.app.put('/tasks/PROGRESS/2') self.assertEquals(403, rv.status_code)
def create_task(): if current_user.teams.count() == 0: abort(403) jsons = json.loads(request.data) if jsons.get('id', 0): task = Task.query.get_or_404(jsons.get('id')) task.title = jsons.get('title', '') task.detail = jsons.get('detail', '') db.session.commit() return jsonify(object=task.toJSON()), 200 else: status = jsons.get('status', 'NEW') if status not in ['NEW', 'READY']: abort(403) price = jsons.get('price', 0) if status == 'READY' and price == 0: abort(403) team_id = int(jsons.get('team_id', 0)) task = Task( jsons.get('title'), jsons.get('detail', ''), priority=jsons.get('priority', 100), status=status, price=price, team=Team.query.get(team_id) if team_id else current_user.teams[0]) for category_name in jsons.get('categories', '').split(','): if not category_name: category_name = u'未分类' category = Category.query.filter( Category.name == category_name).first() if category: task.categories.append(category) else: task.categories.append(Category(category_name)) db.session.add(task) db.session.commit() return jsonify(object=task.toJSON()), 201
def test_task_toJSON(self): team = Team('Log') team.id = 1 task = Task('title1', 'detail', status='DONE', price=1, estimate=4, team=team) task.id = 1 task.owner = User('Mike') self.assertEquals( { 'id': 1, 'title': 'title1', 'detail': 'detail', 'status': 'DONE', 'price': 1, 'estimate': 4, 'priority': 100, 'time_slots': [], 'consuming': '0', 'created_time': 'just now', 'last_updated': 'just now', 'team': { 'name': 'Log', 'color': '2a33d8', 'id': 1 }, 'owner': { 'name': 'Mike', 'gravater': '91f376c4b36912e5075b6170d312eab5' }, 'partner': {} }, task.toJSON())
def test_not_allow_multi_paired(self): create_entity(User('Bob')) create_entity(User('Martin')) task = Task('title1', 'detail1', estimate=10, price=10, status='PROGRESS', start_time=datetime(2012, 11, 11)) task.partner = User.query.get(1) task.owner = User.query.get(2) create_entity(task) task = Task('title2', 'detail2', estimate=10, price=10, status='READY', start_time=datetime(2012, 11, 11)) task.owner = User.query.get(3) create_entity(task) rv = self.app.put('/jointask/2') self.assertEquals(403, rv.status_code)
def test_join_partner(self): task = Task('title2', 'detail2', estimate=10, price=10, status='PROGRESS', start_time=datetime(2012, 11, 11), team=Team.query.get(1)) task.owner = User.query.get(2) create_entity(task) rv = self.app.put('/jointask/1') self.assertEquals(200, rv.status_code) self.assertEquals( { "object": { "status": "PROGRESS", 'consuming': '1', "time_slots": [{ "partner": {}, "start_time": "3 months ago", "consuming_hours": "1", "user": { "gravater": "91f376c4b36912e5075b6170d312eab5", "name": "Bob" }, "bar_width": "100.00%" }], "owner": { "gravater": "91f376c4b36912e5075b6170d312eab5", "name": "Bob" }, "title": "title2", "estimate": 10, 'priority': 100, "partner": { "gravater": "91f376c4b36912e5075b6170d312eab5", "name": "Mike" }, "price": 10, "team": { 'id': 1, "color": "2a33d8", "name": "Log" }, "id": 1, 'last_updated': 'just now', 'created_time': 'just now', "detail": "detail2" } }, json.loads(rv.data)) task = Task.query.get(1) self.assertEquals(1, task.time_slots.count()) self.assertEquals('PROGRESS', task.status) self.assertEquals(3600, task.time_slots[0].consuming) self.assertEquals('Bob', task.time_slots[0].user.name) self.assertIsNone(task.time_slots[0].partner) self.assertEquals(task.start_time, miami.utils.now())
def test_paired_to_done(self): task = Task('title2', 'detail2', estimate=10, price=10, status='PROGRESS', start_time=datetime(2012, 11, 11), team=Team.query.get(1)) task.owner = User.query.get(1) task.partner = User.query.get(2) task.start_time = datetime(2012, 11, 11, 1, 0, 0) task.time_slots.append(TimeSlot(task.start_time, 3600, task.owner)) create_entity(task) when(miami.utils).now().thenReturn(datetime(2012, 11, 11, 2, 0, 0)) rv = self.app.put('/tasks/DONE/1') self.assertEquals(200, rv.status_code) self.assertEquals( { 'object': { 'detail': 'detail2', 'estimate': 10, 'id': 1, 'last_updated': 'just now', 'created_time': 'just now', 'owner': {}, 'partner': {}, 'price': 10, 'status': 'DONE', "consuming": "2", 'priority': 100, "time_slots": [{ "partner": {}, "start_time": "3 months ago", "consuming_hours": "1", "user": { "gravater": "91f376c4b36912e5075b6170d312eab5", "name": "Mike" }, "bar_width": "50.00%" }, { "partner": { "gravater": "91f376c4b36912e5075b6170d312eab5", "name": "Bob" }, "start_time": "3 months ago", "consuming_hours": "1", "user": { "gravater": "91f376c4b36912e5075b6170d312eab5", "name": "Mike" }, "bar_width": "50.00%" }], 'team': { 'id': 1, 'color': '2a33d8', 'name': 'Log' }, 'title': 'title2' } }, json.loads(rv.data)) task = Task.query.get(1) self.assertIsNone(task.partner) self.assertIsNone(task.owner) self.assertEquals('DONE', task.status) self.assertEquals(2, task.time_slots.count()) self.assertEquals(3600, task.time_slots[0].consuming) self.assertEquals('Mike', task.time_slots[0].user.name) self.assertIsNone(task.time_slots[0].partner) self.assertEquals(3600, task.time_slots[1].consuming) self.assertEquals('Mike', task.time_slots[1].user.name) self.assertEquals('Bob', task.time_slots[1].partner.name)
def test_paired_to_done(self): task = Task('title2', 'detail2', estimate=10, price=10, status='PROGRESS', start_time=datetime(2012, 11, 11), team=Team.query.get(1)) task.owner = User.query.get(1) task.partner = User.query.get(2) task.start_time = datetime(2012, 11, 11, 1, 0, 0) task.time_slots.append(TimeSlot(task.start_time, 3600, task.owner)) create_entity(task) when(miami.utils).now().thenReturn(datetime(2012, 11, 11, 2, 0, 0)) rv = self.app.put('/tasks/DONE/1') self.assertEquals(200, rv.status_code) self.assertEquals({'object': {'detail': 'detail2', 'estimate': 10, 'id': 1, 'last_updated': 'just now', 'created_time': 'just now', 'owner': {}, 'partner': {}, 'price': 10, 'status': 'DONE', "consuming": "2", 'priority': 100, "time_slots": [ { "partner": {}, "start_time": "3 months ago", "consuming_hours": "1", "user": { "gravater": "91f376c4b36912e5075b6170d312eab5", "name": "Mike" }, "bar_width": "50.00%" }, { "partner": { "gravater": "91f376c4b36912e5075b6170d312eab5", "name": "Bob" }, "start_time": "3 months ago", "consuming_hours": "1", "user": { "gravater": "91f376c4b36912e5075b6170d312eab5", "name": "Mike" }, "bar_width": "50.00%" } ], 'team': {'id':1, 'color': '2a33d8', 'name': 'Log'}, 'title': 'title2'}}, json.loads(rv.data)) task = Task.query.get(1) self.assertIsNone(task.partner) self.assertIsNone(task.owner) self.assertEquals('DONE', task.status) self.assertEquals(2, task.time_slots.count()) self.assertEquals(3600, task.time_slots[0].consuming) self.assertEquals('Mike', task.time_slots[0].user.name) self.assertIsNone(task.time_slots[0].partner) self.assertEquals(3600, task.time_slots[1].consuming) self.assertEquals('Mike', task.time_slots[1].user.name) self.assertEquals('Bob', task.time_slots[1].partner.name)
miami.init_db() team = Team('Log') team.members.append(User('yachuan.chen', email='*****@*****.**')) team.members.append(User('yue.zhang', email='*****@*****.**')) team.members.append(User('peng.yuan', email='*****@*****.**')) db.session.add(team) db.session.add(Category(u'功能')) db.session.add(Category('Bug')) db.session.add(Category('Test')) db.session.commit() task = Task('title1', 'detail', status='DONE', price=1, estimate=4, team=Team.query.get(1), start_time=miami.utils.get_last_monday().replace(hour=10), ready_time=miami.utils.get_last_monday().replace(hour=10)) ts = TimeSlot(miami.utils.get_last_monday().replace(hour=10), 7200, User.query.get(1)) task.time_slots.append(ts) task.categories.append(Category.query.get(1)) task.time_slots.append( TimeSlot(miami.utils.get_last_monday().replace(hour=14), 7200, User.query.get(1), partner=User.query.get(2))) db.session.add(task) db.session.commit()