Skip to content

Commit

Permalink
Upgrade dmutils to 10.2.0
Browse files Browse the repository at this point in the history
The entirety of the changes in this commit are related to the 10.0.0
change.

Crown-Commercial-Service/digitalmarketplace-utils#182
  • Loading branch information
robyoung committed Oct 16, 2015
1 parent 0c14c95 commit 9f81a53
Show file tree
Hide file tree
Showing 13 changed files with 36 additions and 39 deletions.
12 changes: 3 additions & 9 deletions app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,9 @@
search_api_client = apiclient.SearchAPIClient()
feature_flags = flask_featureflags.FeatureFlag()

questions_loader = ContentLoader(
"app/content/frameworks/g-cloud-6/manifests/search_filters.yml",
"app/content/frameworks/g-cloud-6/questions/services/"
)

service_questions_loader = ContentLoader(
"app/content/frameworks/g-cloud-6/manifests/display_service.yml",
"app/content/frameworks/g-cloud-6/questions/services/"
)
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')


def create_app(config_name):
Expand Down
16 changes: 12 additions & 4 deletions app/helpers/search_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def clean_request_args(request_args, lot_filters):
return clean_args


def group_request_filters(request_filters, content_loader):
def group_request_filters(request_filters, content_builder):
"""Groups filters using ','/& according to question type.
* Questions of type "radios" result in OR filters - there's only one
Expand All @@ -94,7 +94,7 @@ def group_request_filters(request_filters, content_loader):
"""
filter_query = {}
for key, values in request_filters.lists():
if content_loader.get_question(key).get("type") == 'radios':
if is_radio_type(content_builder, key):
filter_query[key] = ','.join(values)
elif len(values) == 1:
filter_query[key] = values[-1]
Expand All @@ -104,6 +104,14 @@ def group_request_filters(request_filters, content_loader):
return filter_query


def is_radio_type(content_builer, key):
if key == 'lot':
return True

question = content_builer.get_question(key) or {}
return question.get('type') == 'radios'


def replace_g5_search_dots(keywords_query):
"""Replaces '.' with '-' in G5 service IDs to support old ID search format."""

Expand All @@ -114,7 +122,7 @@ def replace_g5_search_dots(keywords_query):
)


