def post_search_law(): if g.session.add_charge_state is None or g.session.add_charge_state.charge_type is None: current_app.logger.info("Redirecting to: %s", url_for("add_land_charge.new")) return redirect(url_for("add_land_charge.new")) if 'legislation-nojs' in request.form: provision = request.form['legislation-nojs'].strip() elif 'legislation' in request.form: provision = request.form['legislation'].strip() else: provision = '' provisions = CategoryService.get_all_stat_provs() validation_errors = StatutoryProvisionsValidator.validate(provision, provisions) if validation_errors.errors: current_app.logger.warning("Validation errors occurred") return render_template('search_law.html', provisions=provisions, current_provision=provision, validation_errors=validation_errors.errors, validation_summary_heading=validation_errors.summary_heading_text), 400 g.session.add_charge_state.statutory_provision = provision g.session.category_confirmation = False g.session.commit() return where_to_next()
def test_get_top_level_permissions(self, mock_current_app): with main.app.test_request_context(): g.requests = MagicMock() g.session = MagicMock() g.session.user.permissions = ["TEST-PERMISSION"] response = MagicMock() response.status_code = 200 response.json.return_value = [{ "permission": "TEST-PERMISSION", "display-name": "Test 1", "name": "test-1" }, { "permission": None, "display-name": "Test 2", "name": "test-2" }] g.requests.get.return_value = response response = CategoryService.get_categories() self.assertEqual(2, len(response)) self.assertEqual("test-1", response[0]['name']) self.assertEqual("Test 1", response[0]['display']) self.assertEqual("test-2", response[1]['name']) self.assertEqual("Test 2", response[1]['display']) g.requests.get.assert_called_with("{}/categories".format('abc')) mock_current_app.logger.info.assert_called()
def search_law(): if g.session.add_charge_state is None or g.session.add_charge_state.charge_type is None: current_app.logger.info("Redirecting to: %s", url_for("add_land_charge.new")) return redirect(url_for("add_land_charge.new")) provisions = CategoryService.get_all_stat_provs() current_app.logger.info("Displaying page 'search_law.html'") return render_template('search_law.html', provisions=provisions)
def get_all_legal_document(): if g.session.add_charge_state is None or g.session.add_charge_state.charge_type is None: current_app.logger.info("Redirecting to: %s", url_for("add_land_charge.new")) return redirect(url_for("add_land_charge.new")) instruments = CategoryService.get_all_instruments() current_app.logger.info("Displaying page 'instruments.html'") return render_template('instruments.html', instruments=instruments)
def post_sub_category(): if g.session.add_charge_state is None or g.session.add_charge_state.charge_type is None: current_app.logger.info("Redirecting to: %s", url_for("add_land_charge.new")) return redirect(url_for("add_land_charge.new")) category = request.form.get('charge-sub-category') current_app.logger.info("Running validation") validation_errors = ChargeSubCategoryValidator.validate(category) if validation_errors.errors: current_app.logger.warning("Validation errors occurred") category_info = CategoryService.get_category_parent_info( g.session.category_details.name) return render_template('sub_categories.html', validation_errors=validation_errors.errors, categories=category_info.sub_categories, parent=category_info.display_name.lower(), validation_summary_heading=validation_errors. summary_heading_text), 400 if category == "I don't know the charge category": return redirect(url_for('add_land_charge.get_subcategory_not_known')) current_app.logger.info( "Updating session object with charge sub-category: %s", category) g.session.add_charge_state.charge_sub_category = category category_info = CategoryService.get_sub_category_info( g.session.category_details.name, category) g.session.category_details = category_info g.session.commit() if len(category_info.sub_categories) > 0: current_app.logger.info("Displaying page 'sub_categories.html'") return render_template('sub_categories.html', categories=category_info.sub_categories, parent=category_info.display_name.lower()) setup_session_for_instruments_and_provision(category_info) return where_to_next(category_info)
def get_charge_type(): if g.session.add_charge_state is None: current_app.logger.info("Redirecting to: %s", url_for("add_land_charge.new")) return redirect(url_for("add_land_charge.new")) reset_category_info() categories = CategoryService.get_categories() current_app.logger.info("Displaying page 'charge_type.html'") return render_template('charge_type.html', categories=categories, submit_url=url_for('add_land_charge.post_charge_type'))
def test_get_sub_category_info_permission(self, mock_current_app): with main.app.test_request_context(): g.requests = MagicMock() g.session = MagicMock() g.session.user.permissions = [ "parent-permission", "sub-permission" ] response = MagicMock() response.status_code = 200 response.json.return_value = { "permission": "parent-permission", "display-name": "Test 1", "name": "test-1", "sub-categories": [{ "name": "sub name", "display-name": "sub display", "permission": "sub-permission" }], "statutory-provisions": ["test stat prov"], "instruments": ["test instrument"], "parent": None } g.requests.get.return_value = response category = CategoryService.get_sub_category_info("test", "abc") self.assertIsNotNone(category) self.assertEqual("test-1", category.name) self.assertEqual("Test 1", category.display_name) self.assertEqual(1, len(category.sub_categories)) self.assertEqual("sub name", category.sub_categories[0].name) self.assertEqual("sub display", category.sub_categories[0].display_name) self.assertEqual(1, len(category.statutory_provisions)) self.assertEqual("test stat prov", category.statutory_provisions[0]) self.assertEqual(1, len(category.instruments)) self.assertEqual("test instrument", category.instruments[0]) g.requests.get.assert_called_with( "{}/categories/test/sub-categories/abc".format('abc')) mock_current_app.logger.info.assert_called()
def test_get_all_instruments(self, mock_current_app): with main.app.test_request_context(): g.requests = MagicMock() response = MagicMock() response.status_code = 200 response.json.return_value = ["test instrument"] g.requests.get.return_value = response instruments = CategoryService.get_all_instruments() self.assertIsNotNone(instruments) self.assertEqual(1, len(instruments)) self.assertEqual("test instrument", instruments[0]) g.requests.get.assert_called_with("abc/instruments") mock_current_app.logger.info.assert_called()
def test_get_all_stat_provs(self, mock_current_app): with main.app.test_request_context(): g.requests = MagicMock() response = MagicMock() response.status_code = 200 response.json.return_value = ["test stat prov"] g.requests.get.return_value = response stat_provs = CategoryService.get_all_stat_provs() self.assertIsNotNone(stat_provs) self.assertEqual(1, len(stat_provs)) self.assertEqual("test stat prov", stat_provs[0]) g.requests.get.assert_called_with( "{}/statutory-provisions".format('abc'), params={'selectable': True}) mock_current_app.logger.info.assert_called()
def post_charge_type(): current_app.logger.info("Endpoint called with charge-type = '%s'", request.form['charge-type'] if 'charge-type' in request.form else None) if g.session.add_charge_state is None: current_app.logger.info("Redirecting to: %s", url_for("add_land_charge.new")) return redirect(url_for("add_land_charge.new")) charge_type = request.form.get('charge-type') current_app.logger.info("Running validation") validation_errors = ChargeTypeValidator.validate(charge_type) if validation_errors.errors: current_app.logger.warning("Validation errors occurred") categories = CategoryService.get_categories() return render_template( 'charge_type.html', categories=categories, validation_errors=validation_errors.errors, validation_summary_heading=validation_errors.summary_heading_text, submit_url=url_for('add_land_charge.post_charge_type') ), 400 current_app.logger.info( "Updating session object with charge type: %s", charge_type) if g.session.add_charge_state.charge_type is not None and g.session.add_charge_state.charge_type != charge_type: current_app.logger.info("Clearing session - charge type changed") if g.session.adding_charge_for_other_authority: authority = g.session.add_charge_state.originating_authority else: authority = g.session.user.organisation g.session.add_charge_state = LocalLandChargeItem() g.session.add_charge_state.originating_authority = authority g.session.add_charge_state.statutory_provision = 'Not provided' g.session.add_charge_state.schema_version = SCHEMA_VERSION g.session.redirect_route = None g.session.add_charge_state.charge_type = charge_type g.session.commit() return redirect(url_for('add_land_charge.get_sub_category'))
def get_sub_category(): if g.session.add_charge_state is None or g.session.add_charge_state.charge_type is None: current_app.logger.info("Redirecting to: %s", url_for("add_land_charge.new")) return redirect(url_for("add_land_charge.new")) reset_sub_category_info() current_category = g.session.add_charge_state.charge_type category_info = CategoryService.get_category_parent_info(current_category) g.session.category_details = category_info g.session.commit() if len(category_info.sub_categories) > 0: current_app.logger.info("Displaying page 'sub_categories.html'") return render_template('sub_categories.html', categories=category_info.sub_categories, parent=category_info.display_name.lower()) setup_session_for_instruments_and_provision(category_info) return where_to_next(category_info)