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"
        )
Esempio n. 2
0
def get_framework_contract_title(content_path: str,
                                 framework_slug: str) -> str:
    """The contract title is different for G-Cloud and DOS. Look up the correct name with the content loader"""
    content_loader = ContentLoader(content_path)
    content_loader.load_messages(framework_slug, ["e-signature"])
    return str(
        content_loader.get_message(framework_slug, "e-signature",
                                   "framework_contract_title"))
def load_manifest(schema_type, framework_slug, lot_slug):
    loader = ContentLoader('./')
    loader.load_manifest(framework_slug,
                         MANIFESTS[schema_type]['question_set'],
                         MANIFESTS[schema_type]['manifest'])

    return loader.get_builder(framework_slug,
                              MANIFESTS[schema_type]['manifest']).filter(
                                  {'lot': lot_slug})
def load_manifest(schema_type, framework_slug, lot_slug):
    loader = ContentLoader('./')
    loader.load_manifest(
        framework_slug,
        MANIFESTS[schema_type]['question_set'],
        MANIFESTS[schema_type]['manifest']
    )

    return loader.get_builder(framework_slug, MANIFESTS[schema_type]['manifest']).filter({'lot': lot_slug})
Esempio n. 5
0
    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")
Esempio n. 6
0
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)))
Esempio n. 7
0
    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")
Esempio n. 8
0
    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 _make_content_loader_factory(application,
                                 frameworks,
                                 initial_instance=None):
    # for testing purposes we allow an initial_instance to be provided
    primary_cl = initial_instance if initial_instance is not None else ContentLoader(
        'app/content')
    for framework_data in frameworks:
        if not framework_data['slug'] in application.config.get(
                'DM_FRAMEWORK_CONTENT_MAP', {}):
            if framework_data['framework'] == 'g-cloud':
                primary_cl.load_manifest(framework_data['slug'], 'services',
                                         'services_search_filters')
                # we need to be able to display old services, even on expired frameworks
                primary_cl.load_manifest(framework_data['slug'], 'services',
                                         'display_service')
                primary_cl.load_manifest(framework_data['slug'], 'services',
                                         'download_results')
                try_load_metadata(primary_cl, application, framework_data,
                                  ['following_framework'])
            elif framework_data[
                    'framework'] == 'digital-outcomes-and-specialists':
                primary_cl.load_manifest(framework_data['slug'], 'briefs',
                                         'display_brief')
                try_load_manifest(primary_cl, application, framework_data,
                                  'briefs', 'briefs_search_filters')

    # seal primary_cl in a closure by returning a function which will only ever return an independent copy of it.
    # this is of course only guaranteed when the initial_instance argument wasn't used.
    return lambda: deepcopy(primary_cl)
Esempio n. 10
0
def _make_content_loader_factory():
    primary_cl = ContentLoader('app/content')

    _load_dos(primary_cl)
    _load_g_cloud(primary_cl)

    # seal primary_cl in a closure by returning a function which will only ever return an independent copy of it
    return lambda: deepcopy(primary_cl)
Esempio n. 11
0
    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')
Esempio n. 12
0
    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
Esempio n. 13
0
    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)])
Esempio n. 15
0
def _make_content_loader_factory(application, frameworks, initial_instance=None):
    # for testing purposes we allow an initial_instance to be provided
    master_cl = initial_instance if initial_instance is not None else ContentLoader('app/content')
    for framework_data in frameworks:
        try:
            master_cl.load_manifest(framework_data['slug'], 'services', 'edit_service_as_admin')
        except ContentNotFoundError:
            # Not all frameworks have this, so no need to panic (e.g. G-Cloud 4, G-Cloud 5)
            application.logger.info(
                "Could not load edit_service_as_admin manifest for {}".format(framework_data['slug'])
            )
        try:
            master_cl.load_manifest(framework_data['slug'], 'declaration', 'declaration')
        except ContentNotFoundError:
            # Not all frameworks have this, so no need to panic (e.g. G-Cloud 4, G-Cloud 5, G-Cloud-6)
            application.logger.info(
                "Could not load declaration manifest for {}".format(framework_data['slug'])
            )

    # seal master_cl in a closure by returning a function which will only ever return an independent copy of it.
    # this is of course only guaranteed when the initial_instance argument wasn't used.
    return lambda: deepcopy(master_cl)
