def test_insertShift_badevent(self):
     eventFK = 99999
     start = datetime.datetime(2013, 7, 24, 13, 0)
     end = datetime.datetime(2013, 7, 24, 14, 0)
     location = 'Booth B'
     minWorkers = 24
     maxWorkers = 42
     
     shiftJSON = '{'
     shiftJSON += '"{key}":"{val}",'.format(key=models.SHIFT_START_KEY, val=start)
     shiftJSON += '"{key}":"{val}",'.format(key=models.SHIFT_END_KEY, val=end)
     shiftJSON += '"{key}":"{val}",'.format(key=models.SHIFT_LOCATION_KEY, val=location)
     shiftJSON += '"{key}":{val},'.format(key=models.SHIFT_MINWORKERS_KEY, val=minWorkers)
     shiftJSON += '"{key}":{val}'.format(key=models.SHIFT_MAXWORKERS_KEY, val=maxWorkers)
     shiftJSON += '}'
     shiftDict = json.loads(shiftJSON)
     
     result = shifts_controller.insertShift(eventFK, shiftDict, self.db)
     resultDict = json.loads(result)
     for key,value in resultDict.iteritems():
         if key == 'success':
             self.assertEqual(value, 'false')
         if key == 'msg':
             self.assertEqual(value, 'BadEvent')
         elif key == 'shift_pk':
             self.assertEqual(value, 'None')        
 def test_insertShift_duplicate(self):
     shift1 = models.Shift.query.first()
     
     shift2 = models.Shift()
     shift2.startdatetime = shift1.startdatetime
     shift2.enddatetime = shift1.enddatetime
     shift2.location=shift1.location
     shiftJSON = shifts_controller.shiftToJSON(shift2)
     shiftDict = json.loads(shiftJSON)
     
     result = shifts_controller.insertShift(shift1.eventFK, shiftDict, self.db)
     resultDict = json.loads(result)
     for key,value in resultDict.iteritems():
         if key == 'success':
             self.assertEqual(value, 'false')
         if key == 'msg':
             self.assertEqual(value, 'Duplicate')
         elif key == 'shift_pk':
             self.assertEqual(value, 'None')
 def test_insertShift_true(self):
     eventFK = 1
     start = datetime.datetime(2013, 7, 24, 13, 0)
     end = datetime.datetime(2013, 7, 24, 14, 0)
     location = 'Booth C'
     minWorkers = 24
     maxWorkers = 42
     
     shiftJSON = '{'
     shiftJSON += '"{key}":"{val}",'.format(key=models.SHIFT_START_KEY, val=start)
     shiftJSON += '"{key}":"{val}",'.format(key=models.SHIFT_END_KEY, val=end)
     shiftJSON += '"{key}":"{val}",'.format(key=models.SHIFT_LOCATION_KEY, val=location)
     shiftJSON += '"{key}":{val},'.format(key=models.SHIFT_MINWORKERS_KEY, val=minWorkers)
     shiftJSON += '"{key}":{val}'.format(key=models.SHIFT_MAXWORKERS_KEY, val=maxWorkers)
     shiftJSON += '}'
     shiftDict = json.loads(shiftJSON)
     
     result = shifts_controller.insertShift(eventFK, shiftDict, self.db)
     self.assertIsNotNone(result)
     newKey = 0
     resultDict = json.loads(result)
     for key,value in resultDict.iteritems():
         if key == 'success':
             self.assertEqual(value, 'true')
         if key == models.SHIFT_PK_KEY:
             self.assertTrue(value > 0)
             newKey = value
     
     newShift = models.Shift.query.filter_by(pk=newKey).first()
     self.assertEqual(newShift.pk, newKey)
     self.assertEqual(newShift.eventFK, eventFK)
     self.assertEqual(newShift.startdatetime, start)
     self.assertEqual(newShift.enddatetime, end)
     self.assertEqual(newShift.location, location)
     self.assertEqual(newShift.minWorkers, minWorkers)
     self.assertEqual(newShift.maxWorkers, maxWorkers)
示例#4
0
def createShiftForEvent(org_id, event_id):
    try:
        result = shifts_controller.insertShift(event_id, request.json, db)
        return Response(response=result, mimetype='application/json')
    except Exception, e:
        return abort(404)