def test_delete_order_not_yours(self):
        user_id = BaseTestCase.user_id()
        meal = MealItemFactory.create()
        menu = MenuFactory.create()
        order_data = {
            'user_id': '-UTG654RfggtdI',
            'date_booked_for': '2018-10-20',
            'channel': 'web',
            'meal_period': 'lunch',
            'menu_id': menu.id,
            'meal_items': [meal],
            'location_id': 1
        }
        order_repo = OrderRepo()
        order = order_repo.create_order(**order_data)

        response = self.client().delete(self.make_url(f'/orders/{order.id}'),
                                        headers=self.headers())
        response_json = self.decode_from_json_string(
            response.data.decode('utf-8'))

        self.assert403(response)
        self.assertEqual(response_json['msg'],
                         'You cannot delete an order that is not yours')
Exemplo n.º 2
0
    def test_create_menu_endpoint_with_wrong_protein_items(self):
        """Test for creation of new menu with wrong protein items"""
        menu = MenuFactory.build()
        main_meal_item = MealItemFactory.create()
        side_meal_item = MealItemFactory.create()
        protein_meal_item = MealItemFactory.create()

        vendor = VendorFactory.build()
        vendor_engagement = VendorEngagementFactory.build(vendor_id=vendor.id)

        role = RoleFactory.create(name='admin')
        user_id = BaseTestCase.user_id()
        PermissionFactory.create(keyword='create_menu', role=role)
        UserRoleFactory.create(user_id=user_id, role=role)

        data = {
            'date': menu.date.strftime('%Y-%m-%d'),
            'mealPeriod': menu.meal_period,
            'mainMealId': main_meal_item.id,
            'allowedSide': menu.allowed_side,
            'allowedProtein': menu.allowed_protein,
            'sideItems': [side_meal_item.id],
            'proteinItems': [100],
            'vendorEngagementId': vendor_engagement.id
        }

        response = self.client().post(self.make_url('/admin/menus/'), \
                                      data=self.encode_to_json_string(data), headers=self.headers())
        response_json = self.decode_from_json_string(
            response.data.decode('utf-8'))

        self.assertEqual(response.status_code, 400)
        self.assertEqual(
            response_json['msg'],
            'Bad Request - proteinItems contains invalid id(s) for meal_item table '
        )
Exemplo n.º 3
0
    def test_list_menu_range_endpoint_succeeds(self):
        location = LocationFactory.create()
        meal_item_repo = MealItemRepo()

        main_meal_item = meal_item_repo.new_meal_item(name="main1",
                                                      image="image1",
                                                      meal_type="main",
                                                      location_id=location.id)
        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)
        headers = self.headers()
        headers.update({'X-Location': location.id})
        menu = MenuFactory.create(main_meal_id=main_meal_item.id,
                                  side_items=str(side_meal_item.id),
                                  protein_items=str(protein_meal_item.id),
                                  location=location)
        menu.save()
        start_date = menu.vendor_engagement.start_date - timedelta(days=1)

        response = self.client().get(self.make_url(
            f'/menus/{menu.meal_period}/{start_date}/{menu.vendor_engagement.end_date}'
        ),
                                     headers=headers)

        response_json = self.decode_from_json_string(
            response.data.decode('utf-8'))
        self.assertEqual(response_json['msg'], 'OK')
        self.assertEqual(
            response_json['payload']['menuList'][0]['menus'][0]['id'], menu.id)
Exemplo n.º 4
0
    def test_interactions_after_final_meal_selection(self, mock_json_loads, mock_user_info, mock_order_repo, mock_andela_service, mock_menu_repo, mock_meal_items, mock_post):
        location = LocationFactory.create()
        location.save()
        menu = MenuFactory.create()
        menu.save()

        final_selection['state'] = f'{menu.id}_breakfast_2019-02-19_order_{location.id}_1'
        mock_json_loads.return_value = final_selection
        mock_user_info.return_value = {'user': {'profile': {'email': '*****@*****.**'}}}
        mock_andela_service.return_value = {'id': 'victor_adukwu_andela_com', 'email': '*****@*****.**'}

        mock_menu_repo.return_value = menu

        order = OrderFactory.create(menu=menu, location=location)

        mock_order_repo.return_value = order
        mock_meal_items.return_values = MealItemFactory.create()

        response = self.client().post(self.make_url(f'/bot/interactions/'), headers=self.headers())
        response_json = self.decode_from_json_string(response.data.decode('utf-8'))

        self.assert200(response)
        self.assertEqual(response_json['type'], 'dialog_submission')
        mock_post.assert_called_once()