Esempio n. 16
0
def _make_content_loader_factory(application,
                                 frameworks,
                                 initial_instance=None):
    # for testing purposes we allow an initial_instance to be provided
    master_cl = initial_instance if initial_instance is not None else ContentLoader(
        'app/content')
    for framework_data in frameworks:
        try:
            master_cl.load_manifest(framework_data['slug'], 'services',
                                    'edit_service_as_admin')
        except ContentNotFoundError:
            _log_missing_manifest(application, "edit_service_as_admin",
                                  framework_data['slug'])
        try:
            master_cl.load_manifest(framework_data['slug'], 'declaration',
                                    'declaration')
        except ContentNotFoundError:
            _log_missing_manifest(application, "declaration",
                                  framework_data['slug'])

    # seal master_cl in a closure by returning a function which will only ever return an independent copy of it.
    # this is of course only guaranteed when the initial_instance argument wasn't used.
    return lambda: deepcopy(master_cl)
Esempio n. 17
0
from flask import Blueprint, current_app, flash
from flask_login import current_user, login_required
from dmcontent.content_loader import ContentLoader

buyers = Blueprint('buyers', __name__)

content_loader = ContentLoader('app/content')
content_loader.load_manifest('digital-outcomes-and-specialists', 'briefs',
                             'edit_brief')
content_loader.load_manifest('digital-outcomes-and-specialists',
                             'brief-responses', 'output_brief_response')
content_loader.load_manifest('digital-outcomes-and-specialists',
                             'clarification_question',
                             'clarification_question')
content_loader.load_manifest('digital-service-professionals', 'briefs',
                             'edit_brief')
content_loader.load_manifest('digital-service-professionals',
                             'brief-responses', 'output_brief_response')
content_loader.load_manifest('digital-service-professionals',
                             'clarification_question',
                             'clarification_question')
content_loader.load_manifest('digital-marketplace', 'briefs', 'edit_brief')
content_loader.load_manifest('digital-marketplace', 'brief-responses',
                             'output_brief_response')
content_loader.load_manifest('digital-marketplace', 'clarification_question',
                             'clarification_question')


@buyers.before_request
@login_required
def require_login():
Esempio n. 18
0
from flask import Blueprint
from dmcontent.content_loader import ContentLoader

main = Blueprint('main', __name__)

content_loader = ContentLoader('app/content')
content_loader.load_manifest('g-cloud-6', 'services', 'edit_service')
content_loader.load_messages('g-cloud-6', ['dates'])

content_loader.load_manifest('g-cloud-7', 'services', 'edit_service')
content_loader.load_manifest('g-cloud-7', 'services', 'edit_submission')
content_loader.load_manifest('g-cloud-7', 'declaration', 'declaration')
content_loader.load_messages('g-cloud-7', ['dates'])

content_loader.load_manifest('digital-outcomes-and-specialists', 'declaration',
                             'declaration')
content_loader.load_manifest('digital-outcomes-and-specialists', 'services',
                             'edit_submission')
content_loader.load_manifest('digital-outcomes-and-specialists',
                             'brief-responses', 'edit_brief_response')
content_loader.load_messages('digital-outcomes-and-specialists', ['dates'])

content_loader.load_manifest('g-cloud-8', 'services', 'edit_service')
content_loader.load_manifest('g-cloud-8', 'services', 'edit_submission')
content_loader.load_manifest('g-cloud-8', 'declaration', 'declaration')
content_loader.load_messages('g-cloud-8', ['dates'])


@main.after_request
def add_cache_control(response):
    response.cache_control.no_cache = True
Esempio n. 19
0
import mock
import unittest
import datetime
from werkzeug.exceptions import NotFound

import app.helpers as helpers
from dmcontent.content_loader import ContentLoader

from dmapiclient import api_stubs

