Beispiel #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"))
Beispiel #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"))
Beispiel #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')
Beispiel #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"))
Beispiel #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')
Beispiel #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"))
Beispiel #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
        })
Beispiel #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 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)