def test_links_to_sections_go_to_the_correct_pages_whether_they_be_sections_or_questions( self, content_loader, brief): # noqa content_fixture = ContentLoader("tests/fixtures/content") content_fixture.load_manifest("dos", "data", "edit_brief") content_loader.get_manifest.return_value = content_fixture.get_manifest( "dos", "edit_brief") document = self.get_requirements_task_list_page(brief) section_steps = document.cssselect("ol.dm-task-list") section_1_link = section_steps[0].xpath( 'li//a[contains(text(), "Section 1")]') section_2_link = section_steps[0].xpath( 'li//a[contains(text(), "Section 2")]') section_4_link = section_steps[0].xpath( 'li//a[contains(text(), "Section 4")]') # section with multiple questions assert ( section_1_link[0].get("href").strip() == "/buyers/frameworks/digital-outcomes-and-specialists-4/requirements/digital-specialists/1234/section-1" ) # section with single question assert ( section_2_link[0].get("href").strip() == "/buyers/frameworks/digital-outcomes-and-specialists-4" "/requirements/digital-specialists/1234/edit/section-2/required2") # section with single question and a description assert ( section_4_link[0].get("href").strip() == "/buyers/frameworks/digital-outcomes-and-specialists-4/requirements/digital-specialists/1234/section-4" )
def test_edit_brief_submission_raises_error_if_question_type_not_known(self, content_loader): with pytest.raises(UndefinedError): content_fixture = ContentLoader('tests/fixtures/content') content_fixture.load_manifest('dos', 'data', 'edit_brief_fail') content_loader.get_manifest.return_value = content_fixture.get_manifest('dos', 'edit_brief_fail') self.client.get( "/buyers/frameworks/digital-outcomes-and-specialists-4/requirements/digital-specialists" "/1234/edit/section-1/unhandled")
def main(): args = docopt(__doc__) frameworks_repo = Path(args["--frameworks-repo"]).resolve() framework_slug = args["<framework_slug>"] content_loader = ContentLoader(frameworks_repo) content_loader.load_manifest(framework_slug, "services", "services_search_filters") manifest = content_loader.get_manifest(framework_slug, "services_search_filters") # FIXME there isn't a uniform way to get the lots from the framework # content repo, hard code for G-Cloud for now framework_lots = [ { "name": "Cloud hosting", "slug": "cloud-hosting" }, { "name": "Cloud software", "slug": "cloud-software" }, { "name": "Cloud support", "slug": "cloud-support" }, ] writer = csv.writer(sys.stdout) # do the thing writer.writerow(["lot", "filter name", "filter value", "filter sub-value"]) def rows_for_filters(filters: dict): for section in filters.values(): yield ["", str(section["label"]), "", ""] for option in section["filters"]: yield ["", "", str(option["label"]), ""] # category filters can have sub-categories # (but not sub-sub-categories) if "children" in option: for suboption in option["children"]: yield ["", "", "", suboption["label"]] # start with filters that are common to all lots common_filters = filters_for_lot("all", manifest, framework_lots) writer.writerow(["Any lot", "", ""]) writer.writerows(rows_for_filters(common_filters)) for lot in framework_lots: writer.writerow([lot.get("name", lot["slug"])]) writer.writerows( rows_for_filters( filters_for_lot(lot["slug"], manifest, framework_lots)))
def test_edit_brief_submission_return_link_to_brief_overview_if_single_question(self, content_loader): content_fixture = ContentLoader('tests/fixtures/content') content_fixture.load_manifest('dos', 'data', 'edit_brief') content_loader.get_manifest.return_value = content_fixture.get_manifest('dos', 'edit_brief') res = self.client.get( "/buyers/frameworks/digital-outcomes-and-specialists-4/requirements/digital-specialists" "/1234/edit/section-2/required2") assert res.status_code == 200 document = html.fromstring(res.get_data(as_text=True)) secondary_action_link = document.xpath('//a[normalize-space(text())="Return to overview"]')[0] assert document.xpath('//h1')[0].text_content().strip() == "Required 2" assert secondary_action_link.get('href').strip() == "/buyers/frameworks/digital-outcomes-and-specialists-4/requirements/digital-specialists/1234" # noqa self._test_breadcrumbs_on_question_page(response=res, has_summary_page=False, question="Required 2")
def test_edit_brief_submission_multiquestion(self, content_loader): content_fixture = ContentLoader('tests/fixtures/content') content_fixture.load_manifest('dos', 'data', 'edit_brief') content_loader.get_manifest.return_value = content_fixture.get_manifest('dos', 'edit_brief') res = self.client.get( "/buyers/frameworks/digital-outcomes-and-specialists-4/requirements/digital-specialists/1234/edit/section-5/required3") # noqa assert res.status_code == 200 document = html.fromstring(res.get_data(as_text=True)) assert document.xpath('//h1')[0].text_content().strip() == "Required 3" assert document.xpath( '//label[contains(@for, "required3_1")]')[0].text_content().strip() == "Required 3_1" assert document.xpath( '//label[contains(@for, "required3_2")]')[0].text_content().strip() == "Required 3_2"
def test_post_update_if_single_question_no_description_redirects_to_overview(self, content_loader): content_fixture = ContentLoader('tests/fixtures/content') content_fixture.load_manifest('dos', 'data', 'edit_brief') content_loader.get_manifest.return_value = content_fixture.get_manifest('dos', 'edit_brief') res = self.client.post( "/buyers/frameworks/digital-outcomes-and-specialists-4/requirements/" "digital-specialists/1234/edit/section-2/required2", data={ "required2": "Answer" }) assert res.status_code == 302 self.data_api_client.update_brief.assert_called_with( '1234', {"required2": "Answer"}, page_questions=['required2'], updated_by='*****@*****.**' ) assert res.headers['Location'].endswith( 'buyers/frameworks/digital-outcomes-and-specialists-4/requirements/digital-specialists/1234' ) is True
def setup(self): content_loader = ContentLoader('tests/fixtures/content') content_loader.load_manifest('dos', "services", "edit_submission") self.content_manifest = content_loader.get_manifest( 'dos', "edit_submission") self.record = { "supplier": { "name": "ACME INC" }, "declaration": { "supplierRegisteredName": "ACME Ltd" }, "supplier_id": 34567, "onFramework": True, "services": [{ "locations": ["Offsite", "Scotland", "North East England"], "accessibleApplicationsOutcomes": True }] }
def main(): args = docopt(__doc__) frameworks_repo = Path(args["--frameworks-repo"]).resolve() framework_slug = args["<framework_slug>"] stage = args["<stage>"] lot = args["<lot>"] data_api_client = DataAPIClient(get_api_endpoint_from_stage(stage), get_auth_token('api', stage)) content_loader = ContentLoader(frameworks_repo) content_loader.load_manifest(framework_slug, "services", "services_search_filters") manifest = content_loader.get_manifest(framework_slug, "services_search_filters") # FIXME there isn't a uniform way to get the lots from the framework # content repo, hard code for G-Cloud for now framework_lots = [ {"name": "Cloud hosting", "slug": "cloud-hosting"}, {"name": "Cloud software", "slug": "cloud-software"}, {"name": "Cloud support", "slug": "cloud-support"}, ] writer = csv.writer(sys.stdout) # do the thing writer.writerow(['serviceId', 'topLevelCategories']) for service in data_api_client.find_services_iter(framework=framework_slug, status='published', lot=lot): service_categories = service['serviceCategories'] if service.get('serviceCategories') else [] top_level_categories = [] for f in filters_for_lot(service['lot'], manifest, framework_lots)['categories']['filters']: children = [f['label'] for f in f['children']] if f.get('children') else [] if any(item in service_categories for item in children): top_level_categories.append(f['label']) writer.writerow([service['id'], '; '.join(top_level_categories)])
("supplier_name", record["supplier"]["name"]), ("supplier_declaration_name", record["declaration"].get("supplierRegisteredName", "")), ("status", "PASSED" if record["onFramework"] else "FAILED"), ] return row + make_fields_from_content_questions(questions, record) return inner if __name__ == '__main__': arguments = docopt(__doc__) STAGE = arguments['<stage>'] CONTENT_PATH = arguments['<content_path>'] FRAMEWORK_SLUG = arguments['<framework_slug>'] client = DataAPIClient(get_api_endpoint_from_stage(STAGE), get_auth_token('api', STAGE)) content_loader = ContentLoader(CONTENT_PATH) content_loader.load_manifest(FRAMEWORK_SLUG, "services", "edit_submission") content_manifest = content_loader.get_manifest(FRAMEWORK_SLUG, "edit_submission") records = find_all_participants(client) write_csv_with_make_row( records, make_row(content_manifest), "output/{}-user-research-participants.csv".format(FRAMEWORK_SLUG))
class TestViewBriefSectionSummaryPage(BaseApplicationTest): def setup_method(self, method): super().setup_method(method) self.data_api_client_patch = mock.patch( "app.main.views.create_a_brief.edit.data_api_client", autospec=True ) self.data_api_client = self.data_api_client_patch.start() self.data_api_client.get_brief.return_value = BriefStub( framework_slug="digital-outcomes-and-specialists-4", ).single_result_response() self.data_api_client.get_framework.return_value = FrameworkStub( slug='digital-outcomes-and-specialists-4', status='live', lots=[ LotStub(slug='digital-specialists', allows_brief=True).response() ] ).single_result_response() self.login_as_buyer() self.content_fixture = ContentLoader('tests/fixtures/content') self.content_fixture.load_manifest('dos', 'data', 'edit_brief') def teardown_method(self, method): self.data_api_client_patch.stop() super().teardown_method(method) def _setup_brief(self, brief_status="draft", **stub_kwargs): brief_json = BriefStub( framework_slug="digital-outcomes-and-specialists-4", status=brief_status, **stub_kwargs ).single_result_response() brief_questions = brief_json['briefs'] brief_questions.update({ 'required1': 'test background info', 'required2': 'work work work', 'required3_1': 'yep', 'required3_2': 'yep' }) return brief_json @mock.patch('app.main.views.create_a_brief.edit.content_loader', autospec=True) def test_get_view_section_summary(self, content_loader): content_loader.get_manifest.return_value = self.content_fixture.get_manifest('dos', 'edit_brief') res = self.client.get( "/buyers/frameworks/digital-outcomes-and-specialists-4/requirements/digital-specialists/1234/section-1" ) assert res.status_code == 200 @pytest.mark.parametrize('show_dos_preview_links', (True, False, None)) @mock.patch('app.main.views.create_a_brief.edit.content_loader', autospec=True) def test_get_view_section_summary_links(self, content_loader, show_dos_preview_links): content_loader.get_manifest.return_value = self.content_fixture.get_manifest('dos', 'edit_brief') brief = self._setup_brief(lot_slug='digital-specialists') self.data_api_client.get_brief.return_value = brief res = self.client.get( "/buyers/frameworks/digital-outcomes-and-specialists-4/requirements/digital-specialists/1234/section-1" ) assert res.status_code == 200 document = html.fromstring(res.get_data(as_text=True)) overview_links = document.xpath( '//a[@href="/buyers/frameworks/digital-outcomes-and-specialists-4/requirements/digital-specialists/1234"]' ) assert [link.text_content().strip() for link in overview_links] == [ "I need a thing to do a thing", # breadcrumbs "Return to overview" # bottom nav link ] assert document.xpath( "//a[@href=$u][normalize-space(string())=$t]", u="/buyers/frameworks/digital-outcomes-and-specialists-4/requirements/digital-specialists/1234/preview", t="Preview your requirements", ) def test_wrong_lot_get_view_section_summary(self): res = self.client.get( "/buyers/frameworks/digital-outcomes-and-specialists-4/requirements/digital-outcomes/1234/section-1" ) assert res.status_code == 404
import mock import pytest from werkzeug.exceptions import NotFound import app.main.helpers as helpers from dmcontent.content_loader import ContentLoader from dmtestutils.api_model_stubs import BriefStub, FrameworkStub, LotStub content_loader = ContentLoader('tests/fixtures/content') content_loader.load_manifest('dos', 'data', 'edit_brief') questions_builder = content_loader.get_manifest('dos', 'edit_brief') class TestBuyersHelpers(object): def test_get_framework_and_lot(self): provided_lot = LotStub(slug='digital-specialists', allows_brief=True).response() data_api_client = mock.Mock() data_api_client.get_framework.return_value = FrameworkStub( slug='digital-outcomes-and-specialists-4', status='live', lots=[provided_lot], ).single_result_response() framework, lot = helpers.buyers_helpers.get_framework_and_lot( 'digital-outcomes-and-specialists-4', 'digital-specialists', data_api_client) assert framework['status'] == "live" assert framework['name'] == 'Digital Outcomes and Specialists 4'
from werkzeug.datastructures import MultiDict from werkzeug.urls import Href from dmcontent.content_loader import ContentLoader from app.main.presenters.search_presenters import ( filters_for_lot, set_filter_states, build_lots_and_categories_link_tree, ) from ...helpers import BaseApplicationTest content_loader = ContentLoader('tests/fixtures/content') content_loader.load_manifest('g6', 'data', 'manifest') content_loader.load_manifest('g9', 'data', 'manifest') g6_builder = content_loader.get_manifest('g6', 'manifest') g9_builder = content_loader.get_manifest('g9', 'manifest') def _get_fixture_data(): test_root = os.path.abspath( os.path.join(os.path.dirname(__file__), "../..") ) fixture_path = os.path.join( test_root, 'fixtures', 'search_results_fixture.json' ) with open(fixture_path) as fixture_file: return json.load(fixture_file) def _get_g9_aggregations_fixture_data():
return inner def get_specialist_roles(section): return [ question for outer_question in section.questions for question in outer_question.questions ] if __name__ == '__main__': arguments = docopt(__doc__) STAGE = arguments['<stage>'] API_TOKEN = arguments['<api_token>'] CONTENT_PATH = arguments['<content_path>'] client = DataAPIClient(get_api_endpoint_from_stage(STAGE), API_TOKEN) content_loader = ContentLoader(CONTENT_PATH) content_loader.load_manifest(FRAMEWORK_SLUG, "services", "edit_submission") content_manifest = content_loader.get_manifest(FRAMEWORK_SLUG, "edit_submission") suppliers = find_all_specialists(client) write_csv(suppliers, make_row(content_manifest), "output/dos-specialists.csv")