Ejemplo n.º 1
0
    def test_competition_json(self):
        company = CompanyModel('GOL')
        expected = {
            'id': company.id,
            'name': company.name,
        }

        self.assertEqual(
            company.json(), expected,
            "The JSON export of the company is incorrect. Received {}, expected {}."
            .format(company.json(), expected))
    def post(self, name):
        if CompanyModel.find_by_name(name):
            return {'message': "A store with name '{}' already exists.".format(name)}, 400

        company = CompanyModel(name)
        try:
            company.save_to_db()
        except:
            return {"message": "An error occurred creating the store."}, 500

        return company.json(), 201
Ejemplo n.º 3
0
    def post(self):
        data = self.parser.parse_args()
        companyName = data['companyName']
        if CompanyModel.find_by_name(companyName):
            return {
                'message':
                "An item with name '{}' already exists.".format(companyName)
            }, 400

        company = CompanyModel(companyName, **data)

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

        return company.json(), 201