def build_search_query(request, lot_filters, content_loader):
def build_search_query(request, lot_filters, content_builder):
"""Match request args with known filters.
Removes any unknown query parameters, and will only keep `page`, `q`
Expand All @@ -132,7 +140,7 @@ def build_search_query(request, lot_filters, content_loader):
if 'q' in query:
query['q'] = replace_g5_search_dots(query['q'])

return group_request_filters(query, content_loader)
return group_request_filters(query, content_builder)


def query_args_for_pagination(args):
Expand Down
11 changes: 5 additions & 6 deletions app/main/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
from dmutils.formats import LOTS

from . import main
from .. import questions_loader
from .. import service_questions_loader
from ..presenters.search_presenters import (
filters_for_lot,
set_filter_states,
Expand All @@ -29,7 +27,7 @@
)

from ..exceptions import AuthException
from .. import search_api_client, data_api_client
from .. import search_api_client, data_api_client, content_loader


@main.route('/')
Expand Down Expand Up @@ -135,7 +133,7 @@ def get_service_by_id(service_id):
service_data = service['services']
service_view_data = Service(
service_data,
service_questions_loader.get_builder().filter(
content_loader.get_builder('g-cloud-6', 'display_service').filter(
service_data
)
)
Expand Down Expand Up @@ -175,13 +173,14 @@ def redirect_search():

@main.route('/g-cloud/search')
def search():
content_builder = content_loader.get_builder('g-cloud-6', 'search_filters')
filters = filters_for_lot(
get_lot_from_request(request),
questions_loader.get_builder()
content_builder
)

response = search_api_client.search_services(
**build_search_query(request, filters, questions_loader)
**build_search_query(request, filters, content_builder)
)

search_results_obj = SearchResults(response)
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ requests==2.5.1
inflection==0.2.1
pyyaml==3.11
git+https://github.com/madzak/[email protected]#egg=python-json-logger==v0.1.3
git+https://github.com/alphagov/digitalmarketplace-utils.git@8.3.0#egg=digitalmarketplace-utils==8.3.0
git+https://github.com/alphagov/digitalmarketplace-utils.git@10.2.0#egg=digitalmarketplace-utils==10.2.0

# Required for SNI to work in requests
pyOpenSSL==0.14
Expand Down
File renamed without changes.
7 changes: 3 additions & 4 deletions tests/unit/test_search_presenters.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@
from app.presenters.search_presenters import filters_for_lot, set_filter_states


questions_builder = ContentLoader(
"tests/fixtures/g6_questions/manifest.yml",
"tests/fixtures/g6_questions/data/"
).get_builder()
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():
Expand Down
7 changes: 2 additions & 5 deletions tests/unit/test_search_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,12 @@
from app.presenters.search_results import SearchResults
from app.presenters.search_summary import SearchSummary, \
SummaryRules, SummaryFragment
from dmutils.content_loader import ContentLoader
from app import content_loader


filter_groups = filters_for_lot(
"saas",
ContentLoader(
"app/content/frameworks/g-cloud-6/manifests/search_filters.yml",
"app/content/frameworks/g-cloud-6/questions/services/"
).get_builder()
content_loader.get_builder('g-cloud-6', 'search_filters')
)


Expand Down
20 changes: 10 additions & 10 deletions tests/unit/test_service_presenters.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from app.presenters.service_presenters import (
Service, Attribute, Meta, lowercase_first_character_unless_part_of_acronym
)
from app import service_questions_loader
from app import content_loader


def _get_fixture_data():
Expand All @@ -24,7 +24,7 @@ def setUp(self):
self.fixture = _get_fixture_data()
self.fixture = self.fixture['services']
self.service = Service(
self.fixture, service_questions_loader.get_builder()
self.fixture, content_loader.get_builder('g-cloud-6', 'display_service')
)

def tearDown(self):
Expand All @@ -42,17 +42,17 @@ def test_lot_attribute_is_set(self):

def test_Service_works_if_supplierName_is_not_set(self):
del self.fixture['supplierName']
self.service = Service(self.fixture, service_questions_loader.get_builder())
self.service = Service(self.fixture, content_loader.get_builder('g-cloud-6', 'display_service'))
self.assertFalse(hasattr(self.service, 'supplierName'))

def test_Service_works_if_serviceFeatures_is_not_set(self):
del self.fixture['serviceFeatures']
self.service = Service(self.fixture, service_questions_loader.get_builder())
self.service = Service(self.fixture, content_loader.get_builder('g-cloud-6', 'display_service'))
self.assertFalse(hasattr(self.service, 'features'))

def test_Service_works_if_serviceBenefits_is_not_set(self):
del self.fixture['serviceBenefits']
self.service = Service(self.fixture, service_questions_loader.get_builder())
self.service = Service(self.fixture, content_loader.get_builder('g-cloud-6', 'display_service'))
self.assertFalse(hasattr(self.service, 'benefits'))

def test_features_attributes_are_correctly_set(self):
Expand All @@ -65,7 +65,7 @@ def test_benefits_attributes_are_correctly_set(self):

def test_attributes_are_correctly_set(self):
service = Service(
self.fixture, service_questions_loader.get_builder()
self.fixture, content_loader.get_builder('g-cloud-6', 'display_service')
)
self.assertEquals(
service.attributes[0]['name'],
Expand All @@ -82,15 +82,15 @@ def test_attributes_are_correctly_set(self):

def test_the_support_attribute_group_is_not_there_if_no_attributes(self):
del self.fixture['openStandardsSupported']
service = Service(self.fixture, service_questions_loader.get_builder())
service = Service(self.fixture, content_loader.get_builder('g-cloud-6', 'display_service'))
for group in service.attributes:
if group['name'] == 'Open standards':
self.fail("Support group should not be found")

def test_only_attributes_with_a_valid_type_are_added_to_groups(self):
invalidValue = (u'Manuals provided', u'CMS training')
self.fixture['onboardingGuidance'] = invalidValue
service = Service(self.fixture, service_questions_loader.get_builder())
service = Service(self.fixture, content_loader.get_builder('g-cloud-6', 'display_service'))
for group in service.attributes:
if (
(group['name'] == 'External interface protection') and
Expand All @@ -99,7 +99,7 @@ def test_only_attributes_with_a_valid_type_are_added_to_groups(self):
self.fail("Attribute with tuple value should not be in group")

def test_attributes_with_assurance_in_the_fields_add_it_correctly(self):
service = Service(self.fixture, service_questions_loader.get_builder())
service = Service(self.fixture, content_loader.get_builder('g-cloud-6', 'display_service'))
for group in service.attributes:
if group['name'] == 'Data-in-transit protection':
for row in group['rows']:
Expand All @@ -119,7 +119,7 @@ def test_attributes_with_assurance_in_the_fields_add_it_correctly(self):
)

def test_attributes_with_assurance_for_a_list_value_has_a_caveat(self):
service = Service(self.fixture, service_questions_loader.get_builder())
service = Service(self.fixture, content_loader.get_builder('g-cloud-6', 'display_service'))
for group in service.attributes:
if group['name'] == 'Asset protection and resilience':
for row in group['rows']:
Expand Down

0 comments on commit 9f81a53

Please sign in to comment.