def get_title(title_ref):
    logger.debug('Start GET titles: {}'.format(title_ref))
    data = db_access.get_title_register(title_ref)
    if data:
        result = {
            'data': data.register_data,
            'title_number': data.title_number,
            'geometry_data': data.geometry_data,
        }
        logger.debug('End GET titles')
        return jsonify(result)
    else:
        logger.debug('End GET titles. Title not found.')
        return TITLE_NOT_FOUND_RESPONSE
    def test_get_title_register_returns_title_data_when_title_not_marked_as_deleted(self):
        title_number = 'title123'
        register_data = {'register': 'data1'}
        geometry_data = {'geometry': 'data2'}
        is_deleted = False
        last_modified = datetime(2015, 9, 10, 12, 34, 56, 123)
        official_copy_data = {'official': 'copy'}
        lr_uprns = ['123', '456']

        self._create_title(title_number, register_data, geometry_data, is_deleted, last_modified, official_copy_data, lr_uprns)

        title = db_access.get_title_register(title_number)
        assert title is not None
        assert title.title_number == title_number
        assert title.register_data == register_data
        assert title.geometry_data == geometry_data
        assert title.is_deleted == is_deleted
        assert title.last_modified.timestamp() == last_modified.timestamp()
        assert title.official_copy_data == official_copy_data
        assert title.lr_uprns == lr_uprns
    def test_get_title_register_returns_none_when_title_marked_as_deleted(self):
        title_number = 'title123'
        self._create_title(title_number, is_deleted=True)

        title = db_access.get_title_register(title_number)
        assert title is None
 def test_get_title_register_returns_none_when_title_not_in_the_db(self):
     assert db_access.get_title_register('non-existing') is None
def _hit_postgresql_with_sample_query():
    # Hitting PostgreSQL database to see if it responds properly
    db_access.get_title_register('non-existing-title')