Example #1
0
    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)
Example #2
0
    def test_edit_servient_structure_position_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.validate.return_value.errors = {"error": "test-error"}

        response = self.client.post(
            url_for('modify_lon.edit_servient_structure_position_post'))

        self.assert_status(response, 400)
        self.assert_template_used('servient_structure_position.html')
        self.assert_context("validation_errors", {"error": "test-error"})
Example #3
0
    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')
Example #4
0
    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)
Example #5
0
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,
    def test_upload_lon_documents_no_errors(self, mock_upload_func,
                                            mock_validator,
                                            mock_review_router):
        with main.app.test_request_context():
            self.client.set_cookie('localhost', Session.session_cookie_name,
                                   'cookie_value')

            mock_review_router.get_redirect_url.return_value = url_for(
                GET_SERVIENT_STRUCTURE_HEIGHT)
            expected_filenames = {
                "form_a": 'test1.pdf',
                "temporary_lon_cert": 'test2.pdf',
                "definitive_lon_cert": 'test3.pdf'
            }

            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_UPLOAD_LON_DOCUMENTS),
                                        buffered=True,
                                        content_type='multipart/form-data',
                                        data=dict({
                                            'form-a-file-input':
                                            (BytesIO(b'a'), 'test1.pdf'),
                                            'temporary-lon-cert-file-input':
                                            (BytesIO(b'a'), 'test2.pdf'),
                                            'definitive-lon-cert-file-input':
                                            (BytesIO(b'a'), 'test3.pdf'),
                                            'certificate': [
                                                'Definitive LON certificate',
                                                'Temporary LON certificate'
                                            ],
                                            'definitive_cert_year':
                                            '2012',
                                            'definitive_cert_month':
                                            '12',
                                            'definitive_cert_day':
                                            '24',
                                            'temp_cert_year':
                                            '2003',
                                            'temp_cert_month':
                                            '2',
                                            'temp_cert_day':
                                            '1',
                                            'temp_expiry_year':
                                            '2006',
                                            'temp_expiry_month':
                                            '5',
                                            'temp_expiry_day':
                                            '4'
                                        }))

            self.assert_status(response, 302)
            self.assertRedirects(response,
                                 url_for(GET_SERVIENT_STRUCTURE_HEIGHT))
            self.assertEqual(self.mock_session.return_value.filenames,
                             expected_filenames)
 def build_session():
     g.session = MagicMock()
     g.session.add_lon_charge_state = LightObstructionNoticeItem()
     g.session.edited_fields = {}
     g.trace_id = 'some trace id'
    def test_value_set(self):
        search_extent_geo = {
            'features': [{
                'geometry': {
                    'coordinates': [[[-378838.7455502291, 6966202.685233321],
                                     [159887.69930341933, 6965138.008464836],
                                     [177987.20436767233, 6568013.573819755],
                                     [-456560.1496496685, 6562690.189977327],
                                     [-378838.7455502291, 6966202.685233321]]]
                }
            }]
        }

        category_obj = Category(name="top-level",
                                display_name="Top Level",
                                sub_categories=[],
                                parent=None,
                                statutory_provisions=[],
                                instruments=[])

        add_lon_charge_state_obj = LightObstructionNoticeItem()
        llc1_state_obj = LLC1Search()
        last_created_charge_obj = LastCreatedCharge()

        with main.app.test_request_context():
            user = User()
            user.id = 'id'
            user.first_name = 'joe'
            user.surname = 'bloggs'
            user.organisation = 'testorg'
            user.roles = ['testrole']
            user.status = 'Active'
            user.email = 'username'

            state = LocalLandChargeItem()

            state.statutory_provision = "test_provision"
            state.charge_geographic_description = "test_geo_location"
            state.expiry_date = date(2011, 1, 1)
            state.further_information_location = "test_fi_location"
            state.further_information_reference = "test_fi_reference"

            sess = Session('abc')
            sess.user = user
            sess.add_charge_state = state
            sess.redirect_route = 'some route for redirection'
            sess.two_factor_authentication_passed = True
            sess.two_factor_authentication_code = 123
            sess.two_factor_authentication_redirect_url = 'redirect url'
            sess.two_factor_authentication_generation_time = 'generation time'
            sess.two_factor_authentication_invalid_attempts = 0

            sess.add_lon_charge_state = add_lon_charge_state_obj
            sess.llc1_state = llc1_state_obj
            sess.last_created_charge = last_created_charge_obj
            sess.statutory_provision_list = 'statutory provision list'
            sess.edited_fields = ['field']
            sess.search_extent = search_extent_geo
            sess.filenames = {
                'form_a': '',
                'temporary_lon_cert': '',
                'definitive_lon_cert': ''
            }
            sess.previously_selected_address = {
                "address": "previously selected address"
            }
            sess.adding_charge_for_other_authority = False
            sess.submit_token = 'a submit token'
            sess.category_details = category_obj
            sess.category_confirmation = True
            sess.upload_shapefile_processed = True
            sess.charge_added_outside_users_authority = True
            sess.other_authority_update_permission = True
            sess.other_authority_cancel_permission = True

            g.trace_id = "test_id"

            self.assertIsNotNone(sess)

            result = sess.to_dict()

            self.assertEqual(result['add_charge_state']['statutory-provision'],
                             "test_provision")
            self.assertEqual(
                result['add_charge_state']['charge-geographic-description'],
                "test_geo_location")
            self.assertEqual(result['add_charge_state']['expiry-date'],
                             "2011-01-01")
            self.assertEqual(
                result['add_charge_state']['further-information-location'],
                "test_fi_location")
            self.assertEqual(
                result['add_charge_state']['further-information-reference'],
                "test_fi_reference")
            self.assertEqual(result['redirect_route'],
                             'some route for redirection')
            self.assertEqual(result['add_lon_charge_state'],
                             add_lon_charge_state_obj.to_json())
            self.assertEqual(result['llc1_state'], llc1_state_obj.to_json())
            self.assertEqual(result['last_created_charge'],
                             last_created_charge_obj.__dict__)
            self.assertEqual(result['statutory_provision_list'],
                             'statutory provision list')
            self.assertEqual(result['edited_fields'], ['field'])
            self.assertEqual(result['search_extent'], search_extent_geo)
            self.assertEqual(result['filenames'], {
                'form_a': '',
                'temporary_lon_cert': '',
                'definitive_lon_cert': ''
            })
            self.assertEqual(result['previously_selected_address'],
                             {"address": "previously selected address"})
            self.assertEqual(result['submit_token'], 'a submit token')
            self.assertEqual(result['category_details'],
                             category_obj.to_json())
            self.assertEqual(result['category_confirmation'], True)
            self.assertEqual(result['upload_shapefile_processed'], True)
            self.assertEqual(result['charge_added_outside_users_authority'],
                             True)
            self.assertEqual(result['other_authority_update_permission'], True)
            self.assertEqual(result['other_authority_cancel_permission'], True)

            two_factor_authentication_result = sess.two_factor_authentication_to_dict(
            )

            self.assertEqual(
                two_factor_authentication_result[
                    'two_factor_authentication_passed'], True)
            self.assertEqual(
                two_factor_authentication_result[
                    'two_factor_authentication_code'], 123)
            self.assertEqual(
                two_factor_authentication_result[
                    'two_factor_authentication_redirect_url'], 'redirect url')
            self.assertEqual(
                two_factor_authentication_result[
                    'two_factor_authentication_generation_time'],
                'generation time')
            self.assertEqual(
                two_factor_authentication_result[
                    'two_factor_authentication_invalid_attempts'], 0)