Esempio n. 1
0
 def setUp(self):
     self.BaseSetUp()
     self.repo = OrderRepo()
     self.location = LocationFactory()
     self.meal_item = MealItemFactory(location_id=self.location.id)
     self.vendor_engagement = VendorEngagementFactory(
         location_id=self.location.id)
     self.menu = MenuFactory(location_id=self.location.id,
                             main_meal_id=self.meal_item.id,
                             vendor_engagement_id=self.vendor_engagement.id)
Esempio n. 2
0
    def test_meal_average_method_returns_meal_rating(self):
        vendor_rating = VendorRatingFactory.build(
            vendor_id=self.vendor.id, engagement_id=self.engagement.id)
        main_meal_id = MealItemFactory.create().id

        new_vendor_rating = self.repo.new_rating(
            vendor_rating.vendor_id, vendor_rating.user_id,
            vendor_rating.rating, vendor_rating.service_date,
            vendor_rating.rating_type, vendor_rating.type_id,
            vendor_rating.engagement_id, main_meal_id, vendor_rating.channel,
            vendor_rating.comment)

        average_rating = self.repo.meal_average(new_vendor_rating.main_meal_id,
                                                new_vendor_rating.service_date)

        self.assertEqual(average_rating, 4)
Esempio n. 3
0
    def test_update_order_method_updates_order_object(self):
        meal = MealItemFactory.build()
        new_meal = MealItemRepo().new_meal_item(meal.name, meal.image,
                                                meal.meal_type,
                                                meal.location_id)

        order = OrderFactory.build()
        new_order = self.repo.create_order(
            order.user_id, order.date_booked_for.strftime('%Y-%m-%d'),
            order.meal_item_orders, order.location_id, order.menu_id,
            order.channel, order.meal_period)

        update_meal_list = [new_meal]

        update_order = self.repo.update_order(
            order.user_id, order.date_booked_for.strftime('%Y-%m-%d'),
            new_order.date_booked.strftime('%Y-%m-%d'), update_meal_list)

        self.assertIsInstance(update_order, Order)
        self.assertEqual(new_order.user_id, order.user_id)
        self.assertEqual(update_order.meal_item_orders, update_meal_list)
Esempio n. 4
0
    def test_new_menu_method_returns_new_menu_object(self):
        location = LocationFactory()
        meal_item = MealItemFactory.create(location=location)
        vendor_engagement = VendorEngagementFactory()
        menu = MenuFactory(location=location,
                           main_meal_id=meal_item.id,
                           vendor_engagement=vendor_engagement)

        new_menu = self.repo.new_menu(menu.date.strftime('%Y-%m-%d'),
                                      menu.meal_period, menu.main_meal_id,
                                      menu.allowed_side, menu.allowed_protein,
                                      [1, 2], [3, 4], vendor_engagement.id,
                                      location.id)

        self.assertIsInstance(new_menu, Menu)
        self.assertEqual(new_menu.allowed_protein, menu.allowed_protein)
        self.assertEqual(new_menu.allowed_side, menu.allowed_protein)
        self.assertEqual(new_menu.meal_period, menu.meal_period)

        self.assertIsInstance(new_menu, Menu)
        self.assertEqual(new_menu.allowed_protein, menu.allowed_protein)
        self.assertEqual(new_menu.allowed_side, menu.allowed_protein)
        self.assertEqual(new_menu.meal_period, menu.meal_period)
Esempio n. 5
0
    def test_update_order_method_updates_order_object(self):
        new_meal = MealItemFactory(name=self.meal_item.name,
                                   image=self.meal_item.image,
                                   meal_type=self.meal_item.meal_type,
                                   location_id=self.meal_item.location.id)

        order = OrderFactory.create(menu_id=self.menu.id,
                                    location_id=self.location.id,
                                    location=self.location)
        new_order = self.repo.create_order(
            order.user_id, order.date_booked_for.strftime('%Y-%m-%d'),
            order.meal_item_orders, order.location_id, order.menu_id,
            order.channel, order.meal_period)

        update_meal_list = [new_meal]

        update_order = self.repo.update_order(
            order.user_id, order.date_booked_for.strftime('%Y-%m-%d'),
            new_order.date_booked.strftime('%Y-%m-%d'), update_meal_list,
            order.location_id)

        self.assertIsInstance(update_order, Order)
        self.assertEqual(new_order.user_id, order.user_id)
        self.assertEqual(update_order.meal_item_orders, update_meal_list)
    def test_update_vendor_rating(self):
        vendor = VendorFactory.build(location_id=self.location.id)
        new_vendor = self.repo.new_vendor(vendor.name, vendor.address,
                                          vendor.tel, vendor.is_active,
                                          vendor.contact_person,
                                          vendor.location_id)

        engagement = VendorEngagementFactory(location_id=self.location.id,
                                             vendor_id=vendor.id,
                                             vendor=vendor)

        vendor_rating = VendorRatingFactory.build()
        main_meal_id = MealItemFactory.create().id
        vendor_rating = VendorRatingFactory.build(vendor_id=vendor.id,
                                                  engagement_id=engagement.id)
        self.rating_repo.new_rating(
            new_vendor.id, vendor_rating.user_id, 4,
            vendor_rating.service_date, vendor_rating.rating_type,
            vendor_rating.type_id, vendor_rating.engagement_id, main_meal_id,
            vendor_rating.channel, vendor_rating.comment)

        self.repo.update_vendor_average_rating(new_vendor.id)

        self.assertEqual(new_vendor.average_rating, 4)
    def test_create_order_rating_ok_response(
        self,
        mock_vendor_engagement_repo_get,
        mock_meal_item_repo_get,
        mock_auth_user,
        mock_vendor_rating_controller_request_params,
        mock_order_repo_get,
        mock_vendor_repo_update_average_rating
    ):
        '''Test create_order_rating when order has already been rated.
        '''
        # Arrange
        vendor = VendorFactory()
        location = LocationFactory()
        vendor_engagement = VendorEngagementFactory()
        meal_item = MealItemFactory()
        menu = MenuFactory()

        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=location.id
            )
            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() + timedelta(days=5)),
                status=1,
                termination_reason='Mock reason'
            )
            mock_order = Order(
                id=1,
                created_at=datetime.now(),
                updated_at=datetime.now(),
                user_id='user_id',
                date_booked_for=datetime.now(),
                date_booked=datetime.now(),
                channel='web',
                meal_period='lunch',
                order_status='booked',
                has_rated=False,
                menu_id=menu.id,
                location_id=location.id
            )

            mock_vendor_rating_controller_request_params.return_value = (
                2, meal_item.id, vendor_engagement.id, 'Mock comment', 3, '2019-02-06', 'web'
            )
            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_order_repo_get.return_value = mock_order
            vendor_rating_controller = VendorRatingController(
                self.request_context
            )
            mock_vendor_repo_update_average_rating.return_value = None

            # Act
            result = vendor_rating_controller.create_order_rating()

            # Assert
            assert result.status_code == 201
            assert result.get_json()['msg'] == 'Rating successful'