Esempio n. 1
0
	def new_rating(self, vendor_id, user_id, rating, rating_type, type_id, engagement_id, channel, comment=''):
		vendor_rating = VendorRating(
			vendor_id=vendor_id, user_id=user_id,
			rating=rating, channel=channel, comment=comment,
			rating_type=rating_type, type_id=type_id,
			engagement_id=engagement_id
		)
		vendor_rating.save()
		return vendor_rating
Esempio n. 2
0
    def test_list_ratings_with_missing_main_meal_id_succeeds(
            self, mock_vendor_rating_repo_meal_average,
            mock_meal_item_repo_get, mock_vendor_repo_get,
            mock_vendor_rating_repo_filter_by,
            mock_vendor_rating_controler_get_params_dict):
        '''Test list_ratings OK response.
        '''
        # Arrange
        with self.app.app_context():
            mock_vendor_rating_1 = VendorRating(vendor_id=1,
                                                user_id=1,
                                                comment='Mock comment',
                                                service_date=datetime.now(),
                                                rating=1.0,
                                                channel='Mock channel',
                                                rating_type='engagement',
                                                type_id=0,
                                                engagement_id=1,
                                                id=1,
                                                created_at=datetime.now(),
                                                updated_at=datetime.now(),
                                                main_meal_id=1)
            mock_vendor_rating_2 = VendorRating(vendor_id=1,
                                                user_id=1,
                                                comment='Mock comment',
                                                service_date=datetime.now(),
                                                rating=1.0,
                                                channel='Mock channel',
                                                rating_type='engagement',
                                                type_id=0,
                                                engagement_id=1,
                                                id=1,
                                                created_at=datetime.now(),
                                                updated_at=datetime.now(),
                                                main_meal_id=None)

            mock_vendor_rating_repo_filter_by.return_value.items = [
                mock_vendor_rating_1, mock_vendor_rating_2
            ]
            mock_vendor_rating_controler_get_params_dict.return_value = {}
            mock_vendor_repo_get.return_value.name = 'Mock vender'
            mock_meal_item_repo_get.return_value.name = 'Mock meal name'
            mock_vendor_rating_repo_meal_average.return_value = 2.0
            vendor_rating_controller = VendorRatingController(
                self.request_context)

            # Act
            result = vendor_rating_controller.list_ratings('2019-02-06')

            # Assert
            assert result.status_code == 200
            assert result.get_json()['msg'] == 'OK'
            assert len(result.get_json()['payload']['result'][0]['items']) == 1
Esempio n. 3
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'
Esempio n. 4
0
    def test_get_vendor_rating_ok_response(self, mock_vendor_rating_repo_get):
        '''Test get_vendor_rating OK response.
        '''
        # Arrange
        with self.app.app_context():
            mock_vendor_rating = VendorRating(vendor_id=1,
                                              user_id=1,
                                              comment='Mock comment',
                                              service_date=datetime.now(),
                                              rating=1.0,
                                              channel='Mock channel',
                                              rating_type='engagement',
                                              type_id=0,
                                              engagement_id=1,
                                              id=1,
                                              created_at=datetime.now(),
                                              updated_at=datetime.now(),
                                              main_meal_id=1)
            mock_vendor_rating_repo_get.return_value = mock_vendor_rating
            vendor_rating_controller = VendorRatingController(
                self.request_context)

            # Act
            result = vendor_rating_controller.get_vendor_rating(1)

            # Assert
            assert result.status_code == 200
            assert result.get_json()['msg'] == 'OK'
Esempio n. 5
0
    def test_create_order_rating_when_meal_already_rated(
            self, mock_vendor_engagement_repo_get, mock_meal_item_repo_get,
            mock_auth_user, mock_vendor_rating_controller_request_params,
            mock_vendor_rating_repo_get_unpaginated):
        '''Test create_order_rating when order has already been rated.
        '''
        # Arrange
        with self.app.app_context():
            mock_meal_item = MealItem(id=1,
                                      created_at=datetime.now(),
                                      updated_at=datetime.now(),
                                      meal_type='main',
                                      name='Mock meal',
                                      image='',
                                      location_id=1)
            mock_vendor_engagement = VendorEngagement(
                id=1,
                created_at=datetime.now(),
                updated_at=datetime.now(),
                vendor_id=1,
                location_id=1,
                start_date=datetime.now(),
                end_date=(datetime.now() + timedelta(days=5)),
                status=1,
                termination_reason='Mock reason')
            mock_vendor_rating = VendorRating(id=1,
                                              created_at=datetime.now(),
                                              updated_at=datetime.now(),
                                              vendor_id=1,
                                              user_id='user_id',
                                              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)
            service_date = datetime.strftime(
                (datetime.now() - timedelta(1)).date(), '%Y-%m-%d')
            mock_vendor_rating_controller_request_params.return_value = (
                None, None, None, None, 3, service_date, None)
            mock_auth_user.return_value = 1
            mock_meal_item_repo_get.return_value = mock_meal_item
            mock_vendor_engagement_repo_get.return_value = \
                mock_vendor_engagement
            mock_vendor_rating_repo_get_unpaginated.return_value = [
                mock_vendor_rating,
            ]
            vendor_rating_controller = VendorRatingController(
                self.request_context)

            # Act
            result = vendor_rating_controller.create_order_rating()

            # Assert
            assert result.status_code == 400
            assert result.get_json()['msg'] == 'You have already rated' \
                ' this meal'
