Exemplo n.º 1
0
    def test_update_vendor_rating_ok_response(
            self, mock_auth_user, mock_vendor_rating_controller_get_json,
            mock_vendor_rating_repo_get, mock_vendor_rating_repo_update):
        '''Test update_vendor_rating when rating is forbidden.
        '''
        # Arrange
        with self.app.app_context():
            mock_auth_user.return_value = 1
            mock_vendor_rating_controller_get_json.return_value = {
                'comment': 'Mock comment'
            }
            mock_vendor_rating = VendorRating(id=1,
                                              created_at=datetime.now(),
                                              updated_at=datetime.now(),
                                              vendor_id=1,
                                              user_id=1,
                                              comment='Mock comment',
                                              service_date=datetime.now(),
                                              rating=3.0,
                                              channel='web',
                                              rating_type='meal',
                                              type_id=1,
                                              engagement_id=1,
                                              main_meal_id=1)
            mock_vendor_rating_repo_get.return_value = mock_vendor_rating
            mock_vendor_rating_repo_update.return_value = mock_vendor_rating
            vendor_rating_controller = VendorRatingController(
                self.request_context)

            # Act
            result = vendor_rating_controller.update_vendor_rating(1)

            # Assert
            assert result.status_code == 200
            assert result.get_json()['msg'] == 'OK'
    def test_update_vendor_rating_when_rating_is_invalid(
        self,
        mock_vendor_rating_repo_get,
        mock_vendor_rating_controller_get_json
    ):
        '''Test update_vendor_rating when rating is invalid.
        '''
        # Arrange
        with self.app.app_context():
            mock_rating_id = 1
            mock_vendor_rating_controller_get_json.return_value = {
                'comment': 'Mock comment'
            }
            mock_vendor_rating_repo_get.return_value = None
            vendor_rating_controller = VendorRatingController(
                self.request_context
            )

            # Act
            result = vendor_rating_controller.update_vendor_rating(
                mock_rating_id
            )

            # Assert
            assert result.status_code == 404
            assert result.get_json()['msg'] == 'Invalid or incorrect ' \
                'rating_id provided'