def convert_geographic_to_db(value, context): if isinstance(value, list): regions = value elif value: regions = [value] else: regions = [] return GeoCoverageType.get_instance().form_to_db(regions)
def convert_geographic_to_db(value, context): from ckanext.dgu.schema import GeoCoverageType if isinstance(value, list): regions = value elif value: regions = [value] else: regions = [] return GeoCoverageType.get_instance().form_to_db(regions)
def test_backward_compatibility_of_adding_an_extra_option(self): """ Test that omitting the last character from the bit-string encoding is equivelant to having the character set at '0'. This ensures backward compatibility when reading from the db. """ # str_, form, db expected_data = [ ('England', ['england'], u'100000: England'), ('England and Wales', ['england', 'wales'], u'101000: England, Wales'), ('Scotland', ['scotland'], u'010000: Scotland'), ('Northern Ireland', ['northern_ireland'], u'000100: Northern Ireland'), ('GB', ['england', 'scotland', 'wales'], u'111000: Great Britain (England, Scotland, Wales)'), ('UK', ['england', 'scotland', 'wales', 'northern_ireland'], u'111100: United Kingdom (England, Scotland, Wales, Northern Ireland)'), ] for str_, form, db in expected_data: result_form = GeoCoverageType.get_instance().db_to_form(db) assert_equal(result_form, form)
def test_backward_compatibility_of_adding_an_extra_option(self): """ Test that omitting the last character from the bit-string encoding is equivelant to having the character set at '0'. This ensures backward compatibility when reading from the db. """ # str_, form, db expected_data = [ ("England", ["england"], u"100000: England"), ("England and Wales", ["england", "wales"], u"101000: England, Wales"), ("Scotland", ["scotland"], u"010000: Scotland"), ("Northern Ireland", ["northern_ireland"], u"000100: Northern Ireland"), ("GB", ["england", "scotland", "wales"], u"111000: Great Britain (England, Scotland, Wales)"), ( "UK", ["england", "scotland", "wales", "northern_ireland"], u"111100: United Kingdom (England, Scotland, Wales, Northern Ireland)", ), ] for str_, form, db in expected_data: result_form = GeoCoverageType.get_instance().db_to_form(db) assert_equal(result_form, form)
def convert_geographic_to_form(value, context): return GeoCoverageType.get_instance().db_to_form(value)
def convert_geographic_to_form(value, context): from ckanext.dgu.schema import GeoCoverageType return GeoCoverageType.get_instance().db_to_form(value)
def test_db_to_form(self): for str_, form, db in self.expected_data: if form is None or db is None: continue result_form = GeoCoverageType.get_instance().db_to_form(db) assert_equal(result_form, form)
def test_str_to_db(self): for str_, form, db in self.expected_data: if str_ is None or db is None: continue result_db = GeoCoverageType.get_instance().str_to_db(str_) assert_equal(result_db, db)