Example #1
0
 def test_put_with_existing_id_status(self):
     data = {'username': '******', 'email': 'updated'}
     operator = OperatorModel('old', 'old', 'old', 'old')
     operator.save_to_db()
     _id = operator.json()['id']
     response = self.client.put("/operators/{}".format(_id), data=data)
     self.assertEquals(response.status_code, 200)
Example #2
0
def create_lead_and_operator():
    appeal = AppealModel('title', 'url')
    appeal.save_to_db()

    lead = LeadModel('email', 'phone', 'name', 'surname', appeal.id)
    lead.save_to_db()

    operator = OperatorModel('testuser', 'name', 'surname', 'email')
    operator.save_to_db()

    return lead, operator
Example #3
0
def create_call():
    appeal = AppealModel('title', 'url')
    appeal.save_to_db()

    lead = LeadModel('email', 'phone', 'name', 'surname', appeal.id)
    lead.save_to_db()

    operator = OperatorModel('testuser', 'name', 'surname', 'email')
    operator.save_to_db()

    call = CallModel('04-12-2020', '03::04::05', 5.4, lead.id, operator.id)
    call.save_to_db()
Example #4
0
def create_donation():
    appeal = AppealModel('title', 'url')
    appeal.save_to_db()

    lead = LeadModel('email', 'phone', 'name', 'surname', appeal.id)
    lead.save_to_db()

    operator = OperatorModel('testuser', 'name', 'surname', 'email')
    operator.save_to_db()

    donation = DonationModel('Annual', 30.00, lead.id, operator.id)
    donation.save_to_db()
    return donation
Example #5
0
    def get(self, id):
        operator = OperatorModel.find_by_id(id)

        if operator:
            return operator.json()

        return {'message': "There is no operator with given id"}, 404
Example #6
0
    def delete(self, id):
        operator = OperatorModel.find_by_id(id)

        if operator:
            operator.delete_from_db()
            return {'message': 'Operator deleted'}

        return {'message': 'There is no operator with this id'}, 404
Example #7
0
    def put(self, id):
        operator = OperatorModel.find_by_id(id)

        if operator:
            data = self.parser.parse_args()

            for attribute, value in data.items():
                if value:
                    setattr(operator, attribute, value)

            try:
                operator.save_to_db()
            except Exception:
                return {'message': 'An error occured inserting an operator'}, \
                        500

            return operator.json()

        return {'message': 'There is no operator with this id'}, 404
Example #8
0
    def post(self):
        data = self.parser.parse_args()

        if OperatorModel.find_by_username(data['username']):
            return {'message': 'Username already exists'}

        operator = OperatorModel(**data)

        try:
            operator.save_to_db()
        except Exception:
            return {'message': 'An error occured inserting an operator'}, 500

        return operator.json()
Example #9
0
 def create_operator(self):
     operator = OperatorModel('bobcat', 'Bob', 'Cat', '*****@*****.**')
     operator.save_to_db()
     return operator