Exemplo n.º 1
0
def feedback():
    form = UserFeedbackForm().validate_for_api()
    uid = g.user.uid
    create_time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
    title = form.title.data
    text = form.text.data
    Feedback.feedback(uid=uid, create_time=create_time, title=title, text=text)
    return SuccessViewModel.redict(dicts=[])
Exemplo n.º 2
0
 def feedback(self, pid):
     feedbacks = Feedback.query.all()
     for feedback in feedbacks:
         if str(feedback.pid) == pid:
             flash('感谢您的反馈,请待管理员处理。')
             return redirect(url_for('UserView:show_position', pid=pid))
     feedback = Feedback()
     feedback.fid = datetime.now().strftime('%y%m%d%f')[:10]
     feedback.uid = current_user.id
     feedback.pid = pid
     db.session.add(feedback)
     db.session.commit()
     flash('感谢您的反馈,请待管理员处理。')
     return redirect(url_for('UserView:show_position', pid=pid))
Exemplo n.º 3
0
    def test_client_check_feedback_with_token(self) -> None:
        """Test of checking feedback with the token"""
        feedback_data = {
            'email': '*****@*****.**',
            'title': 'This is the test title',
            'content': 'This is the test content',
            'response': 'The response content',
            'review_status_id': 2
        }
        db.session.add(Feedback(**feedback_data))
        db.session.commit()
        feedback_in_db = db.session.query(Feedback) \
            .filter_by(**feedback_data).first()

        # post token to check feedback
        token = feedback_in_db.token
        response = self.client.post('/check/', data={'token': token})

        status = ReviewStatus.query \
            .filter_by(id=feedback_data['review_status_id']).first()
        text = response.get_data(as_text=True)

        # assure the check page return the expected information
        self.assertTrue(response.status_code - 200 in range(0, 100),
                        ('wrong status code. Expect 2XX, '
                         f'got {response.status_code}'))
        self.assertTrue(feedback_data['email'] in text, 'email not found')
        self.assertTrue(feedback_data['title'] in text, 'title not found')
        self.assertTrue(feedback_data['content'] in text, 'content not found')
        self.assertTrue(feedback_data['response'] in text, 'wrong response')
        self.assertTrue(status.name in text, 'wrong review status')
Exemplo n.º 4
0
def index():
    """View of providing a feedback from the client side"""
    form = FeedbackForm()
    if form.validate_on_submit():
        try:
            data = {
                'email': form.email.data,
                'title': form.title.data,
                'content': form.content.data,
            }
            new_feedback = Feedback(**data)
            db.session.add(new_feedback)
            db.session.commit()

            committed_feedback = Feedback.query \
                .filter_by(**data).first()
            token = committed_feedback.token

            send_email(data['email'],
                       'Thank you for your feedback.',
                       'main/mail/new_feedback',
                       token=token)

            flash('Your Feedback is added Successfully')
            return render_template('/main/success.html', token=token)

        except SQLAlchemyError:
            flash('Failed to give a Feedback')

    return render_template('/main/index.html', form=form)
Exemplo n.º 5
0
 def test_token_is_unique(self) -> None:
     """Test of the uniqueness of the token"""
     email = '*****@*****.**'
     feedback = Feedback(email=email)
     db.session.add(feedback)
     db.session.commit()
     with self.assertRaises(IntegrityError):
         db.session.query(Feedback) \
             .filter_by(email=email) \
             .update({'token': self.test_feedback_in_db.token})
Exemplo n.º 6
0
 def test_id_auto_increment(self) -> None:
     """Test of id auto-incrementing"""
     old_id = self.test_feedback.id
     emails = [f'test{i}@email.com' for i in range(5)]
     feedbacks = [Feedback(email=email) for email in emails]
     for feedback in feedbacks:
         db.session.add(feedback)
         db.session.commit()
         new_id = db.session.query(Feedback) \
             .filter_by(email=feedback.email).first().id
         self.assertEqual(old_id + 1, new_id)
         old_id = new_id
