test: fix the tests
This commit is contained in:
parent
d9a7804fb5
commit
f34a5b8aaf
1 changed files with 206 additions and 211 deletions
|
|
@ -40,13 +40,15 @@ class FakeMUCClient(object):
|
|||
self.host = plugin_parent.host
|
||||
self.joined_rooms = {}
|
||||
|
||||
def join(self, roomJID, nick, profile):
|
||||
def join(self, room_jid, nick, options=None, profile_key=C.PROF_KEY_NONE):
|
||||
"""
|
||||
@param roomJID: the room JID
|
||||
@param room_jid: the room JID
|
||||
@param nick: nick to be used in the room
|
||||
@param profile: the profile of the user joining the room
|
||||
@param options: joining options
|
||||
@param profile_key: the profile key of the user joining the room
|
||||
@return: the deferred joined wokkel.muc.Room instance
|
||||
"""
|
||||
profile = self.host.memory.getProfileName(profile_key)
|
||||
roster = {}
|
||||
|
||||
# ask the other profiles to fill our roster
|
||||
|
|
@ -55,7 +57,7 @@ class FakeMUCClient(object):
|
|||
if other_profile == profile:
|
||||
continue
|
||||
try:
|
||||
other_room = self.plugin_parent.clients[other_profile].joined_rooms[roomJID.userhost()]
|
||||
other_room = self.plugin_parent.clients[other_profile].joined_rooms[room_jid]
|
||||
roster.setdefault(other_room.nick, User(other_room.nick, C.PROFILE_DICT[other_profile]))
|
||||
for other_nick in other_room.roster:
|
||||
roster.setdefault(other_nick, other_room.roster[other_nick])
|
||||
|
|
@ -68,9 +70,9 @@ class FakeMUCClient(object):
|
|||
break # same user with different resource --> same nickname
|
||||
nick = nick + "_"
|
||||
|
||||
room = Room(roomJID, nick)
|
||||
room = Room(room_jid, nick)
|
||||
room.roster = roster
|
||||
self.joined_rooms[roomJID.userhost()] = room
|
||||
self.joined_rooms[room_jid] = room
|
||||
|
||||
# fill the other rosters with the new entry
|
||||
for i in xrange(0, len(C.PROFILE)):
|
||||
|
|
@ -78,31 +80,32 @@ class FakeMUCClient(object):
|
|||
if other_profile == profile:
|
||||
continue
|
||||
try:
|
||||
other_room = self.plugin_parent.clients[other_profile].joined_rooms[roomJID.userhost()]
|
||||
other_room = self.plugin_parent.clients[other_profile].joined_rooms[room_jid]
|
||||
other_room.roster.setdefault(room.nick, User(room.nick, C.PROFILE_DICT[profile]))
|
||||
except (AttributeError, KeyError):
|
||||
pass
|
||||
|
||||
return defer.succeed(room)
|
||||
|
||||
def leave(self, roomJID, profile):
|
||||
def leave(self, roomJID, profile_key=C.PROF_KEY_NONE):
|
||||
"""
|
||||
@param roomJID: the room JID
|
||||
@param profile: the profile of the user joining the room
|
||||
@param profile_key: the profile key of the user joining the room
|
||||
@return: a dummy deferred
|
||||
"""
|
||||
room = self.joined_rooms[roomJID.userhost()]
|
||||
profile = self.host.memory.getProfileName(profile_key)
|
||||
room = self.joined_rooms[roomJID]
|
||||
# remove ourself from the other rosters
|
||||
for i in xrange(0, len(C.PROFILE)):
|
||||
other_profile = C.PROFILE[i]
|
||||
if other_profile == profile:
|
||||
continue
|
||||
try:
|
||||
other_room = self.plugin_parent.clients[other_profile].joined_rooms[roomJID.userhost()]
|
||||
other_room = self.plugin_parent.clients[other_profile].joined_rooms[roomJID]
|
||||
del other_room.roster[room.nick]
|
||||
except (AttributeError, KeyError):
|
||||
pass
|
||||
del self.joined_rooms[roomJID.userhost()]
|
||||
del self.joined_rooms[roomJID]
|
||||
return defer.Deferred()
|
||||
|
||||
|
||||
|
|
@ -123,10 +126,9 @@ class FakeXEP_0045(plugin_xep_0045.XEP_0045):
|
|||
@return: the deferred joined wokkel.muc.Room instance or None
|
||||
"""
|
||||
profile = self.host.memory.getProfileName(profile_key)
|
||||
room_jid_s = room_jid.userhost()
|
||||
if room_jid_s in self.clients[profile].joined_rooms:
|
||||
if room_jid in self.clients[profile].joined_rooms:
|
||||
return defer.succeed(None)
|
||||
room = self.clients[profile].join(room_jid, nick, profile)
|
||||
room = self.clients[profile].join(room_jid, nick, profile_key=profile)
|
||||
return room
|
||||
|
||||
def joinRoom(self, muc_index, user_index):
|
||||
|
|
@ -145,8 +147,7 @@ class FakeXEP_0045(plugin_xep_0045.XEP_0045):
|
|||
@return: a dummy deferred
|
||||
"""
|
||||
profile = self.host.memory.getProfileName(profile_key)
|
||||
room_jid_s = room_jid.userhost()
|
||||
if room_jid_s not in self.clients[profile].joined_rooms:
|
||||
if room_jid not in self.clients[profile].joined_rooms:
|
||||
raise plugin_xep_0045.UnknownRoom("This room has not been joined")
|
||||
return self.clients[profile].leave(room_jid, profile)
|
||||
|
||||
|
|
@ -163,22 +164,22 @@ class FakeXEP_0045(plugin_xep_0045.XEP_0045):
|
|||
"""Called by tests
|
||||
@return: a wokkel.muc.Room instance"""
|
||||
profile = C.PROFILE[user_index]
|
||||
muc_s = C.MUC_STR[muc_index]
|
||||
muc_jid = C.MUC[muc_index]
|
||||
try:
|
||||
return self.clients[profile].joined_rooms[muc_s]
|
||||
return self.clients[profile].joined_rooms[muc_jid]
|
||||
except (AttributeError, KeyError):
|
||||
return None
|
||||
|
||||
def getNick(self, muc_index, user_index):
|
||||
try:
|
||||
return self.getRoomNick(C.MUC_STR[muc_index], C.PROFILE[user_index])
|
||||
return self.getRoomNick(C.MUC[muc_index], C.PROFILE[user_index])
|
||||
except (KeyError, AttributeError):
|
||||
return ''
|
||||
|
||||
def getNickOfUser(self, muc_index, user_index, profile_index, secure=True):
|
||||
try:
|
||||
room = self.clients[C.PROFILE[profile_index]].joined_rooms[C.MUC_STR[muc_index]]
|
||||
return self.getRoomNickOfUser(room, C.JID_STR[user_index])
|
||||
room = self.clients[C.PROFILE[profile_index]].joined_rooms[C.MUC[muc_index]]
|
||||
return self.getRoomNickOfUser(room, C.JID[user_index])
|
||||
except (KeyError, AttributeError):
|
||||
return None
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue