Ejemplo n.º 1
0
    def test_post_redirects_when_single_address_chosen(self, session, mock_address_converter):
        with app.test_request_context():
            self.client.set_cookie('localhost', Session.session_cookie_name, 'cookie_value')
            self.mock_session.return_value.llc1_state = LLC1Search()
            self.mock_session.return_value.user.permissions = [Permissions.request_llc1]

            g.session = MagicMock()
            response = MagicMock()
            response.status_code = 201
            session.return_value.post.return_value = response
            selected_address = {
                'address': 'display address',
                'line_1': 'Flat 1',
                'line_2': 'Place',
                'line_3': 'Holder',
                'line_4': 'Flat 1',
                'line_5': 'Flat 1',
                'line_6': 'Flat 1',
                'postcode': 'postcode',
                'uprn': 123456789
            }

            mock_address_converter.to_charge_address.return_value = selected_address

            response = self.client.post(url_for("create_llc1.llc1_set_description"), data={
                'has-address': 'ProvideAddress',
                'selected-address': json.dumps(selected_address),
            })
            self.assertEqual(self.mock_session.return_value.llc1_state.description, 'Flat 1, Place, Holder, Flat 1, '
                                                                                    'Flat 1, Flat 1 postcode')
            self.assert_status(response, 302)
            self.assertRedirects(response, url_for("create_llc1.llc1_get_result"))
Ejemplo n.º 2
0
 def test_post_redirects_when_extent_is_within_migrated_area(
         self, local_authority_service_mock):
     self.client.set_cookie('localhost', Session.session_cookie_name,
                            'cookie_value')
     self.mock_session.return_value.llc1_state = LLC1Search()
     self.mock_session.return_value.user.permissions = [
         Permissions.request_llc1
     ]
     feature_collection = json.dumps({
         "type":
         "FeatureCollection",
         "features": [{
             "geometry": {
                 "type": "Point",
                 "coordinates": [1, 2]
             },
             "properties": None,
             "id": None
         }]
     })
     local_authority_service_mock.return_value.is_extent_within_migrated_area.return_value = True
     response = self.client.post(
         url_for("create_llc1.llc1_set_extent"),
         data={'saved-features': feature_collection})
     self.assert_status(response, 302)
     self.assertRedirects(response,
                          url_for("create_llc1.llc1_get_description"))
Ejemplo n.º 3
0
 def test_post_renders_error_when_no_description(self):
     self.client.set_cookie('localhost', Session.session_cookie_name, 'cookie_value')
     self.mock_session.return_value.llc1_state = LLC1Search()
     self.mock_session.return_value.user.permissions = [Permissions.request_llc1]
     response = self.client.post(url_for("create_llc1.llc1_set_description"),
                                 data={'has-address': 'No', 'charge-geographic-description': ''})
     self.assertStatus(response, 400)
     self.assert_template_used('search_description.html')
Ejemplo n.º 4
0
    def test_get_renders_when_state_ok(self):
        self.client.set_cookie('localhost', Session.session_cookie_name, 'cookie_value')
        self.mock_session.return_value.llc1_state = LLC1Search()
        self.mock_session.return_value.user.permissions = [Permissions.request_llc1]

        response = self.client.get(url_for("create_llc1.llc1_get_description"))
        self.assert_status(response, 200)
        self.assert_template_used("search_description.html")
def create_llc1():
    current_app.logger.info('Create LLC1 endpoint called')
    g.session.llc1_state = LLC1Search()
    g.session.commit()

    current_app.logger.info("Redirecting to: %s",
                            url_for("create_llc1.llc1_get_location"))
    return redirect(url_for("create_llc1.llc1_get_location"))
Ejemplo n.º 6
0
 def test_post_renders_error_with_no_saved_features(self):
     self.client.set_cookie('localhost', Session.session_cookie_name,
                            'cookie_value')
     self.mock_session.return_value.llc1_state = LLC1Search()
     self.mock_session.return_value.user.permissions = [
         Permissions.request_llc1
     ]
     response = self.client.post(url_for("create_llc1.llc1_set_extent"),
                                 data={'saved-features': []})
     self.assertStatus(response, 400)
     self.assert_template_used('search_extent.html')
 def test_post_redirects_when_location_valid(self, search):
     search.return_value = {"test": "object that isn't None"}
     self.client.set_cookie('localhost', Session.session_cookie_name,
                            'cookie_value')
     self.mock_session.return_value.llc1_state = LLC1Search()
     self.mock_session.return_value.user.permissions = [
         Permissions.request_llc1
     ]
     response = self.client.post(url_for("create_llc1.llc1_post_location"),
                                 data={'location': 'Exeter'})
     self.assertStatus(response, 302)
     self.assertRedirects(response, url_for("create_llc1.llc1_get_extent"))
 def test_post_renders_error_when_address_invalid(self, search):
     search.return_value = None
     self.client.set_cookie('localhost', Session.session_cookie_name,
                            'cookie_value')
     self.mock_session.return_value.llc1_state = LLC1Search()
     self.mock_session.return_value.user.permissions = [
         Permissions.request_llc1
     ]
     response = self.client.post(url_for("create_llc1.llc1_post_location"),
                                 data={'location': 'SJHFAkD'})
     self.assertStatus(response, 400)
     self.assert_template_used('search_location.html')
Ejemplo n.º 9
0
    def test_get_no_location_redirects_when_state_ok(self):
        self.client.set_cookie('localhost', Session.session_cookie_name,
                               'cookie_value')
        self.mock_session.return_value.llc1_state = LLC1Search()
        self.mock_session.return_value.user.permissions = [
            Permissions.request_llc1
        ]

        response = self.client.get(
            url_for("create_llc1.llc1_get_extent_no_location"))
        self.assert_status(response, 302)
        self.assertRedirects(response, url_for("create_llc1.llc1_get_extent"))
