def post(self, name): _entry = EntryModel.find_by_name(name) competition = CompetitionModel.find_by_name(name) if competition: if competition.isFinished: return {'message': "The competition '{}' is Finished! Can not accept more entries!".format(name)} competition_num_tries = competition.numTrys else: return {'message': "The competition '{}' doesen't exists.".format(name)} data = Entry.parser.parse_args() competition_id = CompetitionModel.find_competition_id(name) athlete_num_tries = EntryModel.find_athlete_tries(competition_id, data['atleta']) if _entry and athlete_num_tries and athlete_num_tries >= competition_num_tries: return {'message': "{} has reached the maximum number of attempts in {} competition.".format(data['atleta'], name)}, 500 competition = CompetitionModel.find_by_name(name) entry = EntryModel(data['atleta'], data['value'], data['unidade'], competition.id) try: entry.save_to_db() except: return {"message": "An error occurred inserting the entry."}, 500 return entry.json(), 201
def post(self, user_id): entry = EntryModel(user_id) try: entry.save_to_db() except: return {'message': 'An error occurred while creating the store.'}, 500 return entry.json(), 201
def test_entry_json(self): entry = EntryModel('test', 19.99, 'm', 1) expected = { 'atleta': 'test', 'value': 19.99, 'unidade': 'm' } self.assertEqual( entry.json(), expected, "The JSON export of the entry is incorrect. Received {}, expected {}.".format(entry.json(), expected))