Exemplo n.º 7
0
def submit():
    if request.method == 'POST':
        customer = request.form['customer']
        dealer = request.form['dealer']
        rating = request.form['rating']
        comments = request.form['comments']
        # print(customer, dealer, rating, comments)
        if customer == '' or dealer == '':
            return render_template('index.html', message='Please enter required fields')
        if db.session.query(Feedback).filter(Feedback.customer == customer).count() == 0:
            data = Feedback(customer, dealer, rating, comments)
            db.session.add(data)
            db.session.commit()
            send_mail(customer, dealer, rating, comments)
            return render_template('success.html')
        return render_template('index.html', message='You have already submitted feedback')
    def test_feedback_can_set_reference(self) -> None:
        """Test of setting reviewer for a feedback"""
        email = '*****@*****.**'
        feedback = Feedback(email=email,
                            reviewer_id=self.reviewer_in_db.id,
                            review_status_id=self.review_status_in_db.id)
        db.session.add(feedback)
        db.session.commit()
        feedback_in_db = db.session.query(Feedback)\
            .filter_by(email=email).first()

        self.assertEqual(feedback_in_db.reviewer_id, self.reviewer_in_db.id,
                         'fail to refer a reviewer for a feedback')

        self.assertEqual(feedback_in_db.review_status_id,
                         self.review_status_in_db.id,
                         'fail to refer a admin status for a feedback')
Exemplo n.º 9
0
    def setUp(self) -> None:
        self.app = create_app('testing')
        self.app_context = self.app.app_context()
        self.app_context.push()
        db.create_all()

        # create an Feedback for testing
        self.test_info = {
            'email': '*****@*****.**',
            'title': 'this is title',
            'content': u'this is content',
        }
        self.test_feedback = Feedback(**self.test_info)
        db.session.add(self.test_feedback)
        db.session.commit()
        self.test_feedback_in_db = db.session.query(Feedback) \
            .filter_by(email=self.test_feedback.email).first()
Exemplo n.º 10
0
 def test_check_feedback_with_wrong_token(self) -> None:
     """Test check feedback with wrong token"""
     feedback_data = {
         'email': '*****@*****.**',
         'title': 'This is the test title',
         'content': 'This is the test content',
         'response': 'The response content',
         'review_status_id': 2
     }
     db.session.add(Feedback(**feedback_data))
     db.session.commit()
     feedback_in_db = db.session.query(Feedback) \
         .filter_by(**feedback_data).first()
     token = feedback_in_db.token
     wrong_token = token[:-1]
     response = self.client.post('/check/', data={'token': wrong_token})
     self.assertEqual(200, response.status_code)
     text = response.get_data(as_text=True)
     self.assertTrue('Feedback not found.' in text,
                     'warning message not found')
Exemplo n.º 11
0
    def setUp(self) -> None:
        self.app = create_app('testing')
        self.app_context = self.app.app_context()
        self.app_context.push()
        db.create_all()
        Administrator.insert_administrator()
        ReviewStatus.insert_review_status()

        self.client = self.app.test_client(use_cookies=True)

        # create some feedbacks for testing
        self.test_info = [{
            'email': f'test{i}@email.com',
            'title': f'title{i}',
            'content': f'some content{i}',
        } for i in range(5)]

        for info in self.test_info:
            db.session.add(Feedback(**info))
            db.session.commit()
    def test_link_all_feedbacks(self) -> None:
        """Test of access all feedbacks reviewed by a administrator"""
        for _ in range(5):
            feedback = Feedback(reviewer_id=self.reviewer_in_db.id,
                                review_status_id=self.review_status_in_db.id)
            db.session.add(feedback)
            db.session.commit()

        feedback_ids_in_db = [f.id for f in db.session.query(Feedback).all()]

        related_feedback_ids = [f.id for f in self.reviewer_in_db.feedbacks]
        self.assertEqual(
            set(feedback_ids_in_db), set(related_feedback_ids),
            'the related feedbacks not correct for a administrator')

        related_feedback_ids = [
            f.id for f in self.review_status_in_db.feedbacks
        ]
        self.assertEqual(
            set(feedback_ids_in_db), set(related_feedback_ids),
            'the related feedbacks not correct for a admin status')
Exemplo n.º 13
0
 def test_title_len_limit(self) -> None:
     """Test of title length restriction"""
     title = 'n' * 129
     with self.assertRaises(ValueError):
         Feedback(title=title)
Exemplo n.º 14
0
 def test_email_len_limit(self) -> None:
     """Test of email length restriction"""
     email = '*****@*****.**' + 'n' * 64
     with self.assertRaises(ValueError):
         Feedback(email=email)
Exemplo n.º 15
0
 def test_id_is_unique(self) -> None:
     """Test of id uniqueness"""
     same_id = Feedback(id=self.test_feedback_in_db.id)
     db.session.add(same_id)
     with self.assertRaises(FlushError):
         db.session.commit()