Example #1
0
    def test_absent(self):
        '''
        Test to ensure that the named schema is absent.
        '''
        name = 'myname'
        dbname = 'mydb'

        ret = {'name': name,
               'dbname': dbname,
               'changes': {},
               'result': True,
               'comment': ''}

        mock_t = MagicMock(side_effect=[True, False])
        mock = MagicMock(side_effect=[True, True, False])
        with patch.dict(postgres_schema.__salt__,
                        {'postgres.schema_exists': mock,
                         'postgres.schema_remove': mock_t}):
            comt = ('Schema {0} has been removed from database {1}'.
                    format(name, dbname))
            ret.update({'comment': comt, 'result': True,
                        'changes': {name: 'Absent'}})
            self.assertDictEqual(postgres_schema.absent(dbname, name), ret)

            comt = ('Schema {0} failed to be removed'.format(name))
            ret.update({'comment': comt, 'result': False, 'changes': {}})
            self.assertDictEqual(postgres_schema.absent(dbname, name), ret)

            comt = ('Schema {0} is not present in database {1},'
                    ' so it cannot be removed'.format(name, dbname))
            ret.update({'comment': comt, 'result': True})
            self.assertDictEqual(postgres_schema.absent(dbname, name), ret)
Example #2
0
    def test_absent(self):
        '''
        Test to ensure that the named schema is absent.
        '''
        name = 'myname'
        dbname = 'mydb'

        ret = {'name': name,
               'dbname': dbname,
               'changes': {},
               'result': True,
               'comment': ''}

        mock_t = MagicMock(side_effect=[True, False])
        mock = MagicMock(side_effect=[True, True, False])
        with patch.dict(postgres_schema.__salt__,
                        {'postgres.schema_exists': mock,
                         'postgres.schema_remove': mock_t}):
            comt = ('Schema {0} has been removed from database {1}'.
                    format(name, dbname))
            ret.update({'comment': comt, 'result': True,
                        'changes': {name: 'Absent'}})
            self.assertDictEqual(postgres_schema.absent(dbname, name), ret)

            comt = ('Schema {0} failed to be removed'.format(name))
            ret.update({'comment': comt, 'result': False, 'changes': {}})
            self.assertDictEqual(postgres_schema.absent(dbname, name), ret)

            comt = ('Schema {0} is not present in database {1},'
                    ' so it cannot be removed'.format(name, dbname))
            ret.update({'comment': comt, 'result': True})
            self.assertDictEqual(postgres_schema.absent(dbname, name), ret)
Example #3
0
    def test_absent(self):
        """
        Test to ensure that the named schema is absent.
        """
        name = "myname"
        dbname = "mydb"

        ret = {
            "name": name,
            "dbname": dbname,
            "changes": {},
            "result": True,
            "comment": "",
        }

        mock_t = MagicMock(side_effect=[True, False])
        mock = MagicMock(side_effect=[True, True, True, False])
        with patch.dict(
                postgres_schema.__salt__,
            {
                "postgres.schema_exists": mock,
                "postgres.schema_remove": mock_t
            },
        ):
            with patch.dict(postgres_schema.__opts__, {"test": True}):
                comt = "Schema {0} is set to be removed from database {1}".format(
                    name, dbname)
                ret.update({"comment": comt, "result": None})
                self.assertDictEqual(postgres_schema.absent(dbname, name), ret)

            with patch.dict(postgres_schema.__opts__, {"test": False}):
                comt = "Schema {0} has been removed from database {1}".format(
                    name, dbname)
                ret.update({
                    "comment": comt,
                    "result": True,
                    "changes": {
                        name: "Absent"
                    }
                })
                self.assertDictEqual(postgres_schema.absent(dbname, name), ret)

                comt = "Schema {0} failed to be removed".format(name)
                ret.update({"comment": comt, "result": False, "changes": {}})
                self.assertDictEqual(postgres_schema.absent(dbname, name), ret)

            comt = ("Schema {0} is not present in database {1},"
                    " so it cannot be removed".format(name, dbname))
            ret.update({"comment": comt, "result": True})
            self.assertDictEqual(postgres_schema.absent(dbname, name), ret)
Example #4
0
 def test_absent_remove(self):
     with patch.dict(
             postgres_schema.__salt__,
         {
             "postgres.schema_exists": Mock(return_value=True),
             "postgres.schema_remove": MagicMock(),
         },
     ):
         ret = postgres_schema.absent("dbname", "foo")
         self.assertEqual(
             ret,
             {
                 "comment":
                 "Schema foo has been removed from database dbname",
                 "changes": {
                     "foo": "Absent"
                 },
                 "dbname": "dbname",
                 "name": "foo",
                 "result": True,
             },
         )
         self.assertEqual(
             postgres_schema.__salt__["postgres.schema_remove"].call_count,
             1)
