def test_present_nocreation(self): with patch.dict( postgres_schema.__salt__, { "postgres.schema_get": Mock(return_value={"foo": { "acl": "", "owner": "postgres" }}), "postgres.schema_create": MagicMock(), }, ): ret = postgres_schema.present("dbname", "foo") self.assertEqual( ret, { "comment": "Schema foo already exists in database dbname", "changes": {}, "dbname": "dbname", "name": "foo", "result": True, }, ) self.assertEqual( self.salt_stub["postgres.schema_create"].call_count, 0)
def test_present_creation(self): with patch.dict( postgres_schema.__salt__, { "postgres.schema_get": Mock(return_value=None), "postgres.schema_create": MagicMock(), }, ): ret = postgres_schema.present("dbname", "foo") self.assertEqual( ret, { "comment": "Schema foo has been created in database dbname", "changes": { "foo": "Present" }, "dbname": "dbname", "name": "foo", "result": True, }, ) self.assertEqual( postgres_schema.__salt__["postgres.schema_create"].call_count, 1)
def test_present_nocreation(self): ret = postgres_schema.present('dbname', 'foo') self.assertEqual( ret, {'comment': 'Schema foo already exists in database dbname', 'changes': {}, 'dbname': 'dbname', 'name': 'foo', 'result': True} ) self.assertEqual(SALT_STUB['postgres.schema_create'].call_count, 0)
def test_present_creation(self): ret = postgres_schema.present('dbname', 'foo') self.assertEqual( ret, {'comment': 'Schema foo has been created in database dbname', 'changes': {'foo': 'Present'}, 'dbname': 'dbname', 'name': 'foo', 'result': True} ) self.assertEqual(SALT_STUB['postgres.schema_create'].call_count, 1)
def test_present_nocreation(self): ret = postgres_schema.present('dbname', 'foo') self.assertEqual( ret, { 'comment': 'Schema foo already exists in database dbname', 'changes': {}, 'dbname': 'dbname', 'name': 'foo', 'result': True }) self.assertEqual(SALT_STUB['postgres.schema_create'].call_count, 0)
def test_present_creation(self): with patch.dict(postgres_schema.__salt__, {'postgres.schema_get': Mock(return_value=None), 'postgres.schema_create': MagicMock()}): ret = postgres_schema.present('dbname', 'foo') self.assertEqual( ret, {'comment': 'Schema foo has been created in database dbname', 'changes': {'foo': 'Present'}, 'dbname': 'dbname', 'name': 'foo', 'result': True} ) self.assertEqual(self.salt_stub['postgres.schema_create'].call_count, 1)
def test_present_nocreation(self): with patch.dict(postgres_schema.__salt__, { 'postgres.schema_get': Mock(return_value={'foo': {'acl': '', 'owner': 'postgres'} }), 'postgres.schema_create': MagicMock()}): ret = postgres_schema.present('dbname', 'foo') self.assertEqual( ret, {'comment': 'Schema foo already exists in database dbname', 'changes': {}, 'dbname': 'dbname', 'name': 'foo', 'result': True} ) self.assertEqual(self.salt_stub['postgres.schema_create'].call_count, 0)
def test_present(self): ''' Test to ensure that the named schema is present in the database. ''' name = 'myname' dbname = 'mydb' ret = {'name': name, 'dbname': dbname, 'changes': {}, 'result': True, 'comment': ''} mock = MagicMock(return_value=name) with patch.dict(postgres_schema.__salt__, {'postgres.schema_get': mock}): comt = ('Schema {0} already exists in database {1}'.format(name, dbname)) ret.update({'comment': comt}) self.assertDictEqual(postgres_schema.present(dbname, name), ret)
def test_present(self): """ Test to ensure that the named schema is present in the database. """ name = "myname" dbname = "mydb" ret = { "name": name, "dbname": dbname, "changes": {}, "result": True, "comment": "", } mock = MagicMock(return_value=name) with patch.dict(postgres_schema.__salt__, {"postgres.schema_get": mock}): with patch.dict(postgres_schema.__opts__, {"test": False}): comt = "Schema {0} already exists in database {1}".format( name, dbname) ret.update({"comment": comt}) self.assertDictEqual(postgres_schema.present(dbname, name), ret)