Esempio n. 6
0
 def new_rating(self,
                vendor_id,
                user_id,
                rating,
                service_date,
                rating_type,
                type_id,
                engagement_id,
                main_menu_id,
                channel='web',
                comment=''):
     vendor_rating = VendorRating(vendor_id=vendor_id,
                                  user_id=user_id,
                                  rating=rating,
                                  service_date=service_date,
                                  channel=channel,
                                  comment=comment,
                                  rating_type=rating_type,
                                  type_id=type_id,
                                  engagement_id=engagement_id,
                                  main_meal_id=main_menu_id)
     vendor_rating.save()
     return vendor_rating
Esempio n. 7
0
    def test_create_vendor_rating_ok_response(
            self, mock_vendor_repo_get, mock_auth_user,
            mock_vendor_rating_controller_request_params,
            mock_vendor_engagement_repo_get,
            mock_vendor_rating_repo_new_rating,
            mock_vendor_rating_repo_update_vendor_average_rating):
        '''Test create_vendor_rating OK response.
        '''
        # Arrange
        with self.app.app_context():
            mock_vendor = Vendor(id=1,
                                 created_at=datetime.now(),
                                 updated_at=datetime.now(),
                                 name='Mock vendor',
                                 address='Mock address',
                                 tel='',
                                 contact_person='Mock contact person',
                                 is_active=True,
                                 location_id=1)
            mock_vendor_rating = VendorRating(vendor_id=1,
                                              user_id=1,
                                              comment='Mock comment',
                                              service_date=datetime.now(),
                                              rating=1.0,
                                              channel='Mock channel',
                                              rating_type='engagement',
                                              type_id=0,
                                              engagement_id=1,
                                              id=1,
                                              created_at=datetime.now(),
                                              updated_at=datetime.now(),
                                              main_meal_id=1)
            mock_vendor_repo_get.return_value = mock_vendor
            mock_auth_user.return_value = 1
            mock_vendor_rating_controller_request_params.return_value = (
                'Mock comment', 2.0, '2019-02-01', 'Mock channel', 1)
            mock_vendor_engagement_repo_get.return_value.vendor_id = 1
            mock_vendor_rating_repo_new_rating \
                .return_value = mock_vendor_rating
            vendor_rating_controller = VendorRatingController(
                self.request_context)
            mock_vendor_rating_repo_update_vendor_average_rating.return_value = None

            # Act
            result = vendor_rating_controller.create_vendor_rating()

            # Assert
            assert result.status_code == 201
            assert result.get_json()['msg'] == 'Rating created'
Esempio n. 8
0
	def new_vendor_rating(self, vendor_id, user_id, rating, channel, comment=''):
		vendor_rating = VendorRating(vendor_id=vendor_id, user_id=user_id, rating=rating, channel=channel, comment=comment)
		vendor_rating.save()
		return vendor_rating
 def setUp(self):
     self.BaseSetUp()
     self.fake = Faker()
     vendor = VendorFactory()
     location = LocationFactory()
     self.mock_vendor_engagement = VendorEngagement(
         id=1,
         created_at=datetime.now(),
         updated_at=datetime.now(),
         vendor_id=vendor.id,
         location_id=location.id,
         start_date=datetime.now(),
         end_date=datetime.now(),
         status=1,
         termination_reason=self.fake.text())
     self.mock_rating = VendorRating(id=1,
                                     created_at=datetime.now(),
                                     updated_at=datetime.now(),
                                     vendor_id=vendor.id,
                                     user_id=1,
                                     comment=self.fake.text(),
                                     service_date=datetime.now(),
                                     rating=1.2,
                                     channel='web',
                                     type_id=1,
                                     engagement_id=1,
                                     main_meal_id=1)
     self.mock_vendor_with_dependants = Vendor(
         id=1,
         created_at=datetime.now(),
         updated_at=datetime.now(),
         is_deleted=False,
         name=self.fake.name(),
         address=self.fake.address(),
         tel=self.fake.phone_number(),
         contact_person=self.fake.name(),
         is_active=True,
         location_id=location.id,
         ratings=[
             self.mock_rating,
         ],
         engagements=[
             self.mock_vendor_engagement,
         ])
     self.mock_vendor = Vendor(id=1,
                               created_at=datetime.now(),
                               updated_at=datetime.now(),
                               is_deleted=False,
                               name=self.fake.name(),
                               address=self.fake.address(),
                               tel=self.fake.phone_number(),
                               contact_person=self.fake.name(),
                               is_active=True,
                               location_id=location.id)
     self.mock_deleted_vendor = Vendor(id=1,
                                       created_at=datetime.now(),
                                       updated_at=datetime.now(),
                                       is_deleted=True,
                                       name=self.fake.name(),
                                       address=self.fake.address(),
                                       tel=self.fake.phone_number(),
                                       contact_person=self.fake.name(),
                                       is_active=True,
                                       location_id=location.id)