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

            lcc = LastCreatedCharge()

            lcc.charge_id = 1
            lcc.entry_number = 2
            lcc.registration_date = "abc"

            sess = Session('abc')
            sess.user = user
            sess.last_created_charge = lcc

            g.trace_id = "test_id"

            sess.commit()

            mock_session_api.update_session_data. \
                assert_called_with(sess.session_key,
                                   sess.to_dict(),
                                   Session.session_state_key)
    def test_user_initialisation(self):
        user = User()
        user.id = 'id'
        user.first_name = 'joe'
        user.surname = 'bloggs'
        user.email = 'email'
        user.organisation = 'testorg'
        user.roles = ['testrole']
        user.status = 'Active'
        user.jwt = "MOCK.JWT"

        self.assertIsNotNone(user)
        self.assertEqual(user.id, 'id')
        self.assertEqual(user.first_name, 'joe')
        self.assertEqual(user.surname, 'bloggs')
        self.assertEqual(user.email, 'email')
        self.assertEqual(user.organisation, 'testorg')
        self.assertEqual(user.roles, ['testrole'])
        self.assertEqual(user.status, 'Active')
        self.assertEqual(user.jwt, 'MOCK.JWT')
    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)