def test_poll_howManyCandidates(self): title='test_poll_howManyCandidates- where is your favorite fishing spot?' description='test_poll_howManyCandidates- survey to find out the most favorite fishing spot in Perth' user=User.query.filter_by(userId=1).first() minResponses=5 #if not specified, the default value is -1 which will be ignored orderCandidatesBy=None #if not specified, the default value is alphabel acending 'Acs' isOpenPoll=None #if not specified, the default value is False openAt=None #if not specified, the default value is utcnow() closeAt=None # if not specified, the default value is today + 7 days poll=Poll(title, description, minResponses, orderCandidatesBy, isOpenPoll, openAt, closeAt, user) assert_that(poll.howManyCandidates()).is_equal_to(0) poll.addCandidate('test_poll_howManyCandidates- Narrows Bridge Perth',None) poll.addCandidate('test_poll_howManyCandidates- White Hills Mandurah',None) poll.addCandidate('test_poll_howManyCandidates- North Mole Fremantle',None) poll.addCandidate('test_poll_howManyCandidates- Floreat Drain Floreat',None) poll.addCandidate('test_poll_howManyCandidates- Ricey Beach And Radar Reef Rottnest Island',None) poll.addCandidate('test_poll_howManyCandidates- Lancelin Jetty Lancelin',None) assert_that(poll.howManyCandidates()).is_equal_to(6)
def archiveResponse(Poll, userId): if Poll != None: noResponses = Poll.howManyResponses() * Poll.howManyCandidates() for index in range(noResponses): if Poll.Response[index].userId == userId: Poll.Response[index].isActive = 0 try: db.session.add(Poll.Response[index]) db.session.commit() except: return False return True else: return False
def createPoll(Poll): if Poll == None: print('Poll object is empty') return False else: if Poll.validate(): try: db.session.add(Poll) db.session.commit() for index in range(Poll.howManyCandidates()): Poll.Candidate[index].pollId = Poll.get_id() try: db.session.add(Poll.Candidate[index]) db.session.commit() except: return 'create candidate exception raised: ' + str( sys.exc_info()[0]) return True except: return 'createPoll exception raised: ' + str(sys.exc_info()[0]) else: print('Mandatory data for a poll missing') return False