def getResolve(self, complaint_number): complaint_number = str(complaint_number) info = {} if exists(p for p in Complaint if p.complaint_number == complaint_number): obj = Complaint.get(complaint_number=complaint_number) info = self.__resolveDataPacker(obj) return info
def get(self, c_id): complaint = Complaint.get(c_id) if complaint is None: return {"success": False, "error": "404 Not found"} complaint_json = {} complaint_json['id'] = complaint.id complaint_json['text'] = complaint.text complaint_json['timestamp'] = '{:%Y-%m-%d %H:%M:%S}'.format( complaint.timestamp) complaint_json['status'] = complaint.status result = {} result['complaint'] = complaint_json result['comments'] = [] comments = complaint.get_comments() for comment in comments: comment_json = {} comment_json['id'] = comment.id comment_json['text'] = comment.text comment_json['timestamp'] = '{:%Y-%m-%d %H:%M:%S}'.format( comment.timestamp) comment_json['by'] = comment.by result['comments'].append(comment_json) result['success'] = True return result
def post(self, c_id): args = request.get_json() if ('status' not in args): return {'success': False, 'error': "invalid input"} status = args['status'] complaint = Complaint.get(c_id) if complaint is None: return {"success": False, "error": "404 Not found"} if (complaint.get_status() != 'waiting'): return { "success": False, "error": "The complaint status is already set" } try: complaint.set_status(status) except ValueError as e: return {"success": False, "error": "Invalid Status"} complainant = complaint.get_complainant() prev_comment = complaint.get_latest_comment() prev_post_id = complaint.id if prev_comment is None else prev_comment.id twitter_api.update_status( '@' + complainant.account_handle + '! Your complaint has been ' + status + '. Thanks for registering your complaint.', prev_post_id) return {"success": True, "error": False}
def post(self, c_id): args = request.get_json() if ('text' not in args): return {'success': False, 'error': "invalid input"} complaint = Complaint.get(c_id) if (complaint is None): return {'success': False, 'error': "complaint not found"} complainant = complaint.get_complainant() prev_comment = complaint.get_latest_comment() comment_text = args['text'] prev_post_id = complaint.id if prev_comment is None else prev_comment.id s = twitter_api.update_status( '@' + complainant.account_handle + '!\n' + comment_text, prev_post_id) comment_id = s.id comment = Comment.create_comment(complaint, prev_comment, id=str(comment_id), text=comment_text, timestamp=datetime.datetime.now(), by='admin') comment.save() complaint.latest_comment_id = comment.id complaint.save() return {'success': True}
def test_comment(self): comment_text = "Hey Bro!" rv = self.comment(self.complaint.id, comment_text) j = self.dejsonify(rv.data) self.assertEqual(j['success'], False) self.login(self.supervisor.email, self.supervisor.password) rv = self.comment("randomid", comment_text) j = self.dejsonify(rv.data) self.assertEqual(j['success'], False) rv = self.comment(self.complaint.id, comment_text) j = self.dejsonify(rv.data) self.assertEqual(j['success'], True) self.complaint = Complaint.get(self.complaint.id) latest_comment = self.complaint.get_latest_comment() self.assertEqual(comment_text, latest_comment.text)