def test_fetch_complaint_by_service_return_many(notify_db_session): service_1 = create_service(service_name='first') service_2 = create_service(service_name='second') template_1 = create_template(service=service_1, template_type='email') template_2 = create_template(service=service_2, template_type='email') notification_1 = create_notification(template=template_1) notification_2 = create_notification(template=template_2) notification_3 = create_notification(template=template_2) complaint_1 = Complaint(notification_id=notification_1.id, service_id=service_1.id, ses_feedback_id=str(uuid.uuid4()), complaint_type='abuse', complaint_date=datetime.utcnow()) complaint_2 = Complaint(notification_id=notification_2.id, service_id=service_2.id, ses_feedback_id=str(uuid.uuid4()), complaint_type='abuse', complaint_date=datetime.utcnow()) complaint_3 = Complaint(notification_id=notification_3.id, service_id=service_2.id, ses_feedback_id=str(uuid.uuid4()), complaint_type='abuse', complaint_date=datetime.utcnow(), created_at=datetime.utcnow() + timedelta(minutes=1)) save_complaint(complaint_1) save_complaint(complaint_2) save_complaint(complaint_3) complaints = fetch_complaints_by_service(service_id=service_2.id) assert len(complaints) == 2 assert complaints[0] == complaint_3 assert complaints[1] == complaint_2
def complaint_add_post(): complaint = Complaint( complainttype=request.form.get('add_complainttype'), house_houseid=request.form.get('add_houseid'), complaintdetail=request.form.get('add_complaintdetail')) complaint.complainttime = datetime.strptime( datetime.now().strftime('%Y-%m-%d %H:%M:%S'), '%Y-%m-%d %H:%M:%S') db.session.add(complaint) db.session.commit() return redirect(url_for('community.complaint'))
def handle_complaint(ses_message): recipient_email = remove_emails_from_complaint(ses_message)[0] current_app.logger.info("Complaint from SES: \n{}".format(ses_message)) try: reference = ses_message['mail']['messageId'] except KeyError as e: current_app.logger.exception( "Complaint from SES failed to get reference from message", e) return notification = dao_get_notification_history_by_reference(reference) ses_complaint = ses_message.get('complaint', None) complaint = Complaint( notification_id=notification.id, service_id=notification.service_id, # TODO: this ID is unique, we should make it a unique index so we don't # store duplicate complaints. # See https://docs.aws.amazon.com/ses/latest/DeveloperGuide/notification-contents.html#complaint-object ses_feedback_id=ses_complaint.get('feedbackId', None) if ses_complaint else None, complaint_type=ses_complaint.get('complaintFeedbackType', None) if ses_complaint else None, complaint_date=ses_complaint.get('timestamp', None) if ses_complaint else None) save_complaint(complaint) return complaint, notification, recipient_email
def handle_complaint(ses_message): recipient_email = remove_emails_from_complaint(ses_message)[0] current_app.logger.info("Complaint from SES: \n{}".format( json.dumps(ses_message).replace("{", "(").replace("}", ")"))) try: reference = ses_message["mail"]["messageId"] except KeyError as e: current_app.logger.exception( "Complaint from SES failed to get reference from message", e) return notification = dao_get_notification_history_by_reference(reference) ses_complaint = ses_message.get("complaint", None) complaint = Complaint( notification_id=notification.id, service_id=notification.service_id, ses_feedback_id=ses_complaint.get("feedbackId", None) if ses_complaint else None, complaint_type=ses_complaint.get("complaintFeedbackType", None) if ses_complaint else None, complaint_date=ses_complaint.get("timestamp", None) if ses_complaint else None, ) save_complaint(complaint) return complaint, notification, recipient_email
def handle_ses_complaint( ses_message: dict) -> Tuple[Complaint, Notification, str]: recipient_email = remove_emails_from_complaint(ses_message)[0] current_app.logger.info("Complaint from SES: \n{}".format( json.dumps(ses_message).replace('{', '(').replace('}', ')'))) try: reference = ses_message['mail']['messageId'] except KeyError as e: current_app.logger.exception( "Complaint from SES failed to get reference from message", e) return notification = dao_get_notification_history_by_reference(reference) ses_complaint = ses_message.get('complaint', None) complaint_type = ses_complaint.get('complaintFeedbackType', None) if ses_complaint else None if not complaint_type: current_app.logger.info( f'Received null complaint type from SES for notification {notification.id}' ) complaint = Complaint(notification_id=notification.id, service_id=notification.service_id, feedback_id=ses_complaint.get('feedbackId', None) if ses_complaint else None, complaint_type=complaint_type, complaint_date=ses_complaint.get('timestamp', None) if ses_complaint else None) save_complaint(complaint) return complaint, notification, recipient_email
def complaint(request): if 'username' in request.session and request.session['username'] is not None: if request.method == 'POST': try: description = request.POST['description'] type = request.POST['type'] except e: return redirect('/failure') c = Complaint(user=User.objects.filter(username=request.session['username']).first(), description=description, type=type) try: c.save() except e: return redirect('/failure') return redirect('/success') return render(request, 'app/complaint.html') else: return redirect('/')
def savecomplaint(request): name = request.POST.get('u_name') block_name = request.POST.get('bn') flat_type = request.POST.get('ft') flat_no = request.POST.get('fno') email = request.POST.get('u_email') date = request.POST.get('u_date') complaint = request.POST.get('u_com') print(name, block_name, flat_no, flat_type, email, date, complaint) cp = Complaint(name=name, flat_no=flat_no, date=date, complaint=complaint, email=email, flat_type=flat_type, block_name=block_name) cp.save() res = UserRegister.objects.get(flat_no=flat_no) return render(request, 'userhome.html', {'res': res})
def test_fetch_complaint_by_service_returns_one(sample_service, sample_email_notification): complaint = Complaint(notification_id=sample_email_notification.id, service_id=sample_service.id, ses_feedback_id=str(uuid.uuid4()), complaint_type='abuse', complaint_date=datetime.utcnow()) save_complaint(complaint) complaints = fetch_complaints_by_service(service_id=sample_service.id) assert len(complaints) == 1 assert complaints[0] == complaint
def create_complaint(service=None, notification=None, created_at=None): if not service: service = create_service() if not notification: template = create_template(service=service, template_type='email') notification = create_notification(template=template) complaint = Complaint( notification_id=notification.id, service_id=service.id, ses_feedback_id=str(uuid.uuid4()), complaint_type='abuse', complaint_date=datetime.utcnow(), created_at=created_at if created_at else datetime.now()) db.session.add(complaint) db.session.commit() return complaint
def new_complaint(): form = ComplaintForm() if form.validate_on_submit(): complaint = Complaint( agreement_no=form.agreement_no.data, manufacturer=form.manufacturer.data, model=form.model.data, product=form.product.data, vehicle_age=form.vehicle_age.data, centre=form.centre.data, title=form.title.data, first_name=form.first_name.data, middle_name=form.middle_name.data, last_name=form.last_name.data, email=form.email.data, contact_no=form.contact_no.data, id=form.complaint_no.data, complaint_group=form.complaint_group.data, complaint_source=form.complaint_source.data, complaint_narrative=form.complaint_narrative.data, complaint_status=form.complaint_status.data, severity=form.severity.data, date_received=form.date_received.data, reg_due_date=form.reg_due_date.data, date_modified=None, date_escalated=None, date_acknowledged=None, # company_outcome='', # regulatory_outcome='', # regulatory_reportable='', # goodwill_offered='', # goodwill_method='', # goodwill_reason='', # goodwill_amount='', adviser=current_user) db.session.add(complaint) db.session.commit() flash(f'Complaint no {form.complaint_no.data} saved successfully!', 'success') return redirect(url_for('home')) return render_template('create_complaint.html', title='New Complaint', form=form)
def handle_complaint(ses_message): recipient_email = remove_emails_from_complaint(ses_message)[0] current_app.logger.info("Complaint from SES: \n{}".format(ses_message)) try: reference = ses_message['mail']['messageId'] except KeyError as e: current_app.logger.exception( "Complaint from SES failed to get reference from message", e) return notification = dao_get_notification_history_by_reference(reference) ses_complaint = ses_message.get('complaint', None) complaint = Complaint( notification_id=notification.id, service_id=notification.service_id, ses_feedback_id=ses_complaint.get('feedbackId', None) if ses_complaint else None, complaint_type=ses_complaint.get('complaintFeedbackType', None) if ses_complaint else None, complaint_date=ses_complaint.get('timestamp', None) if ses_complaint else None) save_complaint(complaint) return complaint, notification, recipient_email
def create_complaint(): raw_complaint = request.get_json(True) hex_id = None if 'hexagon' in raw_complaint and raw_complaint['hexagon']: raw_hex = raw_complaint['hexagon'] hex_id = Hexagon.query.filter( Hexagon.selector == raw_hex['selector'], Hexagon.categ_id == Categ.query.filter_by( name=raw_hex['categ']).first_or_404().id).first().id if not hex_id and not 'to' in raw_complaint: return json.dumps({'success': False, 'message': _('No such hexagon')}) complaint = Complaint( body=raw_complaint['text'], hex_id=hex_id, user_id=current_user.id, to=raw_complaint['to'] if 'to' in raw_complaint else '') db.session.add(complaint) db.session.commit() return json.dumps({'success': True})
def test_create_complaint_should_return_complaint_with_correct_info( mocker, notify_api): request = get_govdelivery_request('1111', 'blacklisted') test_email = '*****@*****.**' mocker.patch( 'app.notifications.notifications_govdelivery_callback.save_complaint') test_notification = Notification(id=uuid.uuid4(), to=test_email, service_id=uuid.uuid4()) expected_complaint = Complaint(notification_id=test_notification.id, service_id=test_notification.service_id, feedback_id=request['sid'], complaint_type=request['message_type'], complaint_date=parser.parse( request['completed_at'])) with notify_api.app_context(): complaint = create_complaint(request, test_notification) assert_complaints_are_equal(expected_complaint, complaint)
def create(self, data): complaint = Complaint(user_id=data['user_id']) complaint.complaint_body = data['complaint_body'] complaint.expected_solution_body = data['expected_solution_body'] complaint.complain_type = data['complain_type'] complaint.if_negotiated_by_merchant = data['if_negotiated_by_merchant'] if 'negotiate_timestamp' in data: complaint.negotiate_timestamp = parser.parse( data['negotiate_timestamp']) complaint.allow_public = data['allow_public'] complaint.allow_contact_by_merchant = data['allow_contact_by_merchant'] complaint.allow_press = data['allow_press'] complaint.item_price = data['item_price'] complaint.item_model = data['item_model'] complaint.relatedProducts = data['relatedProducts'] complaint.purchase_timestamp = parser.parse(data['purchase_timestamp']) if 'invoice_files' in data: complaint.invoce_files = json.dumps(data['invoice_files']) if 'id_files' in data: complaint.invoce_files = json.dumps(data['id_files']) db.session.add(complaint) db.session.commit() return "OK"