def test_delete_engagement_with_associated_menus(self):
        datetime.now().date()
        location = LocationFactory()
        location.save()
        meal_item = MealItemFactory(location=location)
        vendor = VendorFactory(location=location)
        engagement = VendorEngagementFactory.create(location=location, vendor=vendor)
        menu_repo = MenuRepo()
        menu_repo.new_menu(
            date='2018-10-15',
            meal_period='lunch',
            main_meal_id=meal_item.id,
            allowed_side=1,
            allowed_protein=1,
            side_items=[2],
            protein_items=[3],
            vendor_engagement_id=engagement.id,
            location_id=location.id
        )

        role = RoleFactory.create(name='admin')
        user_id = BaseTestCase.user_id()
        PermissionFactory.create(keyword='delete_engagement', role=role)
        UserRoleFactory.create(user_id=user_id, role=role, location_id=location.id)

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

        self.assert400(response)

        self.assertEqual(response_json['msg'], 'This engagement cannot be deleted because it has a child object')
    def test_immediate_past_engagement_no_past_engagement(self):

        location = LocationFactory()
        location.save()
        vendor = VendorFactory.create(location=location)
        vendor.save()
        engagement1 = VendorEngagementFactory.create(vendor_id=vendor.id, end_date=datetime.now()+timedelta(10), location=location)
        engagement2 = VendorEngagementFactory.create(vendor_id=vendor.id, end_date=datetime.now()+timedelta(14), location=location)
        engagement1.save()
        engagement2.save()

        response = self.client().get(self.make_url(f'/engagements/past/{location.id}'), headers=self.headers())
        response_json = self.decode_from_json_string(response.data.decode('utf-8'))

        self.assert404(response)
        self.assertEqual(response_json['msg'], 'No past engagement for this location')