def _insertShiftPerson(shiftPerson, db):
    result = 'Unknown'
    isDup = _isDuplicateAssignment(shiftPerson)
    shift = shifts_controller._getShiftByID(shiftPerson.shiftFK)
    if shift is None:
        result = 'BadShift'
    person = models.Person.query.filter_by(entityFK=shiftPerson.personFK).first()
    if person is None:
        result = 'BadPerson'
    if(isDup == False and result == 'Unknown'):
        db.session.add(shiftPerson)
        db.session.commit()
        if(shiftPerson.pk > 0):
            result = shiftPerson.pk
    if(result == 'Unknown'):
        result = 'Duplicate'
    return result
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__getShiftByID_false(self):
     key = 9999
     shift = shifts_controller._getShiftByID(key)
     self.assertIsNone(shift)
 def test__getShiftByID_true(self):
     key = 1
     shift = shifts_controller._getShiftByID(key)
     self.assertIsNotNone(shift)
     control = models.Shift.query.filter_by(pk=shift.pk).first()
     self.assertEqual(shift.__repr__(), control.__repr__())