def test_edit_servient_structure_position_update_success_amend( self, mock_validator, mock_request): self.client.set_cookie('localhost', Session.session_cookie_name, 'cookie_value') self.mock_session.return_value.user.permissions = [ Permissions.vary_lon ] mock_lon = LightObstructionNoticeItem.from_json(get_mock_lon_item()) mock_lon.structure_position_and_dimension[ 'extent-covered'] = 'Part of the extent' mock_lon.structure_position_and_dimension[ 'part-explanatory-text'] = 'northern hedge' self.mock_session.return_value.add_lon_charge_state = mock_lon self.mock_session.return_value.edited_fields = {} mock_validator.validate.return_value.errors = None mock_request.form.get.return_value = "All of the extent" response = self.client.post( url_for('modify_lon.edit_servient_structure_position_post')) structure_position_and_dimension = \ self.mock_session.return_value.add_lon_charge_state.structure_position_and_dimension self.assert_status(response, 302) self.assertEqual(structure_position_and_dimension["extent-covered"], "All of the extent") self.assertEqual( self.mock_session.return_value.edited_fields['structure-position'], "Extent - planned development")
def test_edit_dominant_description_update_success(self, mock_validator, mock_request): self.client.set_cookie('localhost', Session.session_cookie_name, 'cookie_value') self.mock_session.return_value.user.permissions = [ Permissions.vary_lon ] mock_lon = LightObstructionNoticeItem.from_json(get_mock_lon_item()) self.mock_session.return_value.add_lon_charge_state = mock_lon self.mock_session.return_value.edited_fields = { 'charge-address': "Dominant address" } mock_validator.validate.return_value.errors = None mock_request.form = { 'have_address': 'No', 'charge_geographic_description': 'CHANGED' } response = self.client.post( url_for('modify_lon.edit_dominant_building_post')) self.assert_status(response, 302) self.assertEqual( self.mock_session.return_value.add_lon_charge_state.charge_address, '') self.assertEqual( self.mock_session.return_value.add_lon_charge_state. charge_geographic_description, 'CHANGED') self.assertNotIn('charge-address', self.mock_session.return_value.edited_fields) self.assertEqual( self.mock_session.return_value. edited_fields['charge_geographic_description'], 'Dominant address')
def test_edit_dominant_building_extent_update_success( self, mock_validator, mock_request): self.client.set_cookie('localhost', Session.session_cookie_name, 'cookie_value') self.mock_session.return_value.user.permissions = [ Permissions.vary_lon ] mock_lon = LightObstructionNoticeItem.from_json(get_mock_lon_item()) self.mock_session.return_value.add_lon_charge_state = mock_lon self.mock_session.return_value.edited_fields = {} geometry = { 'coordinates': [294230.7392612094, 93185.05361812815], 'type': 'Point' } saved_features = { 'saved-features': json.dumps({'features': [{ 'geometry': geometry }]}) } mock_request.form = saved_features mock_validator.validate.return_value.errors = None response = self.client.post( url_for('modify_lon.edit_dominant_building_extent_post')) self.assert_status(response, 302) self.assertIsNotNone( self.mock_session.return_value.add_lon_charge_state.geometry) self.assertEqual( self.mock_session.return_value.edited_fields['geometry'], "Extent")
def new(): """This will setup state for adding a new land charge and redirect to the starting page.""" g.session.add_lon_charge_state = LightObstructionNoticeItem() # Apply Default Values g.session.add_lon_charge_state.charge_type = LonDefaults.charge_type if g.session.add_charge_state is not None and g.session.add_charge_state.statutory_provision is not None: g.session.add_lon_charge_state.statutory_provision = g.session.add_charge_state.statutory_provision else: g.session.add_lon_charge_state.statutory_provision = LonDefaults.statutory_provision if g.session.add_charge_state is not None and g.session.add_charge_state.instrument is not None: g.session.add_lon_charge_state.instrument = g.session.add_charge_state.instrument else: g.session.add_lon_charge_state.instrument = LonDefaults.instrument g.session.add_lon_charge_state.further_information_location = LonDefaults.further_information_location g.session.add_lon_charge_state.schema_version = SCHEMA_VERSION g.session.payment_info = PaymentInfo() g.session.filenames = None g.session.redirect_route = None g.session.edited_fields = {} g.session.commit() current_app.logger.info("Created new session object: %s", g.session.add_lon_charge_state.to_json()) current_app.logger.info("Redirecting to: %s", url_for("add_lon.get_applicant_info")) return redirect(url_for("add_lon.get_applicant_info"))
def test_edit_lon_land_interest_update_success(self, mock_validator, mock_request): self.client.set_cookie('localhost', Session.session_cookie_name, 'cookie_value') self.mock_session.return_value.user.permissions = [ Permissions.vary_lon ] mock_lon = LightObstructionNoticeItem.from_json(get_mock_lon_item()) self.mock_session.return_value.add_lon_charge_state = mock_lon self.mock_session.return_value.edited_fields = {} mock_validator.return_value.errors = None mock_request.form.get.return_value = "tenant" response = self.client.post( url_for('modify_lon.edit_lon_land_interest_post')) self.assertEqual( self.mock_session.return_value.add_lon_charge_state. servient_land_interest_description, "tenant") self.assertEqual( self.mock_session.return_value. edited_fields['servient-land-interest-description'], "Interest") self.assert_status(response, 302)
def test_edit_servient_structure_height_update_success_amend( self, mock_validator, mock_request): self.client.set_cookie('localhost', Session.session_cookie_name, 'cookie_value') self.mock_session.return_value.user.permissions = [ Permissions.vary_lon ] mock_lon = LightObstructionNoticeItem.from_json(get_mock_lon_item()) mock_lon.structure_position_and_dimension['height'] = '20' mock_lon.structure_position_and_dimension['units'] = 'Metres' self.mock_session.return_value.add_lon_charge_state = mock_lon self.mock_session.return_value.edited_fields = {} mock_validator.validate.return_value.errors = None mock_request.form.get.return_value = "Unlimited height" response = self.client.post( url_for('modify_lon.edit_servient_structure_height_post')) structure_position_and_dimension = \ self.mock_session.return_value.add_lon_charge_state.structure_position_and_dimension self.assert_status(response, 302) self.assertEqual(structure_position_and_dimension["height"], "Unlimited height") self.assertEqual( self.mock_session.return_value. edited_fields['structure-dimension'], "Height - planned development")
def test_cancel_confirm_success(self, mock_service, mock_maintain_api, mock_audit): self.client.set_cookie('localhost', Session.session_cookie_name, 'cookie_value') self.mock_session.return_value.user.permissions = [ Permissions.cancel_lon ] self.mock_session.add_lon_charge_state = LightObstructionNoticeItem() g.session = self.mock_session mock_response = MagicMock() mock_service.return_value.get_by_charge_number.return_value = mock_response mock_response.status_code = 200 mock_response.json.return_value = [{ "item": get_mock_lon_item(), "display_id": "LLC-TST" }] response = self.client.post( url_for('cancel_lon.confirm', charge_id='LLC-TST')) mock_maintain_api.update_charge.assert_called_with( g.session.add_lon_charge_state) mock_audit.audit_event.assert_called_with( 'Cancelling charge', supporting_info={'id': 'LLC-TST'}) self.assert_status(response, 302) self.assertRedirects( response, url_for('cancel_lon.charge_cancelled', charge_id='LLC-TST'))
def test_upload_definitive_certificate_fields(self, mock_service, mock_storage_service, mock_validator, mock_request): self.client.set_cookie('localhost', Session.session_cookie_name, 'cookie_value') self.mock_session.return_value.user.permissions = [ Permissions.vary_lon ] state = LightObstructionNoticeItem() self.mock_session.return_value.add_lon_charge_state = state self.mock_session.return_value.edited_fields = {} expected_expiry_date = datetime.date.today() + relativedelta(years=+21) expected_definitive_date = datetime.date(1, 1, 1) mock_response = MagicMock() mock_response.status_code = 200 mock_response.json.return_value = [{ "item": get_mock_lon_item(), "display_id": "LLC-TST", "cancelled": False }] mock_service.return_value.get_by_charge_number.return_value = mock_response mock_validator.validate.return_value.errors = None mock_request.form.getlist.return_value = ["Definitive Certificate"] mock_request.form.get('definitive_cert_day').return_value = 1 mock_request.form.get('definitive_cert_month').return_value = 1 mock_request.form.get('definitive_cert_year').return_value = 1 mock_request.files.get( 'definitive-certificate-file-input').return_value = True response = self.client.post( url_for('modify_lon.modify_lon_upload_post', charge_id="LLC-TST")) self.assertEqual( self.mock_session.return_value.add_lon_charge_state.expiry_date, expected_expiry_date) self.assertEqual( self.mock_session.return_value.add_lon_charge_state. tribunal_definitive_certificate_date, expected_definitive_date) self.assertEqual( self.mock_session.return_value. edited_fields['tribunal-definitive-certificate-date'], "Tribunal definitive certificate date") self.assertEqual( self.mock_session.return_value.edited_fields['expiry-date'], "Expiry date") self.assert_status(response, 302) self.assertRedirects( response, url_for('modify_lon.modify_lon_details_get', charge_id="LLC-TST"))
def test_add_new(self): self.client.set_cookie('localhost', Session.session_cookie_name, 'cookie_value') self.mock_session.return_value.add_lon_charge_state = LightObstructionNoticeItem() response = self.client.get(url_for('add_lon.new')) self.assert_status(response, 302) self.assertRedirects(response, url_for('add_lon.get_applicant_info')) self.mock_session.return_value.commit.assert_called()
def test_land_interest_get(self): self.client.set_cookie('localhost', Session.session_cookie_name, 'cookie_value') state = LightObstructionNoticeItem() self.mock_session.add_lon_charge_state = state self.mock_session.return_value.user.permissions = [Permissions.add_lon] response = self.client.get(url_for(GET_LAND_INTEREST)) self.assert_status(response, 200) self.assert_template_used(TEMPLATE)
def test_servient_structure_height_get(self): self.client.set_cookie('localhost', Session.session_cookie_name, 'cookie_value') state = LightObstructionNoticeItem() self.mock_session.add_lon_charge_state = state self.mock_session.return_value.user.permissions = [Permissions.add_lon] response = self.client.get(url_for(GET_SERVIENT_STRUCTURE_HEIGHT)) self.assert_status(response, 200) self.assert_template_used(TEMPLATE)
def test_upload_lon_documents_get(self): self.client.set_cookie('localhost', Session.session_cookie_name, 'cookie_value') state = LightObstructionNoticeItem() self.mock_session.add_lon_charge_state = state self.mock_session.return_value.user.permissions = [Permissions.add_lon] response = self.client.get(url_for(GET_UPLOAD_LON_DOCUMENTS)) self.assert_status(response, 200) self.assert_template_used(TEMPLATE)
def test_edit_lon_land_interest_get_with_state(self): self.client.set_cookie('localhost', Session.session_cookie_name, 'cookie_value') self.mock_session.return_value.user.permissions = [ Permissions.vary_lon ] mock_lon = LightObstructionNoticeItem.from_json(get_mock_lon_item()) self.mock_session.return_value.add_lon_charge_state = mock_lon response = self.client.get( url_for('modify_lon.edit_lon_land_interest_get')) self.assert_status(response, 200) self.assert_template_used('lon_land_interest.html')
def test_servient_structure_height_no_select(self, mock_validator): self.client.set_cookie('localhost', Session.session_cookie_name, 'cookie_value') state = LightObstructionNoticeItem() self.mock_session.add_lon_charge_state = state self.mock_session.return_value.user.permissions = [Permissions.add_lon] mock_validator.validate.return_value.errors = ERROR response = self.client.post(url_for(POST_SERVIENT_STRUCTURE_HEIGHT)) self.assert_context('validation_errors', ERROR) self.assert_status(response, 400) self.assert_template_used(TEMPLATE)
def test_land_interest_lender_selected(self, mock_review_router): mock_review_router.get_redirect_url.return_value = url_for( GET_UPLOAD_LON_DOCUMENTS) self.client.set_cookie('localhost', Session.session_cookie_name, 'cookie_value') state = LightObstructionNoticeItem() self.mock_session.add_lon_charge_state = state self.mock_session.return_value.user.permissions = [Permissions.add_lon] data = {'servient-land-interest-description': 'Lender'} response = self.client.post(url_for(POST_LAND_INTEREST), data=data) self.assert_status(response, 302) self.assertRedirects(response, url_for(GET_UPLOAD_LON_DOCUMENTS))
def test_modify_lon_redirect_when_different_id_in_session( self, mock_service): self.client.set_cookie('localhost', Session.session_cookie_name, 'cookie_value') self.mock_session.return_value.user.permissions = [ Permissions.vary_lon ] state = LightObstructionNoticeItem.from_json(get_mock_lon_item()) self.mock_session.return_value.add_lon_charge_state = state response = self.client.get( url_for('modify_lon.modify_lon_upload_get', charge_id=3)) self.assert_status(response, 302)
def test_dominant_building_extent_get(self): self.client.set_cookie('localhost', Session.session_cookie_name, 'cookie_value') state = LightObstructionNoticeItem() self.mock_session.add_lon_charge_state = state self.mock_session.return_value.add_lon_charge_state.charge_address = { "postcode": "EX4 7AN" } self.mock_session.return_value.user.permissions = [Permissions.add_lon] response = self.client.get(url_for(GET_DOMINANT_EXTENT)) self.assert_status(response, 200) self.assert_template_used(TEMPLATE)
def test_servient_structure_position_all_of_the_extent_selected( self, mock_validator, mock_review_router): self.client.set_cookie('localhost', Session.session_cookie_name, 'cookie_value') mock_review_router.get_redirect_url.return_value = url_for( GET_CONFIRMATION) state = LightObstructionNoticeItem() self.mock_session.add_lon_charge_state = state self.mock_session.return_value.user.permissions = [Permissions.add_lon] mock_validator.validate.return_value.errors = None response = self.client.post(url_for(POST_SERVIENT_STRUCTURE_POSITION)) self.assert_status(response, 302) self.assertRedirects(response, url_for(GET_CONFIRMATION))
def test_modify_lon_details_get_with_state(self, mock_service, mock_calc_display_id): self.client.set_cookie('localhost', Session.session_cookie_name, 'cookie_value') self.mock_session.return_value.user.permissions = [ Permissions.vary_lon ] self.mock_session.return_value.add_lon_charge_state = LightObstructionNoticeItem.from_json( get_mock_lon_item()) mock_calc_display_id.return_value = "LLC-TST" response = self.client.get( url_for('modify_lon.modify_lon_details_get', charge_id='LLC-TST')) self.assert_status(response, 200) self.assert_template_used('modify_lon_details.html')
def test_edit_applicant_address_info_get(self): self.client.set_cookie('localhost', Session.session_cookie_name, 'cookie_value') self.mock_session.return_value.user.permissions = [ Permissions.vary_lon ] mock_lon = LightObstructionNoticeItem() self.mock_session.return_value.add_lon_charge_state = mock_lon self.mock_session.add_lon_charge_state.applicant_address = None response = self.client.get( url_for('modify_lon.edit_applicant_info_get')) self.assert_status(response, 200) self.assert_template_used('applicant_info.html')
def test_edit_dominant_building_extent_update_errors(self, mock_validator): self.client.set_cookie('localhost', Session.session_cookie_name, 'cookie_value') self.mock_session.return_value.user.permissions = [ Permissions.vary_lon ] mock_lon = LightObstructionNoticeItem.from_json(get_mock_lon_item()) self.mock_session.return_value.add_lon_charge_state = mock_lon mock_validator.validate.return_value.errors = {"error": "test-error"} response = self.client.post( url_for('modify_lon.edit_dominant_building_extent_post')) self.assert_status(response, 400) self.assert_template_used('dominant_building_extent.html') self.assert_context("validation_errors", {"error": "test-error"})
def test_edit_lon_land_interest_update_errors(self, mock_validator): self.client.set_cookie('localhost', Session.session_cookie_name, 'cookie_value') self.mock_session.return_value.user.permissions = [ Permissions.vary_lon ] self.mock_session.return_value.add_lon_charge_state = LightObstructionNoticeItem( ) mock_validator.return_value.errors = {"error": "test-error"} response = self.client.post( url_for('modify_lon.edit_lon_land_interest_post')) self.assert_status(response, 400) self.assert_template_used('lon_land_interest.html') self.assert_context("validation_errors", {"error": "test-error"})
def test_upload_lon_documents_no_select(self, mock_validator): self.client.set_cookie('localhost', Session.session_cookie_name, 'cookie_value') state = LightObstructionNoticeItem() self.mock_session.add_lon_charge_state = state self.mock_session.return_value.user.permissions = [Permissions.add_lon] mock_validator.validate.return_value.errors = { 'certificate': ['Choose one'] } response = self.client.post(url_for(POST_UPLOAD_LON_DOCUMENTS)) self.assert_context('validation_errors', {'certificate': ['Choose one']}) self.assert_status(response, 400) self.assert_template_used(TEMPLATE)
def get_lon_by_charge_id(charge_id, local_land_charge_service): validate_charge_id(charge_id) current_app.logger.info("Retrieving charge information from charge_id='{}'".format(charge_id)) response = local_land_charge_service.get_by_charge_number(charge_id) if response.status_code == 404: current_app.logger.info("Search service reports '{}' not found - Returning error".format(charge_id)) raise ApplicationError(404) response.raise_for_status() charge_item = LightObstructionNoticeItem.from_json(response.json()[0]['item']) display_id = response.json()[0]['display_id'] current_app.logger.info("Retrieved charge for local_land_charge='{}'".format(charge_id)) return display_id, charge_item
def test_modify_lon_details_cancel_changes(self, mock_service): self.client.set_cookie('localhost', Session.session_cookie_name, 'cookie_value') self.mock_session.return_value.user.permissions = [ Permissions.vary_lon ] self.mock_session.return_value.add_lon_charge_state = LightObstructionNoticeItem( ) self.mock_session.return_value.edited_fields = { "test-change": "test-change" } response = self.client.get( url_for('modify_lon.clear_lon_changes', charge_id='LLC-TST')) self.assert_status(response, 302) self.assertEqual(self.mock_session.return_value.edited_fields, {}) self.assertIsNone(self.mock_session.return_value.add_lon_charge_state)
def test_payment_method_get(self): self.client.set_cookie('localhost', Session.session_cookie_name, 'cookie_value') state = LightObstructionNoticeItem() self.mock_session.return_value.add_lon_charge_state = state self.mock_session.return_value.user.permissions = [Permissions.add_lon] payment_info = { 'payment_method': 'govuk', 'payment_ref': 'test_reference', 'no_payment_notes': '' } self.mock_session.payment_info = payment_info response = self.client.get(url_for('add_lon.get_payment_method')) self.assert_status(response, 200) self.assert_template_used('payment_method.html')
def test_edit_lon_land_interest_other_missing_details( self, mock_render_template, mock_validator, mock_request): self.client.set_cookie('localhost', Session.session_cookie_name, 'cookie_value') self.mock_session.return_value.user.permissions = [ Permissions.vary_lon ] mock_lon = LightObstructionNoticeItem.from_json(get_mock_lon_item()) self.mock_session.return_value.add_lon_charge_state = mock_lon self.mock_session.return_value.edited_fields = {} mock_request.form.get.side_effect = ["Other", ""] mock_validator.return_value.errors = {"error": "test-error"} mock_render_template.return_value = "Template was called" response = self.client.post( url_for('modify_lon.edit_lon_land_interest_post')) self.assert_status(response, 400) mock_render_template.assert_called()
def test_edit_applicant_info_update_success(self, mock_validator, mock_converter, mock_request): self.client.set_cookie('localhost', Session.session_cookie_name, 'cookie_value') self.mock_session.return_value.user.permissions = [ Permissions.vary_lon ] mock_lon = LightObstructionNoticeItem.from_json(get_mock_lon_item()) mock_edited_name = "Test" mock_edited_address = { "line-1": "street", "line-2": "town", "postcode": "postcode", "country": "country" } self.mock_session.return_value.add_lon_charge_state = mock_lon self.mock_session.return_value.edited_fields = {} mock_validator.validate.return_value.errors = None mock_request.form.get.return_value = mock_edited_name mock_converter.condense_address.return_value = mock_edited_address response = self.client.post( url_for('modify_lon.edit_applicant_info_post')) self.assert_status(response, 302) self.assertEqual( self.mock_session.return_value.add_lon_charge_state.applicant_name, mock_edited_name) self.assertEqual( self.mock_session.return_value.add_lon_charge_state. applicant_address, mock_edited_address) self.assertEqual( self.mock_session.return_value.edited_fields['applicant-name'], "Name") self.assertEqual( self.mock_session.return_value.edited_fields['applicant-address'], "Address")
def test_modify_land_charge_confirm(self, mock_audit, mock_maintain_api_service): self.client.set_cookie('localhost', Session.session_cookie_name, 'cookie_value') lon = LightObstructionNoticeItem() self.mock_session.return_value.user.permissions = [ Permissions.vary_lon ] self.mock_session.return_value.add_lon_charge_state = lon self.mock_session.return_value.edited_fields = { "test-change": "test-change" } response = self.client.post( url_for('modify_lon.modify_land_charge_confirm', charge_id='LLC-TST')) self.assert_status(response, 302) self.assertIsNone(self.mock_session.return_value.edited_fields) self.assertIsNone(self.mock_session.return_value.add_lon_charge_state) mock_audit.audit_event.assert_called_with( "Vary request submitted", supporting_info={'id': 'LLC-TST'}) mock_maintain_api_service.update_charge.assert_called_with(lon)
from maintain_frontend import main from flask import url_for from flask_testing import TestCase from unit_tests.utilities import Utilities from unittest.mock import patch from maintain_frontend.dependencies.session_api.session import Session from maintain_frontend.constants.permissions import Permissions from maintain_frontend.models import LightObstructionNoticeItem import json ADD_CHARGE_STATE = LightObstructionNoticeItem() EDITED_FIELDS = [] FILENAMES = {} VALID_PERMISSIONS = [Permissions.add_lon] INVALID_PERMISSIONS = [] class TestReviewLON(TestCase): def create_app(self): Utilities.mock_session_cookie_flask_test(self) return main.app def setUp(self): main.app.config['Testing'] = True main.app.config['WTF_CSRF_ENABLED'] = False @patch('maintain_frontend.add_lon.review.ReviewMap') def test_get(self, mock_review_map): """Should set the redirect_route in session, and render the expected template with expected objects.""" self.client.set_cookie('localhost', Session.session_cookie_name,