Exemplo n.º 1
0
 def test_success(self):
     model_mock = mock.MagicMock(field=mock.sentinel.field)
     res = api.exists(self.sess, model_mock, field=mock.sentinel.field)
     self.sess.query.assert_called_once_with(mock.sentinel.field)
     self.query.filter_by.assert_called_once_with(field=mock.sentinel.field)
     self.query.limit.assert_called_once_with(1)
     self.assertTrue(res)
Exemplo n.º 2
0
 def test_not_found(self):
     model_mock = mock.MagicMock(field=mock.sentinel.field)
     self.query.one.side_effect = sao_exc.NoResultFound
     res = api.exists(self.sess, model_mock, field=mock.sentinel.field)
     self.sess.query.assert_called_once_with(mock.sentinel.field)
     self.query.filter_by.assert_called_once_with(field=mock.sentinel.field)
     self.query.limit.assert_called_once_with(1)
     self.assertFalse(res)
Exemplo n.º 3
0
    def exists(self, obj_type, key):
        """
        Returns True if an object of the supplied type and key exists
        in backend storage.

        :param obj_type: A `procession.objects.Object` class.
        :param key: string key for the object.
        """
        sess = self._get_session()
        model = _get_db_model_from_obj_class(obj_type)
        return api.exists(sess, model, key)