content_loader = ContentLoader('tests/fixtures/content')
content_loader.load_manifest('dos', 'data', 'edit_brief')
questions_builder = content_loader.get_builder('dos', 'edit_brief')


class TestBuyersHelpers(unittest.TestCase):
    def test_get_framework_and_lot(self):
        data_api_client = mock.Mock()
        data_api_client.get_framework.return_value = api_stubs.framework(
            slug='digital-outcomes-and-specialists',
            status='live',
            lots=[
                api_stubs.lot(slug='digital-specialists', allows_brief=True)
            ])

        framework, lot = helpers.buyers_helpers.get_framework_and_lot(
            'digital-outcomes-and-specialists', 'digital-specialists',
            data_api_client)

        assert framework['status'] == "live"
        assert framework['name'] == 'Digital Outcomes and Specialists'
import os
import json
import unittest
from mock import Mock
from dmcontent.content_loader import ContentLoader
from werkzeug.datastructures import MultiDict

from app.presenters.search_presenters import filters_for_lot, set_filter_states

content_loader = ContentLoader('tests/fixtures/content')
content_loader.load_manifest('g6', 'data', 'manifest')
questions_builder = content_loader.get_builder('g6', '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_fixture_multiple_pages_data():
    test_root = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
    fixture_path = os.path.join(test_root, 'fixtures',
                                'search_results_multiple_pages_fixture.json')
    with open(fixture_path) as fixture_file:
        return json.load(fixture_file)


class TestSearchFilters(unittest.TestCase):
Esempio n. 21
0
from dmcontent.content_loader import ContentLoader

from config import configs
from app.helpers.terms_helpers import TermsManager

from react.render import render_component

import redis
from flask_kvsession import KVSessionExtension
from simplekv.memory.redisstore import RedisStore

cache = Cache()
login_manager = LoginManager()
data_api_client = dmapiclient.DataAPIClient()

content_loader = ContentLoader('app/content')
content_loader.load_manifest('g-cloud-6', 'services', 'search_filters')
content_loader.load_manifest('g-cloud-6', 'services', 'display_service')
content_loader.load_manifest('digital-outcomes-and-specialists', 'briefs',
                             'display_brief')
content_loader.load_manifest('digital-service-professionals', 'briefs',
                             'display_brief')
content_loader.load_manifest('digital-marketplace', 'briefs', 'display_brief')


def create_app(config_name):
    asset_path = os.environ.get('ASSET_PATH', configs[config_name].ASSET_PATH)
    application = Flask(__name__, static_url_path=asset_path)

    init_app(
        application,
from dmutils.env_helpers import get_api_endpoint_from_stage

logger = logging_helpers.configure_logger()

if __name__ == '__main__':
    arguments = docopt(__doc__)
    supplier_ids = get_supplier_ids_from_args(arguments)

    STAGE = arguments['<stage>']
    FRAMEWORK_SLUG = arguments['<framework>']
    GOVUK_NOTIFY_API_KEY = arguments['<notify_api_key>']
    GOVUK_NOTIFY_TEMPLATE_ID = arguments['<notify_template_id>']
    CONTENT_PATH = arguments['<content_path>']
    DRY_RUN = arguments['--dry-run']

    content_loader = ContentLoader(CONTENT_PATH)
    content_loader.load_messages(FRAMEWORK_SLUG, ['e-signature'])
    mail_client = scripts_notify_client(GOVUK_NOTIFY_API_KEY, logger=logger)
    api_client = DataAPIClient(base_url=get_api_endpoint_from_stage(STAGE),
                               auth_token=get_auth_token('api', STAGE))

    context_helper = SuccessfulSupplierContextForNotify(
        api_client, FRAMEWORK_SLUG, supplier_ids=supplier_ids, logger=logger)
    context_helper.populate_data()
    context_data = context_helper.get_users_personalisations()
    framework = api_client.get_framework(FRAMEWORK_SLUG).get('frameworks')

    prefix = "[Dry Run] " if DRY_RUN else ""

    # Add in any framework-specific dates etc here
    extra_template_context = {
Esempio n. 23
0
import sys
sys.path.insert(0, '.')

from docopt import docopt
from dmscripts.helpers.auth_helpers import get_auth_token
from dmscripts.helpers.supplier_data_helpers import get_supplier_ids_from_file
from dmscripts.export_framework_results_reasons import export_suppliers
from dmapiclient import DataAPIClient
from dmcontent.content_loader import ContentLoader
from dmutils.env_helpers import get_api_endpoint_from_stage

if __name__ == '__main__':
    args = docopt(__doc__)

    client = DataAPIClient(get_api_endpoint_from_stage(args['<stage>']),
                           get_auth_token('api', args['<stage>']))
    content_loader = ContentLoader(args['<content_path>'])

    declaration_definite_pass_schema = json.load(
        open(args["<declaration_schema_path>"], "r"))
    declaration_baseline_schema = (
        declaration_definite_pass_schema.get("definitions")
        or {}).get("baseline")

    supplier_id_file = args['<supplier_id_file>']
    supplier_ids = get_supplier_ids_from_file(supplier_id_file)

    export_suppliers(client, args['<framework_slug>'], content_loader,
                     args['<output_dir>'], declaration_definite_pass_schema,
                     declaration_baseline_schema, supplier_ids)
    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")
import os
import json
import unittest
from mock import Mock
from dmcontent.content_loader import ContentLoader
from werkzeug.datastructures import MultiDict

from app.presenters.search_presenters import filters_for_lot, set_filter_states


content_loader = ContentLoader('tests/fixtures/content')
content_loader.load_manifest('g6', 'data', 'manifest')
questions_builder = content_loader.get_builder('g6', '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_fixture_multiple_pages_data():
    test_root = os.path.abspath(
        os.path.join(os.path.dirname(__file__), "..")
    )
    fixture_path = os.path.join(
from flask_bootstrap import Bootstrap
from flask_login import LoginManager

import dmapiclient
from dmutils import init_app, init_frontend_app, formats
from dmutils.user import User
from dmcontent.content_loader import ContentLoader

from config import configs


bootstrap = Bootstrap()
data_api_client = dmapiclient.DataAPIClient()
login_manager = LoginManager()

content_loader = ContentLoader('app/content')
content_loader.load_manifest('g-cloud-6', 'services', 'edit_service_as_admin')
content_loader.load_manifest('g-cloud-7', 'declaration', 'declaration')
content_loader.load_manifest('digital-outcomes-and-specialists', 'declaration', 'declaration')
content_loader.load_manifest('g-cloud-8', 'declaration', 'declaration')

from app.main.helpers.service import parse_document_upload_time  # noqa


def create_app(config_name):

    application = Flask(__name__,
                        static_folder='static/',
                        static_url_path=configs[config_name].ASSET_PATH)

    init_app(
import dmapiclient
from dmutils import init_app, init_frontend_app
from dmutils.user import User
from dmcontent.content_loader import ContentLoader

from config import configs
from app.helpers.terms_helpers import TermsManager

from react.render import render_component

cache = Cache()
login_manager = LoginManager()
data_api_client = dmapiclient.DataAPIClient()

content_loader = ContentLoader('app/content')
content_loader.load_manifest('g-cloud-6', 'services', 'search_filters')
content_loader.load_manifest('g-cloud-6', 'services', 'display_service')
content_loader.load_manifest('digital-outcomes-and-specialists', 'briefs', 'display_brief')
content_loader.load_manifest('digital-service-professionals', 'briefs', 'display_brief')
content_loader.load_manifest('digital-marketplace', 'briefs', 'display_brief')


def create_app(config_name):
    asset_path = os.environ.get('ASSET_PATH', configs[config_name].ASSET_PATH)
    application = Flask(__name__, static_url_path=asset_path)

    init_app(
        application,
        configs[config_name],
        data_api_client=data_api_client,
Esempio n. 28
0
def _make_content_loader_factory():
    master_cl = ContentLoader('app/content')

    master_cl.load_manifest('digital-outcomes-and-specialists', 'briefs',
                            'edit_brief')
    master_cl.load_manifest('digital-outcomes-and-specialists',
                            'brief-responses', 'legacy_edit_brief_response')
    master_cl.load_manifest('digital-outcomes-and-specialists',
                            'brief-responses', 'edit_brief_response')
    master_cl.load_manifest('digital-outcomes-and-specialists',
                            'brief-responses', 'legacy_display_brief_response')
    master_cl.load_manifest('digital-outcomes-and-specialists',
                            'brief-responses', 'display_brief_response')

    master_cl.load_manifest('digital-outcomes-and-specialists-2', 'briefs',
                            'edit_brief')
    master_cl.load_manifest('digital-outcomes-and-specialists-2',
                            'brief-responses', 'edit_brief_response')
    master_cl.load_manifest('digital-outcomes-and-specialists-2',
                            'brief-responses', 'display_brief_response')

    master_cl.load_manifest('digital-outcomes-and-specialists-3', 'briefs',
                            'edit_brief')
    master_cl.load_manifest('digital-outcomes-and-specialists-3',
                            'brief-responses', 'edit_brief_response')
    master_cl.load_manifest('digital-outcomes-and-specialists-3',
                            'brief-responses', 'display_brief_response')

    master_cl.load_manifest('digital-outcomes-and-specialists-4', 'briefs',
                            'edit_brief')
    master_cl.load_manifest('digital-outcomes-and-specialists-4',
                            'brief-responses', 'edit_brief_response')
    master_cl.load_manifest('digital-outcomes-and-specialists-4',
                            'brief-responses', 'display_brief_response')

    master_cl.load_manifest('digital-outcomes-and-specialists-5', 'briefs',
                            'edit_brief')
    master_cl.load_manifest('digital-outcomes-and-specialists-5',
                            'brief-responses', 'edit_brief_response')
    master_cl.load_manifest('digital-outcomes-and-specialists-5',
                            'brief-responses', 'display_brief_response')

    # seal master_cl in a closure by returning a function which will only ever return an independent copy of it
    return lambda: deepcopy(master_cl)
import dmapiclient
from dmutils import init_app, init_frontend_app, formats
from dmutils.user import User
from dmcontent.content_loader import ContentLoader

from config import configs

import redis
from flask_kvsession import KVSessionExtension
from simplekv.memory.redisstore import RedisStore

bootstrap = Bootstrap()
data_api_client = dmapiclient.DataAPIClient()
login_manager = LoginManager()

content_loader = ContentLoader('app/content')
content_loader.load_manifest('g-cloud-6', 'services', 'edit_service_as_admin')
content_loader.load_manifest('g-cloud-7', 'declaration', 'declaration')
content_loader.load_manifest('digital-outcomes-and-specialists', 'declaration',
                             'declaration')
content_loader.load_manifest('g-cloud-8', 'declaration', 'declaration')

from app.main.helpers.service import parse_document_upload_time  # noqa


def create_app(config_name):

    application = Flask(__name__,
                        static_folder='static/',
                        static_url_path=configs[config_name].ASSET_PATH)
            ("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))
Esempio n. 31
0
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
def _make_content_loader_factory():
    master_cl = ContentLoader('app/content')
    master_cl.load_manifest('g-cloud-6', 'services', 'edit_service')
    master_cl.load_messages('g-cloud-6', ['urls'])

    master_cl.load_manifest('g-cloud-7', 'services', 'edit_service')
    master_cl.load_manifest('g-cloud-7', 'services', 'edit_submission')
    master_cl.load_manifest('g-cloud-7', 'declaration', 'declaration')
    master_cl.load_messages('g-cloud-7', ['urls'])

    master_cl.load_manifest('digital-outcomes-and-specialists', 'declaration', 'declaration')
    master_cl.load_manifest('digital-outcomes-and-specialists', 'services', 'edit_submission')
    master_cl.load_manifest('digital-outcomes-and-specialists', 'briefs', 'edit_brief')
    master_cl.load_messages('digital-outcomes-and-specialists', ['urls'])

    master_cl.load_manifest('digital-outcomes-and-specialists-2', 'declaration', 'declaration')
    master_cl.load_manifest('digital-outcomes-and-specialists-2', 'services', 'edit_submission')
    master_cl.load_manifest('digital-outcomes-and-specialists-2', 'services', 'edit_service')
    master_cl.load_manifest('digital-outcomes-and-specialists-2', 'briefs', 'edit_brief')
    master_cl.load_messages('digital-outcomes-and-specialists-2', ['urls'])

    master_cl.load_manifest('g-cloud-8', 'services', 'edit_service')
    master_cl.load_manifest('g-cloud-8', 'services', 'edit_submission')
    master_cl.load_manifest('g-cloud-8', 'declaration', 'declaration')
    master_cl.load_messages('g-cloud-8', ['urls'])

    master_cl.load_manifest('g-cloud-9', 'services', 'edit_service')
    master_cl.load_manifest('g-cloud-9', 'services', 'edit_submission')
    master_cl.load_manifest('g-cloud-9', 'declaration', 'declaration')
    master_cl.load_messages('g-cloud-9', ['urls', 'advice'])

    master_cl.load_manifest('g-cloud-10', 'services', 'edit_service')
    master_cl.load_manifest('g-cloud-10', 'services', 'edit_submission')
    master_cl.load_manifest('g-cloud-10', 'declaration', 'declaration')
    master_cl.load_messages('g-cloud-10', ['urls', 'advice'])
    master_cl.load_metadata('g-cloud-10', ['copy_services'])

    master_cl.load_manifest('digital-outcomes-and-specialists-3', 'declaration', 'declaration')
    master_cl.load_manifest('digital-outcomes-and-specialists-3', 'services', 'edit_submission')
    master_cl.load_manifest('digital-outcomes-and-specialists-3', 'services', 'edit_service')
    master_cl.load_manifest('digital-outcomes-and-specialists-3', 'briefs', 'edit_brief')
    master_cl.load_messages('digital-outcomes-and-specialists-3', ['urls'])
    master_cl.load_metadata('digital-outcomes-and-specialists-3', ['copy_services', 'following_framework'])

    master_cl.load_manifest('g-cloud-11', 'services', 'edit_service')
    master_cl.load_manifest('g-cloud-11', 'services', 'edit_submission')
    master_cl.load_manifest('g-cloud-11', 'declaration', 'declaration')
    master_cl.load_messages('g-cloud-11', ['urls', 'advice'])
    master_cl.load_metadata('g-cloud-11', ['copy_services', 'following_framework'])

    master_cl.load_manifest('digital-outcomes-and-specialists-4', 'declaration', 'declaration')
    master_cl.load_manifest('digital-outcomes-and-specialists-4', 'services', 'edit_submission')
    master_cl.load_manifest('digital-outcomes-and-specialists-4', 'services', 'edit_service')
    master_cl.load_manifest('digital-outcomes-and-specialists-4', 'briefs', 'edit_brief')
    master_cl.load_messages('digital-outcomes-and-specialists-4', ['urls'])
    master_cl.load_metadata('digital-outcomes-and-specialists-4', ['copy_services', 'following_framework'])

    master_cl.load_manifest('g-cloud-12', 'services', 'edit_service')
    master_cl.load_manifest('g-cloud-12', 'services', 'edit_submission')
    master_cl.load_manifest('g-cloud-12', 'declaration', 'declaration')
    master_cl.load_messages('g-cloud-12', ['urls', 'advice', 'e-signature'])
    master_cl.load_metadata('g-cloud-12', ['copy_services', 'following_framework'])

    master_cl.load_manifest('digital-outcomes-and-specialists-5', 'declaration', 'declaration')
    master_cl.load_manifest('digital-outcomes-and-specialists-5', 'services', 'edit_submission')
    master_cl.load_manifest('digital-outcomes-and-specialists-5', 'services', 'edit_service')
    master_cl.load_manifest('digital-outcomes-and-specialists-5', 'briefs', 'edit_brief')
    master_cl.load_messages('digital-outcomes-and-specialists-5', ['urls', 'e-signature'])
    master_cl.load_metadata('digital-outcomes-and-specialists-5', ['copy_services', 'following_framework'])

    # seal master_cl in a closure by returning a function which will only ever return an independent copy of it
    return lambda: deepcopy(master_cl)
Esempio n. 33
0
    arguments = docopt(__doc__)

    if bool(arguments.get("--notify-key")) != bool(
            arguments.get("--notify-template-id")):
        raise ValueError(
            "Either specify both --notify-key and --notify-template-id or neither"
        )

    stage = arguments['<stage>']
    data_api_client = DataAPIClient(get_api_endpoint_from_stage(stage),
                                    get_auth_token('api', stage))
    framework_slug = arguments['<framework_slug>']
    framework = data_api_client.get_framework(framework_slug)["frameworks"]
    document_directory = arguments['<documents_directory>']
    content_path = arguments['<content_path>']
    content_loader = ContentLoader(content_path)
    if framework['isESignatureSupported']:
        content_loader.load_messages(framework_slug, ['e-signature'])
        contract_title = content_loader.get_message(
            framework_slug, 'e-signature', 'framework_contract_title')
    else:
        contract_title = 'Framework Agreement'

    dry_run = arguments['--dry-run']
    dm_notify_client = arguments.get("--notify-key") and scripts_notify_client(
        arguments["--notify-key"], logger=logger)

    if dry_run:
        bucket = None
    else:
        bucket = S3(get_bucket_name(stage, "agreements"))
import mock
import unittest
import datetime
from werkzeug.exceptions import NotFound

import app.helpers as helpers
from dmcontent.content_loader import ContentLoader

from dmapiclient import api_stubs

content_loader = ContentLoader('tests/fixtures/content')
content_loader.load_manifest('dos', 'data', 'edit_brief')
questions_builder = content_loader.get_builder('dos', 'edit_brief')


class TestBuyersHelpers(unittest.TestCase):
    def test_get_framework_and_lot(self):
        data_api_client = mock.Mock()
        data_api_client.get_framework.return_value = api_stubs.framework(
            slug='digital-outcomes-and-specialists',
            status='live',
            lots=[
                api_stubs.lot(slug='digital-specialists', allows_brief=True)
            ]
        )

        framework, lot = helpers.buyers_helpers.get_framework_and_lot('digital-outcomes-and-specialists',
                                                                      'digital-specialists',
                                                                      data_api_client)

        assert framework['status'] == "live"
Esempio n. 35
0
    'cloud-support',
]
DOS_LOTS = [
    'digital-outcomes',
    'digital-specialists',
    'user-research-participants',
    'user-research-studios',
]

QUESTION_SETS = ['declaration', 'services']

if __name__ == '__main__':
    arguments = docopt(__doc__)

    content_path = arguments['<DM-content-root-dir>']
    content_loader = ContentLoader(content_path)

    output_dir = arguments['<output-dir>']
    framework_slug = arguments.get('--framework')

    # Generate all files if --question-set not given
    question_sets = [arguments.get('--question-set')
                     ] if arguments.get('--question-set') else QUESTION_SETS

    for question_set in question_sets:
        if question_set == 'declaration':
            output_file = "{}/{}-declaration-questions.csv".format(
                output_dir, framework_slug)
            generate_csv(output_file,
                         framework_slug,
                         content_loader,
Esempio n. 36
0
def _make_content_loader_factory():
    primary_cl = ContentLoader('app/content')
    primary_cl.load_manifest('digital-outcomes-and-specialists', 'briefs',
                             'edit_brief')
    primary_cl.load_manifest('digital-outcomes-and-specialists',
                             'brief-responses', 'output_brief_response')
    primary_cl.load_manifest('digital-outcomes-and-specialists',
                             'brief-responses', 'legacy_output_brief_response')
    primary_cl.load_manifest('digital-outcomes-and-specialists',
                             'clarification_question',
                             'clarification_question')
    primary_cl.load_manifest('digital-outcomes-and-specialists', 'briefs',
                             'award_brief')

    primary_cl.load_manifest('digital-outcomes-and-specialists-2', 'briefs',
                             'edit_brief')
    primary_cl.load_manifest('digital-outcomes-and-specialists-2',
                             'brief-responses', 'output_brief_response')
    primary_cl.load_manifest('digital-outcomes-and-specialists-2',
                             'clarification_question',
                             'clarification_question')
    primary_cl.load_manifest('digital-outcomes-and-specialists-2', 'briefs',
                             'award_brief')

    primary_cl.load_manifest('digital-outcomes-and-specialists-3', 'briefs',
                             'edit_brief')
    primary_cl.load_manifest('digital-outcomes-and-specialists-3',
                             'brief-responses', 'output_brief_response')
    primary_cl.load_manifest('digital-outcomes-and-specialists-3',
                             'clarification_question',
                             'clarification_question')
    primary_cl.load_manifest('digital-outcomes-and-specialists-3', 'briefs',
                             'award_brief')

    primary_cl.load_manifest('digital-outcomes-and-specialists-4', 'briefs',
                             'edit_brief')
    primary_cl.load_manifest('digital-outcomes-and-specialists-4', 'briefs',
                             'display_brief')
    primary_cl.load_manifest('digital-outcomes-and-specialists-4',
                             'brief-responses', 'output_brief_response')
    primary_cl.load_manifest('digital-outcomes-and-specialists-4',
                             'clarification_question',
                             'clarification_question')
    primary_cl.load_manifest('digital-outcomes-and-specialists-4', 'briefs',
                             'award_brief')

    primary_cl.load_manifest('digital-outcomes-and-specialists-5', 'briefs',
                             'edit_brief')
    primary_cl.load_manifest('digital-outcomes-and-specialists-5', 'briefs',
                             'display_brief')
    primary_cl.load_manifest('digital-outcomes-and-specialists-5',
                             'brief-responses', 'output_brief_response')
    primary_cl.load_manifest('digital-outcomes-and-specialists-5',
                             'clarification_question',
                             'clarification_question')
    primary_cl.load_manifest('digital-outcomes-and-specialists-5', 'briefs',
                             'award_brief')

    # seal primary_cl in a closure by returning a function which will only ever return an independent copy of it
    return lambda: deepcopy(primary_cl)
from flask import Blueprint
from dmcontent.content_loader import ContentLoader

main = Blueprint('main', __name__)

content_loader = ContentLoader('app/content')
content_loader.load_manifest('g-cloud-6', 'services', 'edit_service')
content_loader.load_messages('g-cloud-6', ['dates'])

content_loader.load_manifest('g-cloud-7', 'services', 'edit_service')
content_loader.load_manifest('g-cloud-7', 'services', 'edit_submission')
content_loader.load_manifest('g-cloud-7', 'declaration', 'declaration')
content_loader.load_messages('g-cloud-7', ['dates'])

content_loader.load_manifest('digital-outcomes-and-specialists', 'declaration', 'declaration')
content_loader.load_manifest('digital-outcomes-and-specialists', 'services', 'edit_submission')
content_loader.load_manifest('digital-outcomes-and-specialists', 'briefs', 'edit_brief')
content_loader.load_manifest('digital-outcomes-and-specialists', 'brief-responses', 'edit_brief_response')
content_loader.load_manifest('digital-outcomes-and-specialists', 'brief-responses', 'display_brief_response')
content_loader.load_messages('digital-outcomes-and-specialists', ['dates'])

content_loader.load_manifest('digital-service-professionals', 'declaration', 'declaration')
content_loader.load_manifest('digital-service-professionals', 'services', 'edit_submission')
content_loader.load_manifest('digital-service-professionals', 'briefs', 'edit_brief')
content_loader.load_manifest('digital-service-professionals', 'brief-responses', 'edit_brief_response')
content_loader.load_manifest('digital-service-professionals', 'brief-responses', 'display_brief_response')
content_loader.load_messages('digital-service-professionals', ['dates'])

content_loader.load_manifest('digital-marketplace', 'declaration', 'declaration')
content_loader.load_manifest('digital-marketplace', 'services', 'edit_submission')
content_loader.load_manifest('digital-marketplace', 'briefs', 'edit_brief')