Example #5
0
 def test_absent_remove(self):
     ret = postgres_schema.absent('dbname', 'foo')
     self.assertEqual(
         ret,
         {'comment': 'Schema foo has been removed from database dbname',
          'changes': {'foo': 'Absent'},
          'dbname': 'dbname',
          'name': 'foo',
          'result': True}
         )
     self.assertEqual(SALT_STUB['postgres.schema_remove'].call_count, 1)
Example #6
0
 def test_absent_remove(self):
     ret = postgres_schema.absent('dbname', 'foo')
     self.assertEqual(
         ret,
         {'comment': 'Schema foo has been removed from database dbname',
          'changes': {'foo': 'Absent'},
          'dbname': 'dbname',
          'name': 'foo',
          'result': True}
         )
     self.assertEqual(SALT_STUB['postgres.schema_remove'].call_count, 1)
Example #7
0
 def test_absent_noremove(self):
     ret = postgres_schema.absent('dbname', 'foo')
     self.assertEqual(
         ret,
         {'comment': 'Schema foo is not present in database dbname,'
                     ' so it cannot be removed',
          'changes': {},
          'dbname': 'dbname',
          'name': 'foo',
          'result': True}
         )
     self.assertEqual(SALT_STUB['postgres.schema_remove'].call_count, 0)
Example #8
0
 def test_absent_noremove(self):
     ret = postgres_schema.absent('dbname', 'foo')
     self.assertEqual(
         ret, {
             'comment': 'Schema foo is not present in database dbname,'
             ' so it cannot be removed',
             'changes': {},
             'dbname': 'dbname',
             'name': 'foo',
             'result': True
         })
     self.assertEqual(SALT_STUB['postgres.schema_remove'].call_count, 0)
Example #9
0
 def test_absent_remove(self):
     with patch.dict(postgres_schema.__salt__, {'postgres.schema_exists': Mock(return_value=True),
                                                'postgres.schema_remove': MagicMock()}):
         ret = postgres_schema.absent('dbname', 'foo')
         self.assertEqual(
             ret,
             {'comment': 'Schema foo has been removed from database dbname',
              'changes': {'foo': 'Absent'},
              'dbname': 'dbname',
              'name': 'foo',
              'result': True}
             )
         self.assertEqual(self.salt_stub['postgres.schema_remove'].call_count, 1)
Example #10
0
 def test_absent_noremove(self):
     with patch.dict(postgres_schema.__salt__, {'postgres.schema_exists': Mock(return_value=False),
                                                'postgres.schema_remove': MagicMock()}):
         ret = postgres_schema.absent('dbname', 'foo')
         self.assertEqual(
             ret,
             {'comment': 'Schema foo is not present in database dbname,'
                         ' so it cannot be removed',
              'changes': {},
              'dbname': 'dbname',
              'name': 'foo',
              'result': True}
             )
         self.assertEqual(self.salt_stub['postgres.schema_remove'].call_count, 0)
Example #11
0
def test_absent_noremove():
    with patch.dict(
        postgres_schema.__salt__,
        {
            "postgres.schema_exists": Mock(return_value=False),
            "postgres.schema_remove": MagicMock(),
        },
    ):
        ret = postgres_schema.absent("dbname", "foo")
        assert ret == {
            "comment": (
                "Schema foo is not present in database dbname, so it cannot be removed"
            ),
            "changes": {},
            "dbname": "dbname",
            "name": "foo",
            "result": True,
        }
        assert postgres_schema.__salt__["postgres.schema_remove"].call_count == 0
Example #12
0
 def test_absent_noremove(self):
     with patch.dict(
             postgres_schema.__salt__,
         {
             "postgres.schema_exists": Mock(return_value=False),
             "postgres.schema_remove": MagicMock(),
         },
     ):
         ret = postgres_schema.absent("dbname", "foo")
         self.assertEqual(
             ret,
             {
                 "comment": "Schema foo is not present in database dbname,"
                 " so it cannot be removed",
                 "changes": {},
                 "dbname": "dbname",
                 "name": "foo",
                 "result": True,
             },
         )
         self.assertEqual(
             self.salt_stub["postgres.schema_remove"].call_count, 0)