1922
1940
class TestReadonlyStore(TestStore):
1924
scenarios = [('configobj', {'_get_store': get_ConfigObjStore})]
1926
def get_store(self, file_name, content=None):
1927
return self._get_store(
1928
self.get_readonly_transport(), file_name, content=content)
1930
def test_delayed_load(self):
1931
self.build_tree_contents([('foo.conf', '')])
1932
store = self.get_store('foo.conf')
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)
1933
1951
self.assertEquals(False, store.loaded)
1952
store._load_from_string('')
1935
1953
self.assertEquals(True, store.loaded)
1937
1955
def test_get_no_sections_for_empty(self):
1938
store = self.get_store('foo.conf', '')
1956
store = self.get_store(self)
1957
store._load_from_string('')
1940
1958
self.assertEquals([], list(store.get_sections()))
1942
1960
def test_get_default_section(self):
1943
store = self.get_store('foo.conf', 'foo=bar')
1961
store = self.get_store(self)
1962
store._load_from_string('foo=bar')
1944
1963
sections = list(store.get_sections())
1945
1964
self.assertLength(1, sections)
1946
1965
self.assertSectionContent((None, {'foo': 'bar'}), sections[0])
1948
1967
def test_get_named_section(self):
1949
store = self.get_store('foo.conf', '[baz]\nfoo=bar')
1968
store = self.get_store(self)
1969
store._load_from_string('[baz]\nfoo=bar')
1950
1970
sections = list(store.get_sections())
1951
1971
self.assertLength(1, sections)
1952
1972
self.assertSectionContent(('baz', {'foo': 'bar'}), sections[0])
1954
1974
def test_load_from_string_fails_for_non_empty_store(self):
1955
store = self.get_store('foo.conf', 'foo=bar')
1975
store = self.get_store(self)
1976
store._load_from_string('foo=bar')
1956
1977
self.assertRaises(AssertionError, store._load_from_string, 'bar=baz')
1959
1980
class TestMutableStore(TestStore):
1961
scenarios = [('configobj', {'_get_store': get_ConfigObjStore})]
1963
def get_store(self, file_name, content=None):
1964
return self._get_store(
1965
self.get_transport(), file_name, content=content)
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)
1967
1995
def test_save_empty_creates_no_file(self):
1968
store = self.get_store('foo.conf')
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)
1970
self.assertEquals(False, self.get_transport().has('foo.conf'))
2001
self.assertEquals(False, self.has_store(store))
1972
2003
def test_save_emptied_succeeds(self):
1973
store = self.get_store('foo.conf', 'foo=bar\n')
2004
store = self.get_store(self)
2005
store._load_from_string('foo=bar\n')
1974
2006
section = store.get_mutable_section(None)
1975
2007
section.remove('foo')
1977
self.assertEquals(True, self.get_transport().has('foo.conf'))
1978
modified_store = self.get_store('foo.conf')
2009
self.assertEquals(True, self.has_store(store))
2010
modified_store = self.get_store(self)
1979
2011
sections = list(modified_store.get_sections())
1980
2012
self.assertLength(0, sections)
1982
2014
def test_save_with_content_succeeds(self):
1983
store = self.get_store('foo.conf', 'foo=bar\n')
1985
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))
1987
self.assertEquals(True, self.get_transport().has('foo.conf'))
1988
modified_store = self.get_store('foo.conf')
2022
self.assertEquals(True, self.has_store(store))
2023
modified_store = self.get_store(self)
1989
2024
sections = list(modified_store.get_sections())
1990
2025
self.assertLength(1, sections)
1991
2026
self.assertSectionContent((None, {'foo': 'bar'}), sections[0])
1993
2028
def test_set_option_in_empty_store(self):
1994
store = self.get_store('foo.conf')
2029
store = self.get_store(self)
1995
2030
section = store.get_mutable_section(None)
1996
2031
section.set('foo', 'bar')
1998
modified_store = self.get_store('foo.conf')
2033
modified_store = self.get_store(self)
1999
2034
sections = list(modified_store.get_sections())
2000
2035
self.assertLength(1, sections)
2001
2036
self.assertSectionContent((None, {'foo': 'bar'}), sections[0])
2003
2038
def test_set_option_in_default_section(self):
2004
store = self.get_store('foo.conf', '')
2039
store = self.get_store(self)
2040
store._load_from_string('')
2005
2041
section = store.get_mutable_section(None)
2006
2042
section.set('foo', 'bar')
2008
modified_store = self.get_store('foo.conf')
2044
modified_store = self.get_store(self)
2009
2045
sections = list(modified_store.get_sections())
2010
2046
self.assertLength(1, sections)
2011
2047
self.assertSectionContent((None, {'foo': 'bar'}), sections[0])
2013
2049
def test_set_option_in_named_section(self):
2014
store = self.get_store('foo.conf', '')
2050
store = self.get_store(self)
2051
store._load_from_string('')
2015
2052
section = store.get_mutable_section('baz')
2016
2053
section.set('foo', 'bar')
2018
modified_store = self.get_store('foo.conf')
2055
modified_store = self.get_store(self)
2019
2056
sections = list(modified_store.get_sections())
2020
2057
self.assertLength(1, sections)
2021
2058
self.assertSectionContent(('baz', {'foo': 'bar'}), sections[0])