1921
1940
class TestReadonlyStore(TestStore):
1923
scenarios = [('configobj', {'_get_store': get_ConfigObjStore})]
1925
def get_store(self, file_name, content=None):
1926
return self._get_store(
1927
self.get_readonly_transport(), file_name, content=content)
1929
def test_delayed_load(self):
1930
self.build_tree_contents([('foo.conf', '')])
1931
store = self.get_store('foo.conf')
1932
self.assertEquals(False, store.loaded)
1934
self.assertEquals(True, store.loaded)
1936
def test_from_string_delayed_load(self):
1937
store = self.get_store('foo.conf', '')
1938
self.assertEquals(False, store.loaded)
1940
# We loaded the store from the provided content
1942
scenarios = [(key, {'get_store': builder})
1943
for key, builder in test_store_builder_registry.iteritems()]
1946
super(TestReadonlyStore, self).setUp()
1947
self.branch = self.make_branch('branch')
1949
def test_building_delays_load(self):
1950
store = self.get_store(self)
1951
self.assertEquals(False, store.loaded)
1952
store._load_from_string('')
1941
1953
self.assertEquals(True, store.loaded)
1943
1955
def test_get_no_sections_for_empty(self):
1944
store = self.get_store('foo.conf', '')
1956
store = self.get_store(self)
1957
store._load_from_string('')
1946
1958
self.assertEquals([], list(store.get_sections()))
1948
1960
def test_get_default_section(self):
1949
store = self.get_store('foo.conf', 'foo=bar')
1961
store = self.get_store(self)
1962
store._load_from_string('foo=bar')
1950
1963
sections = list(store.get_sections())
1951
1964
self.assertLength(1, sections)
1952
1965
self.assertSectionContent((None, {'foo': 'bar'}), sections[0])
1954
1967
def test_get_named_section(self):
1955
store = self.get_store('foo.conf', '[baz]\nfoo=bar')
1968
store = self.get_store(self)
1969
store._load_from_string('[baz]\nfoo=bar')
1956
1970
sections = list(store.get_sections())
1957
1971
self.assertLength(1, sections)
1958
1972
self.assertSectionContent(('baz', {'foo': 'bar'}), sections[0])
1974
def test_load_from_string_fails_for_non_empty_store(self):
1975
store = self.get_store(self)
1976
store._load_from_string('foo=bar')
1977
self.assertRaises(AssertionError, store._load_from_string, 'bar=baz')
1961
1980
class TestMutableStore(TestStore):
1963
scenarios = [('configobj', {'_get_store': get_ConfigObjStore})]
1965
def get_store(self, file_name, content=None):
1966
# Overriden to get a writable transport
1967
return self._get_store(
1968
self.get_transport(), file_name, content=content)
1970
def test_save_empty_succeeds(self):
1971
store = self.get_store('foo.conf', '')
1973
self.assertEquals(False, self.get_transport().has('foo.conf'))
1975
self.assertEquals(True, self.get_transport().has('foo.conf'))
1982
scenarios = [(key, {'store_id': key, 'get_store': builder})
1983
for key, builder in test_store_builder_registry.iteritems()]
1986
super(TestMutableStore, self).setUp()
1987
self.transport = self.get_transport()
1988
self.branch = self.make_branch('branch')
1990
def has_store(self, store):
1991
store_basename = urlutils.relative_url(self.transport.external_url(),
1992
store.external_url())
1993
return self.transport.has(store_basename)
1995
def test_save_empty_creates_no_file(self):
1996
if self.store_id == 'branch':
1997
raise tests.TestNotApplicable(
1998
'branch.conf is *always* created when a branch is initialized')
1999
store = self.get_store(self)
2001
self.assertEquals(False, self.has_store(store))
2003
def test_save_emptied_succeeds(self):
2004
store = self.get_store(self)
2005
store._load_from_string('foo=bar\n')
2006
section = store.get_mutable_section(None)
2007
section.remove('foo')
2009
self.assertEquals(True, self.has_store(store))
2010
modified_store = self.get_store(self)
2011
sections = list(modified_store.get_sections())
2012
self.assertLength(0, sections)
1977
2014
def test_save_with_content_succeeds(self):
1978
store = self.get_store('foo.conf', 'foo=bar\n')
1980
self.assertEquals(False, self.get_transport().has('foo.conf'))
2015
if self.store_id == 'branch':
2016
raise tests.TestNotApplicable(
2017
'branch.conf is *always* created when a branch is initialized')
2018
store = self.get_store(self)
2019
store._load_from_string('foo=bar\n')
2020
self.assertEquals(False, self.has_store(store))
1982
self.assertEquals(True, self.get_transport().has('foo.conf'))
1983
modified_store = self.get_store('foo.conf')
2022
self.assertEquals(True, self.has_store(store))
2023
modified_store = self.get_store(self)
1984
2024
sections = list(modified_store.get_sections())
1985
2025
self.assertLength(1, sections)
1986
2026
self.assertSectionContent((None, {'foo': 'bar'}), sections[0])
1988
2028
def test_set_option_in_empty_store(self):
1989
store = self.get_store('foo.conf')
2029
store = self.get_store(self)
1990
2030
section = store.get_mutable_section(None)
1991
2031
section.set('foo', 'bar')
1993
modified_store = self.get_store('foo.conf')
2033
modified_store = self.get_store(self)
1994
2034
sections = list(modified_store.get_sections())
1995
2035
self.assertLength(1, sections)
1996
2036
self.assertSectionContent((None, {'foo': 'bar'}), sections[0])
1998
2038
def test_set_option_in_default_section(self):
1999
store = self.get_store('foo.conf', '')
2039
store = self.get_store(self)
2040
store._load_from_string('')
2000
2041
section = store.get_mutable_section(None)
2001
2042
section.set('foo', 'bar')
2003
modified_store = self.get_store('foo.conf')
2044
modified_store = self.get_store(self)
2004
2045
sections = list(modified_store.get_sections())
2005
2046
self.assertLength(1, sections)
2006
2047
self.assertSectionContent((None, {'foo': 'bar'}), sections[0])
2008
2049
def test_set_option_in_named_section(self):
2009
store = self.get_store('foo.conf', '')
2050
store = self.get_store(self)
2051
store._load_from_string('')
2010
2052
section = store.get_mutable_section('baz')
2011
2053
section.set('foo', 'bar')
2013
modified_store = self.get_store('foo.conf')
2055
modified_store = self.get_store(self)
2014
2056
sections = list(modified_store.get_sections())
2015
2057
self.assertLength(1, sections)
2016
2058
self.assertSectionContent(('baz', {'foo': 'bar'}), sections[0])