def test_present_non_existing_pass(): """ Test non existing data directory ok """ name = "/var/lib/psql/data" ret = {"name": name, "changes": {}, "result": False, "comment": ""} mock_true = MagicMock(return_value=True) mock_false = MagicMock(return_value=False) with patch.dict( postgres_initdb.__salt__, { "postgres.datadir_exists": mock_false, "postgres.datadir_init": mock_true }, ): with patch.dict(postgres_initdb.__opts__, {"test": True}): _comt = "Postgres data directory {} is set to be initialized".format( name) ret.update({"comment": _comt, "result": None}) assert postgres_initdb.present(name) == ret with patch.dict(postgres_initdb.__opts__, {"test": False}): _comt = "Postgres data directory {} has been initialized".format( name) _changes = {name: "Present"} ret.update({"comment": _comt, "result": True, "changes": _changes}) assert postgres_initdb.present(name) == ret
def test_present_non_existing_pass(self): ''' Test non existing data directory ok ''' with patch.dict( postgres_initdb.__salt__, { 'postgres.datadir_exists': self.mock_false, 'postgres.datadir_init': self.mock_true }): with patch.dict(postgres_initdb.__opts__, {'test': True}): _comt = 'Postgres data directory {0} is set to be initialized'\ .format(self.name) self.ret.update({'comment': _comt, 'result': None}) self.assertDictEqual(postgres_initdb.present(self.name), self.ret) with patch.dict(postgres_initdb.__opts__, {'test': False}): _comt = 'Postgres data directory {0} has been initialized'\ .format(self.name) _changes = {self.name: 'Present'} self.ret.update({ 'comment': _comt, 'result': True, 'changes': _changes }) self.assertDictEqual(postgres_initdb.present(self.name), self.ret)
def test_present_non_existing_pass(self): """ Test non existing data directory ok """ with patch.dict( postgres_initdb.__salt__, { "postgres.datadir_exists": self.mock_false, "postgres.datadir_init": self.mock_true, }, ): with patch.dict(postgres_initdb.__opts__, {"test": True}): _comt = "Postgres data directory {0} is set to be initialized".format( self.name) self.ret.update({"comment": _comt, "result": None}) self.assertDictEqual(postgres_initdb.present(self.name), self.ret) with patch.dict(postgres_initdb.__opts__, {"test": False}): _comt = "Postgres data directory {0} has been initialized".format( self.name) _changes = {self.name: "Present"} self.ret.update({ "comment": _comt, "result": True, "changes": _changes }) self.assertDictEqual(postgres_initdb.present(self.name), self.ret)
def test_present_existing(self): ''' Test existing data directory handled correctly ''' with patch.dict(postgres_initdb.__salt__, {'postgres.datadir_exists': self.mock_true}): _comt = 'Postgres data directory {0} is already present'\ .format(self.name) self.ret.update({'comment': _comt, 'result': True}) self.assertDictEqual(postgres_initdb.present(self.name), self.ret)
def test_present_existing(self): """ Test existing data directory handled correctly """ with patch.dict(postgres_initdb.__salt__, {"postgres.datadir_exists": self.mock_true}): _comt = "Postgres data directory {0} is already present".format( self.name) self.ret.update({"comment": _comt, "result": True}) self.assertDictEqual(postgres_initdb.present(self.name), self.ret)
def test_present_existing(): """ Test existing data directory handled correctly """ name = "/var/lib/psql/data" ret = {"name": name, "changes": {}, "result": False, "comment": ""} mock_true = MagicMock(return_value=True) with patch.dict(postgres_initdb.__salt__, {"postgres.datadir_exists": mock_true}): _comt = "Postgres data directory {} is already present".format(name) ret.update({"comment": _comt, "result": True}) assert postgres_initdb.present(name) == ret
def test_present_non_existing_fail(self): ''' Test non existing data directory fail ''' with patch.dict( postgres_initdb.__salt__, { 'postgres.datadir_exists': self.mock_false, 'postgres.datadir_init': self.mock_false }): with patch.dict(postgres_initdb.__opts__, {'test': False}): _comt = 'Postgres data directory {0} initialization failed'\ .format(self.name) self.ret.update({'comment': _comt, 'result': False}) self.assertDictEqual(postgres_initdb.present(self.name), self.ret)
def test_present_non_existing_pass(self): ''' Test non existing data directory ok ''' with patch.dict(postgres_initdb.__salt__, {'postgres.datadir_exists': self.mock_false, 'postgres.datadir_init': self.mock_true}): with patch.dict(postgres_initdb.__opts__, {'test': True}): _comt = 'Postgres data directory {0} is set to be initialized'\ .format(self.name) self.ret.update({'comment': _comt, 'result': None}) self.assertDictEqual( postgres_initdb.present(self.name), self.ret) with patch.dict(postgres_initdb.__opts__, {'test': False}): _comt = 'Postgres data directory {0} has been initialized'\ .format(self.name) _changes = {self.name: 'Present'} self.ret.update({ 'comment': _comt, 'result': True, 'changes': _changes}) self.assertDictEqual( postgres_initdb.present(self.name), self.ret)
def test_present_non_existing_fail(self): ''' Test non existing data directory fail ''' with patch.dict(postgres_initdb.__salt__, {'postgres.datadir_exists': self.mock_false, 'postgres.datadir_init': self.mock_false}): with patch.dict(postgres_initdb.__opts__, {'test': False}): _comt = 'Postgres data directory {0} initialization failed'\ .format(self.name) self.ret.update({ 'comment': _comt, 'result': False }) self.assertDictEqual( postgres_initdb.present(self.name), self.ret)
def test_present_non_existing_fail(self): """ Test non existing data directory fail """ with patch.dict( postgres_initdb.__salt__, { "postgres.datadir_exists": self.mock_false, "postgres.datadir_init": self.mock_false, }, ): with patch.dict(postgres_initdb.__opts__, {"test": False}): _comt = "Postgres data directory {0} initialization failed".format( self.name) self.ret.update({"comment": _comt, "result": False}) self.assertDictEqual(postgres_initdb.present(self.name), self.ret)
def test_present_non_existing_fail(): """ Test non existing data directory fail """ name = "/var/lib/psql/data" ret = {"name": name, "changes": {}, "result": False, "comment": ""} mock_false = MagicMock(return_value=False) with patch.dict( postgres_initdb.__salt__, { "postgres.datadir_exists": mock_false, "postgres.datadir_init": mock_false }, ): with patch.dict(postgres_initdb.__opts__, {"test": False}): _comt = "Postgres data directory {} initialization failed".format( name) ret.update({"comment": _comt, "result": False}) assert postgres_initdb.present(name) == ret