def post(self): """ POST Method for Continents. Login required :return: JSON response """ try: self.validate_fields(Continent.required_fields(), request.form) except ValueError: return self.response(400, 'Required fields: ' + ' '.join(Continent.required_fields())) params = self.get_form_values(Continent.get_columns(), request.form) validate = Continent.query.filter_by(code=params['code']).first() if validate: self.response(400, "The code already exists") new_continent = Continent( code=params['code'], name=params['name'] ) new_continent.save() return self.response(201)
def test_01_contintent_new(self): new_continent = Continent(code=self.continent['code'], name=self.continent['name']) new_continent.save() self.assertEqual(new_continent.code, self.continent['code'], "New Continent code") self.assertEqual(new_continent.name, self.continent['name'], "New Contientnt name")