def test_get_policy_by_policy_id_integrity_problems(self): """Raises an error if more than one policy is found.""" self.client.execute.return_value = defer.succeed(['policy-abc', 'policy-def']) d = cass.get_policy_by_policy_id(self.client, '101010', 'policy-abc') result = self.failureResultOf(d) self.assertTrue(result.check(cass.ExcessiveResultsError))
def test_get_policy_by_policy_id_not_found(self): """Raises an error if no policy is found.""" self.client.execute.return_value = defer.succeed([]) d = cass.get_policy_by_policy_id(self.client, '101010', 'policy-abc') result = self.failureResultOf(d) self.assertTrue(result.check(cass.ResultNotFoundError))
def test_get_policy_by_policy_id_integrity_problems(self): """Raises an error if more than one policy is found.""" self.client.execute.return_value = defer.succeed( ['policy-abc', 'policy-def']) d = cass.get_policy_by_policy_id(self.client, '101010', 'policy-abc') result = self.failureResultOf(d) self.assertTrue(result.check(cass.ExcessiveResultsError))
def test_get_policy_by_policy_id(self): """Return a single policy dict, rather than a single item list.""" expected = {'policyId': 'policy-abc', 'groupId': 'group-def', 'alarmTemplate': 'alarmTemplate-ghi', 'checkTemplate': 'checkTemplate-jkl'} self.client.execute.return_value = defer.succeed([expected]) d = cass.get_policy_by_policy_id(self.client, '101010', 'policy-abc') result = self.successResultOf(d) self.assertEqual(result, expected) self.client.execute.assert_called_once_with( 'SELECT * FROM policies WHERE "policyId"=:policyId AND "groupId"=:groupId;', {'policyId': 'policy-abc', 'groupId': '101010'}, 1)
def test_get_policy_by_policy_id(self): """Return a single policy dict, rather than a single item list.""" expected = { 'policyId': 'policy-abc', 'groupId': 'group-def', 'alarmTemplate': 'alarmTemplate-ghi', 'checkTemplate': 'checkTemplate-jkl' } self.client.execute.return_value = defer.succeed([expected]) d = cass.get_policy_by_policy_id(self.client, '101010', 'policy-abc') result = self.successResultOf(d) self.assertEqual(result, expected) self.client.execute.assert_called_once_with( 'SELECT * FROM policies WHERE "policyId"=:policyId AND "groupId"=:groupId;', { 'policyId': 'policy-abc', 'groupId': '101010' }, 1)