Ejemplo n.º 10
0
    def test_get_renders_when_state_ok(self, mock_document_service, mock_audit, mock_report_api_service):
        self.client.set_cookie('localhost', Session.session_cookie_name, 'cookie_value')
        self.mock_session.return_value.llc1_state = LLC1Search()

        mock_document_service.return_value.generate.return_value = {
            "document_url": "http://example.com",
            "external_url": "external-url",
            "number_of_charges": 0
        }

        self.mock_session.return_value.user.permissions = [Permissions.request_llc1]

        response = self.client.get(url_for("create_llc1.llc1_get_result"))

        self.assert_status(response, 200)
        self.assert_template_used("search_result.html")
        mock_report_api_service.send_number_of_charges_per_search_data.assert_called_with({
            'date': ANY, 'channel': 'MAINTAIN', 'number_of_charges': 0, 'repeat': False
        })
Ejemplo n.º 11
0
    def test_post_redirects_when_no_single_address_chosen_with_description(self, session):
        with app.test_request_context():
            self.client.set_cookie('localhost', Session.session_cookie_name, 'cookie_value')
            self.mock_session.return_value.llc1_state = LLC1Search()
            self.mock_session.return_value.user.permissions = [Permissions.request_llc1]

            g.session = MagicMock()
            response = MagicMock()
            response.status_code = 201
            session.return_value.post.return_value = response

            response = self.client.post(url_for("create_llc1.llc1_set_description"), data={
                'has-address': 'No',
                'charge-geographic-description': 'This is a valid description',
            })

            self.assertEqual(self.mock_session.return_value.llc1_state.description, 'This is a valid description')
            self.assert_status(response, 302)
            self.assertRedirects(response, url_for("create_llc1.llc1_get_result"))
 def populate_state(self):
     """Populates the add charge from session state."""
     current_app.logger.info(
         "Method called, getting session state from session api")
     response = SessionAPIService.get_session_state(
         self.session_key, Session.session_state_key)
     if response is not None:
         current_app.logger.info("Non-empty session state contents")
         if 'add_charge_state' in response:
             current_app.logger.info("add_charge_state in session state")
             self.add_charge_state = LocalLandChargeItem.from_json(
                 response['add_charge_state'])
         if 'add_lon_charge_state' in response:
             current_app.logger.info(
                 "add_lon_charge_state in session state")
             self.add_lon_charge_state = LightObstructionNoticeItem.from_json(
                 response['add_lon_charge_state'])
         if 'last_created_charge' in response:
             current_app.logger.info("last_created_charge in session state")
             self.last_created_charge = LastCreatedCharge.from_dict(
                 response['last_created_charge'])
         if 'statutory_provision_list' in response:
             current_app.logger.info(
                 "statutory_provision_list in session state")
             self.statutory_provision_list = response[
                 'statutory_provision_list']
         if 'edited_fields' in response:
             current_app.logger.info("edited_fields in session state")
             self.edited_fields = response['edited_fields']
         if 'llc1_state' in response:
             current_app.logger.info("llc1_state in session state")
             self.llc1_state = LLC1Search.from_json(response['llc1_state'])
         if 'redirect_route' in response:
             current_app.logger.info('redirect_route in session state')
             self.redirect_route = response['redirect_route']
         if 'search_extent' in response:
             current_app.logger.info('search_extent in session state')
             self.search_extent = response['search_extent']
         if 'filenames' in response:
             current_app.logger.info('filenames in session state')
             self.filenames = response['filenames']
         if 'previously_selected_address' in response:
             current_app.logger.info(
                 'previously_selected_address in session state')
             self.previously_selected_address = response[
                 'previously_selected_address']
         if 'adding_charge_for_other_authority' in response:
             current_app.logger.info(
                 'adding_charge_for_other_authority in session state')
             self.adding_charge_for_other_authority = response[
                 'adding_charge_for_other_authority']
         if 'submit_token' in response:
             current_app.logger.info('submit token in session state')
             self.submit_token = response['submit_token']
         if 'upload_shapefile_processed' in response:
             current_app.logger.info(
                 'upload_shapefile_processed in session state')
             self.upload_shapefile_processed = response[
                 'upload_shapefile_processed']
         if 'category_details' in response:
             self.category_details = Category.from_dict(
                 response['category_details'])
         if 'category_confirmation' in response:
             self.category_confirmation = response['category_confirmation']
         if 'charge_added_outside_users_authority' in response:
             self.charge_added_outside_users_authority = response[
                 'charge_added_outside_users_authority']
         if 'other_authority_update_permission' in response:
             self.other_authority_update_permission = response[
                 'other_authority_update_permission']
         if 'other_authority_cancel_permission' in response:
             self.other_authority_cancel_permission = response[
                 'other_authority_cancel_permission']
         if 'source_information' in response:
             self.source_information = response['source_information']
         if 'source_information_id' in response:
             self.source_information_id = response['source_information_id']
         if 'send_payment_link_info' in response:
             current_app.logger.info(
                 "send_payment_link_info in session state")
             self.send_payment_link_info = PaymentLink.from_json(
                 response['send_payment_link_info'])
         if 'payment_info' in response:
             current_app.logger.info("payment_info in session state")
             self.payment_info = PaymentInfo.from_json(
                 response['payment_info'])
         if 'search_details' in response:
             self.search_details = SearchDetails.from_json(
                 response['search_details'])
    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)