Ejemplo n.º 1
0
    def test_competition_relationship(self):
        with self.app_context():
            competition = CompetitionModel('test_competition', False, 1)
            entry = EntryModel('test', 19.99, 'm', 1)

            competition.save_to_db()
            entry.save_to_db()

            self.assertEqual(entry.competition.competicao, 'test_competition')
    def test_competition_relationship(self):
        with self.app_context():
            competition = CompetitionModel('test', False, 1)
            entry = EntryModel('test_entry', 19.99, 'm', 1)

            competition.save_to_db()
            entry.save_to_db()

            self.assertIsNotNone(competition.entrys[0])
            self.assertEqual(competition.entrys[0].atleta, 'test_entry')
    def put(self, name):
        data = Competition.parser.parse_args()
        competition = CompetitionModel.find_by_name(name)

        if competition:
            competition.name = name
            competition.isFinished = data['isFinished']
            competition.numTrys = data['numTrys']
        else:
            competition = CompetitionModel(name, data['isFinished'],
                                           data['numTrys'])

        competition.save_to_db()

        return competition.json()
    def post(self, name):
        if CompetitionModel.find_by_name(name):
            return {
                'message':
                "An competition with name '{}' already exists.".format(name)
            }, 500

        data = Competition.parser.parse_args()
        competition = CompetitionModel(name, 0, data['numTrys'])

        try:
            competition.save_to_db()
        except:
            return {
                "message": "An error occurred inserting the competition."
            }, 500

        return competition.json(), 201
    def test_crud(self):
        with self.app_context():
            competition = CompetitionModel('test', False, 1)

            self.assertIsNone(
                CompetitionModel.find_by_name('test'),
                "Found an competition with name 'test' before save_to_db")

            competition.save_to_db()

            self.assertIsNotNone(
                CompetitionModel.find_by_name('test'),
                "Did not find a competition with name 'test' after save_to_db")

            competition.delete_from_db()

            self.assertIsNone(
                CompetitionModel.find_by_name('test'),
                "Found an competition with name 'test' after delete_from_db")
Ejemplo n.º 6
0
    def test_crud(self):
        with self.app_context():
            competition = CompetitionModel('test', False, 1)
            competition.save_to_db()
            entry = EntryModel('test', 19.99, 'm', 1)

            self.assertIsNone(EntryModel.find_by_name('test').first(), "Found an entry with name 'test' before save_to_db")

            self.assertEqual(EntryModel.find_athlete_tries(1, 'test'), 0, "The number of tries for the athelte 'test' before save_to_db was not 0")


            entry.save_to_db()

            self.assertIsNotNone(EntryModel.find_by_name('test'),
                                 "Did not find an entry with name 'test' after save_to_db")

            self.assertEqual(EntryModel.find_athlete_tries(1, 'test'), 1, "The number of tries for the athelte 'test' after save_to_db was not 1")

            entry.delete_from_db()

            self.assertIsNone(EntryModel.find_by_name('test').first(), "Found an entry with name 'test' after delete_from_db")