mirror of
https://github.com/samba-team/samba.git
synced 2025-01-12 09:18:10 +03:00
Fix all pyldb tests except for modules.
This commit is contained in:
parent
5688f9b13e
commit
94ed43390c
@ -78,6 +78,7 @@ bool PyObject_AsDn(TALLOC_CTX *mem_ctx, PyObject *object,
|
||||
*dn = odn;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (PyLdbDn_Check(object)) {
|
||||
*dn = PyLdbDn_AsDn(object);
|
||||
return true;
|
||||
@ -163,7 +164,7 @@ static PyObject *py_ldb_dn_canonical_ex_str(PyLdbDnObject *self)
|
||||
|
||||
static PyObject *py_ldb_dn_repr(PyLdbDnObject *self)
|
||||
{
|
||||
return PyString_FromFormat("Dn('%s')", ldb_dn_get_linearized(self->ptr));
|
||||
return PyString_FromFormat("Dn(%s)", PyObject_REPR(PyString_FromString(ldb_dn_get_linearized(self->ptr))));
|
||||
}
|
||||
|
||||
static PyObject *py_ldb_dn_check_special(PyLdbDnObject *self, PyObject *args)
|
||||
@ -193,7 +194,7 @@ static PyObject *py_ldb_dn_add_child(PyLdbDnObject *self, PyObject *args)
|
||||
{
|
||||
PyObject *py_other;
|
||||
struct ldb_dn *dn, *other;
|
||||
if (!PyArg_ParseTuple(args, "O", &other))
|
||||
if (!PyArg_ParseTuple(args, "O", &py_other))
|
||||
return NULL;
|
||||
|
||||
dn = PyLdbDn_AsDn((PyObject *)self);
|
||||
@ -208,7 +209,7 @@ static PyObject *py_ldb_dn_add_base(PyLdbDnObject *self, PyObject *args)
|
||||
{
|
||||
PyObject *py_other;
|
||||
struct ldb_dn *other, *dn;
|
||||
if (!PyArg_ParseTuple(args, "O", &other))
|
||||
if (!PyArg_ParseTuple(args, "O", &py_other))
|
||||
return NULL;
|
||||
|
||||
dn = PyLdbDn_AsDn((PyObject *)self);
|
||||
@ -676,12 +677,11 @@ static PyObject *ldb_ldif_to_pyobject(struct ldb_ldif *ldif)
|
||||
|
||||
static PyObject *py_ldb_parse_ldif(PyLdbObject *self, PyObject *args)
|
||||
{
|
||||
char *filename;
|
||||
PyObject *list;
|
||||
struct ldb_ldif *ldif;
|
||||
const char *s;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "s", &filename))
|
||||
if (!PyArg_ParseTuple(args, "s", &s))
|
||||
return NULL;
|
||||
|
||||
list = PyList_New(0);
|
||||
@ -1260,6 +1260,12 @@ static PyObject *py_ldb_msg_element_new(PyTypeObject *type, PyObject *args, PyOb
|
||||
|
||||
if (py_elements != NULL) {
|
||||
int i;
|
||||
if (!PySequence_Check(py_elements)) {
|
||||
el->num_values = 1;
|
||||
el->values = talloc_array(el, struct ldb_val, 1);
|
||||
el->values[0].data = (uint8_t *)PyString_AsString(py_elements);
|
||||
el->values[0].length = PyString_Size(py_elements);
|
||||
} else {
|
||||
el->num_values = PySequence_Size(py_elements);
|
||||
el->values = talloc_array(el, struct ldb_val, el->num_values);
|
||||
for (i = 0; i < el->num_values; i++) {
|
||||
@ -1268,6 +1274,7 @@ static PyObject *py_ldb_msg_element_new(PyTypeObject *type, PyObject *args, PyOb
|
||||
el->values[i].length = PyString_Size(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
el->flags = flags;
|
||||
el->name = talloc_strdup(el, name);
|
||||
@ -1277,7 +1284,24 @@ static PyObject *py_ldb_msg_element_new(PyTypeObject *type, PyObject *args, PyOb
|
||||
|
||||
static PyObject *py_ldb_msg_element_repr(PyLdbMessageElementObject *self)
|
||||
{
|
||||
return PyString_FromFormat("MessageElement()");
|
||||
char *element_str = NULL;
|
||||
int i;
|
||||
struct ldb_message_element *el = PyLdbMessageElement_AsMessageElement(self);
|
||||
PyObject *ret;
|
||||
|
||||
for (i = 0; i < el->num_values; i++) {
|
||||
PyObject *o = py_ldb_msg_element_find(self, i);
|
||||
if (element_str == NULL)
|
||||
element_str = talloc_strdup(NULL, PyObject_REPR(o));
|
||||
else
|
||||
element_str = talloc_asprintf_append(element_str, ",%s", PyObject_REPR(o));
|
||||
}
|
||||
|
||||
ret = PyString_FromFormat("MessageElement([%s])", element_str);
|
||||
|
||||
talloc_free(element_str);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
PyTypeObject PyLdbMessageElement = {
|
||||
@ -1319,25 +1343,36 @@ static PyObject *py_ldb_msg_keys(PyLdbMessageObject *self)
|
||||
return obj;
|
||||
}
|
||||
|
||||
static PyObject *py_ldb_msg_getitem(PyLdbMessageObject *self, PyObject *py_name)
|
||||
static PyObject *py_ldb_msg_getitem_helper(PyLdbMessageObject *self, PyObject *py_name)
|
||||
{
|
||||
struct ldb_message_element *el;
|
||||
char *name = PyString_AsString(py_name);
|
||||
if (!strcmp(name, "dn"))
|
||||
return PyLdbDn_FromDn(PyLdbMessage_AsMessage(self)->dn);
|
||||
el = ldb_msg_find_element(PyLdbMessage_AsMessage(self), name);
|
||||
if (el == NULL)
|
||||
if (el == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
return (PyObject *)PyLdbMessageElement_FromMessageElement(el);
|
||||
}
|
||||
|
||||
static PyObject *py_ldb_msg_getitem(PyLdbMessageObject *self, PyObject *py_name)
|
||||
{
|
||||
PyObject *ret = py_ldb_msg_getitem_helper(self, py_name);
|
||||
if (ret == NULL) {
|
||||
PyErr_SetString(PyExc_KeyError, "No such element");
|
||||
return NULL;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static PyObject *py_ldb_msg_get(PyLdbMessageObject *self, PyObject *args)
|
||||
{
|
||||
PyObject *name, *ret;
|
||||
if (!PyArg_ParseTuple(args, "O", &name))
|
||||
return NULL;
|
||||
|
||||
ret = py_ldb_msg_getitem(self, name);
|
||||
ret = py_ldb_msg_getitem_helper(self, name);
|
||||
if (ret == NULL)
|
||||
return Py_None;
|
||||
return ret;
|
||||
@ -1437,6 +1472,16 @@ static PyGetSetDef py_ldb_msg_getset[] = {
|
||||
{ NULL }
|
||||
};
|
||||
|
||||
static PyObject *py_ldb_msg_repr(PyLdbMessageObject *self)
|
||||
{
|
||||
PyObject *dict = PyDict_New(), *ret;
|
||||
if (PyDict_Update(dict, (PyObject *)self) != 0)
|
||||
return NULL;
|
||||
ret = PyString_FromFormat("Message(%s)", PyObject_REPR(dict));
|
||||
Py_DECREF(dict);
|
||||
return ret;
|
||||
}
|
||||
|
||||
PyTypeObject PyLdbMessage = {
|
||||
.tp_name = "Message",
|
||||
.tp_methods = py_ldb_msg_methods,
|
||||
@ -1445,6 +1490,7 @@ PyTypeObject PyLdbMessage = {
|
||||
.tp_basicsize = sizeof(PyLdbMessageObject),
|
||||
.tp_dealloc = py_talloc_dealloc,
|
||||
.tp_new = py_ldb_msg_new,
|
||||
.tp_repr = (reprfunc)py_ldb_msg_repr,
|
||||
};
|
||||
|
||||
PyObject *PyLdbTree_FromTree(struct ldb_parse_tree *tree)
|
||||
|
@ -264,9 +264,10 @@ class DnTests(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.ldb = ldb.Ldb("foo.ldb")
|
||||
|
||||
def test_eq_str(self):
|
||||
def test_eq(self):
|
||||
x = ldb.Dn(self.ldb, "dc=foo,bar=bloe")
|
||||
self.assertEquals("dc=foo,bar=bloe", x)
|
||||
y = ldb.Dn(self.ldb, "dc=foo,bar=bloe")
|
||||
self.assertEquals(x, y)
|
||||
|
||||
def test_str(self):
|
||||
x = ldb.Dn(self.ldb, "dc=foo,bar=bloe")
|
||||
@ -328,7 +329,8 @@ class DnTests(unittest.TestCase):
|
||||
|
||||
def test_add_base(self):
|
||||
x = ldb.Dn(self.ldb, "dc=foo,bar=bloe")
|
||||
self.assertTrue(x.add_base(ldb.Dn(self.ldb, "bla=bloe")))
|
||||
base = ldb.Dn(self.ldb, "bla=bloe")
|
||||
self.assertTrue(x.add_base(base))
|
||||
self.assertEquals("dc=foo,bar=bloe,bla=bloe", x.__str__())
|
||||
|
||||
def test_add(self):
|
||||
@ -440,13 +442,15 @@ class MessageElementTests(unittest.TestCase):
|
||||
x = ldb.MessageElement(["foo"])
|
||||
self.assertEquals("MessageElement(['foo'])", repr(x))
|
||||
x = ldb.MessageElement(["foo", "bla"])
|
||||
self.assertEquals(2, len(x))
|
||||
self.assertEquals("MessageElement(['foo','bla'])", repr(x))
|
||||
|
||||
def test_get_item(self):
|
||||
x = ldb.MessageElement(["foo", "bar"])
|
||||
self.assertEquals("foo", x[0])
|
||||
self.assertEquals("bar", x[1])
|
||||
self.assertRaises(KeyError, lambda: x[-1])
|
||||
self.assertEquals("bar", x[-1])
|
||||
self.assertRaises(IndexError, lambda: x[45])
|
||||
|
||||
def test_len(self):
|
||||
x = ldb.MessageElement(["foo", "bar"])
|
||||
@ -454,9 +458,12 @@ class MessageElementTests(unittest.TestCase):
|
||||
|
||||
def test_eq(self):
|
||||
x = ldb.MessageElement(["foo", "bar"])
|
||||
self.assertEquals(["foo", "bar"], x)
|
||||
y = ldb.MessageElement(["foo", "bar"])
|
||||
self.assertEquals(y, x)
|
||||
x = ldb.MessageElement(["foo"])
|
||||
self.assertEquals("foo", x)
|
||||
self.assertNotEquals(y, x)
|
||||
y = ldb.MessageElement(["foo"])
|
||||
self.assertEquals(y, x)
|
||||
|
||||
|
||||
class ModuleTests(unittest.TestCase):
|
||||
|
Loading…
Reference in New Issue
Block a user