Exemple #1
0
    def test_list_menu_range_endpoint_with_right_permission_wrong_period(self):
        location = LocationFactory()
        meal_item_repo = MealItemRepo()
        role = RoleFactory.create(name='admin')
        user_id = BaseTestCase.user_id()
        PermissionFactory.create(keyword='view_menu', role=role)
        UserRoleFactory.create(user_id=user_id, role=role)
        current_date = datetime.now().date()
        start_date = current_date.strftime('%Y-%m-%d')
        end_date = (datetime.now().date() +
                    timedelta(days=7)).strftime('%Y-%m-%d')

        side_meal_item = meal_item_repo.new_meal_item(name="side1",
                                                      image="image11",
                                                      meal_type="side",
                                                      location_id=location.id)
        protein_meal_item = meal_item_repo.new_meal_item(
            name="protein1",
            image="image12",
            meal_type="protein",
            location_id=location.id)
        MenuFactory.create_batch(5,
                                 side_items=side_meal_item.id,
                                 protein_items=protein_meal_item.id)

        response = self.client() \
            .get(self.make_url(f'/admin/menus/wrong_period/{start_date}/{end_date}'), headers=self.headers())
        response_json = self.decode_from_json_string(
            response.data.decode('utf-8'))

        self.assert400(response)
        self.assertEqual(response_json['msg'],
                         'Provide valid meal period and date range')
Exemple #2
0
    def test_list_menu_range_endpoint_with_right_permission(self):
        """ Test that users with right permission can view list of menu with date range """
        location = LocationFactory.create()
        meal_item_repo = MealItemRepo()
        role = RoleFactory.create(name='admin')
        user_id = BaseTestCase.user_id()
        PermissionFactory.create(keyword='view_menu', role=role)
        UserRoleFactory.create(user_id=user_id, role=role)
        current_date = datetime.now().date()
        start_date = current_date.strftime('%Y-%m-%d')
        end_date = (datetime.now().date() +
                    timedelta(days=7)).strftime('%Y-%m-%d')

        side_meal_item = meal_item_repo.new_meal_item(name="side1",
                                                      image="image11",
                                                      meal_type="side",
                                                      location_id=location.id)
        protein_meal_item = meal_item_repo.new_meal_item(
            name="protein1",
            image="image12",
            meal_type="protein",
            location_id=location.id)
        MenuFactory.create_batch(5,
                                 side_items=side_meal_item.id,
                                 protein_items=protein_meal_item.id,
                                 location=location)

        response = self.client() \
            .get(self.make_url(f'/admin/menus/{MealPeriods.lunch}/{start_date}/{end_date}'), headers=self.headers())

        self.assert200(response)
Exemple #3
0
    def test_list_menu_endpoint_with_right_permission(self):
        """Test that users with the right permission can view list of menus"""

        meal_item_repo = MealItemRepo()
        role = RoleFactory.create(name='admin')
        user_id = BaseTestCase.user_id()
        PermissionFactory.create(keyword='view_menu', role_id=role.id)
        UserRoleFactory.create(user_id=user_id, role_id=role.id)
        the_date = datetime.now().date()
        current_date = the_date.strftime('%Y-%m-%d')

        side_meal_item = meal_item_repo.new_meal_item(name="side1",
                                                      image="image11",
                                                      meal_type="side",
                                                      location_id=1)
        protein_meal_item = meal_item_repo.new_meal_item(name="protein1",
                                                         image="image12",
                                                         meal_type="protein",
                                                         location_id=1)
        MenuFactory.create_batch(5,
                                 side_items=side_meal_item.id,
                                 protein_items=protein_meal_item.id,
                                 date=the_date)

        response = self.client().get(
            self.make_url(f'/admin/menus/{MealPeriods.lunch}/{current_date}'),
            headers=self.headers())

        self.assert200(response)
Exemple #4
0
    def test_list_menu_range_endpoint_without_right_permission(self):
        """ Test that users without the right permission cannot view list of menus with date range """
        start_date = datetime.now().date()
        end_date = datetime.now().date() + timedelta(days=7)

        MenuFactory.create_batch(5)

        response = self.client().get(self.make_url(
            f'/admin/menus/{MealPeriods.lunch}/{start_date}/{end_date}'),
                                     headers=self.headers())

        self.assert401(response)
Exemple #5
0
    def test_list_menu_endpoint_without_right_permission(self):
        """Test that users without the right permission cannot view list of menus"""

        role = RoleFactory.create(name='admin')
        user_id = BaseTestCase.user_id()
        PermissionFactory.create(keyword='view_menu', role_id=100)
        UserRoleFactory.create(user_id=user_id, role=role)
        current_date = datetime.now().date()

        MenuFactory.create_batch(5)
        Menu.query.all()

        response = self.client().get(
            self.make_url(f'/admin/menus/{MealPeriods.lunch}/{current_date}'),
            headers=self.headers())

        self.assert401(response)
Exemple #6
0
    def test_list_menu_range_endpoint_with_right_permission_wrong_range(self):
        """ Test that users with right permission but wrong range cannot view """
        role = RoleFactory.create(name='admin')
        user_id = BaseTestCase.user_id()
        PermissionFactory.create(keyword='view_menu', role=role)
        UserRoleFactory.create(user_id=user_id, role=role)

        start_date = datetime.now().date()
        end_date = datetime.now().date() + timedelta(days=-7)

        MenuFactory.create_batch(5)

        response = self.client().get(self.make_url(
            f'/admin/menus/{MealPeriods.lunch}/{start_date}/{end_date}'),
                                     headers=self.headers())
        response_json = self.decode_from_json_string(
            response.data.decode('utf-8'))

        self.assert400(response)
        self.assertEqual(
            response_json['msg'],
            'Provide valid date range. start_date cannot be greater than end_date'
        )