def post_test_lead(cls): appeal = AppealModel('Test Title', 'title.url') appeal.save_to_db() lead = LeadModel('*****@*****.**', '1111222233', 'Test', 'Tester', appeal.id) lead.save_to_db() return lead
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
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()
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
def get(self, id): lead = LeadModel.find_by_id(id) if lead: return lead.json() return {'message': 'There is no lead with this email'}, 404
def delete(self, id): lead = LeadModel.find_by_id(id) if lead: try: lead.delete_from_db() return {'message': 'Lead deleted'} except Exception: return {'message': 'Error deleting a lead'}, 500 return {'message': 'There is no lead with this email'}, 404
def put(self, id): lead = LeadModel.find_by_id(id) if lead: data = self.parser.parse_args() for attribute, value in data.items(): if value: setattr(lead, attribute, value) try: lead.save_to_db() except Exception: return {'message': 'An error occured updating a lead'}, 500 return lead.json() return {'message': 'There is no lead with this id'}, 404
def post(self): data = self.parser.parse_args() if LeadModel.find_by_email(data['email']): return {'message': 'There is already a lead with this email'} lead = LeadModel(**data) try: lead.save_to_db() except Exception: return {'message': 'An error occured inserting a lead'}, 500 return lead.json()