def test_extractShiftFromDict(self):
        control = models.Shift.query.first()
        stringJSON = shifts_controller.shiftToJSON(control)
        data = json.loads(stringJSON)
        target = shifts_controller.extractShiftFromDict(data)

        self.assertEqual(control.pk, target.pk)
        self.assertEqual(control.eventFK, target.eventFK)
        self.assertEqual(control.startdatetime, target.startdatetime)
        self.assertEqual(control.enddatetime, target.enddatetime)
        self.assertEqual(control.location, target.location)
        self.assertEqual(control.minWorkers, target.minWorkers)
        self.assertEqual(control.maxWorkers, target.maxWorkers)
def getShiftsByPersonJSON(personFK):
    list = _getShiftsByPerson(personFK)
    resultJSON = '{"Shifts":'
    counter = 0
    if list.count() > 0:
        resultJSON += '['
        for shiftPerson in list:
            shift = shifts_controller._getShiftByID(shiftPerson.shiftFK)
            shiftJSON = shifts_controller.shiftToJSON(shift)
            if counter > 0:
                resultJSON += ','
            resultJSON += shiftJSON
            counter += 1
        resultJSON += ']'
    else:
        resultJSON += '"None"'
    resultJSON += '}'
    return resultJSON
 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_shiftToJSON(self):
     control = models.Shift.query.first()
     controlJSON = shifts_controller.shiftToJSON(control)
     expectedJSON = stringJSON = '{"shift_pk":1,"shift_eventfk":1,"shift_start":"2013-07-12 12:00:00","shift_end":"2013-07-12 13:00:00","shift_location":"Booth A","shift_minworkers":2,"shift_maxworkers":4}'
     self.assertEqual(controlJSON, expectedJSON)