ADComputer fails: assert container_object.__class__.__str__ == 'ADContainer' unbound method issue

Asked by Don Gauthier

As I try to use the ADComputer it fails on the assert line: assert container_object.__class__.__str__ == 'ADContainer'.

Here is my code:

import win32api
import pythoncom
import pyad
from pyad import adbase, adobject
from pyad import adquery,aduser,adcontainer,adcomputer
import pdb

dn = pyad.adcontainer.ADContainer.from_dn("CN=Computers,DC=qatest,DC=XXXX,DC=com")

if dn.__class__.__str__ == 'ADContainer':
    print dn.__class__
else:
    print 'DN String is not ADContainer'
    print dn.__class__.__str__

Here is my output:
python test_addcomputer.py
DN String is not ADContainer
<unbound method ADContainer.__str__>

Can you help me out with this?

Thanks, Don

Question information

Language:
English Edit question
Status:
Solved
For:
pyactivedirectory Edit question
Assignee:
Zakir Durumeric Edit question
Last query:
Last reply:
Revision history for this message
Launchpad Janitor (janitor) said :
#1

This question was expired because it remained in the 'Open' state without activity for the last 15 days.

Revision history for this message
Zakir Durumeric (zakird) said :
#2

If you are looking to find the name of the class, you should call __name__, not __str__. For instance:

ADComputer.from_cn("mycomputer").__class__.__name__ == 'ADComputer'

However, you can also just check if the classes are equal:

ADComputer.from_cn("mycomputer").__class__ == ADComputer

or use is instance:

isinstance(ADComputer.from_cn("mycomputer"), ADComputer)

I hope this helps. Let me know if I can help further.

Zakir

Revision history for this message
Zakir Durumeric (zakird) said :
#3

I just realized that your first line is referencing a piece of the code. Will fix and commit in a moment.

Revision history for this message
Zakir Durumeric (zakird) said :
#4

fix committed.