Skip to content

Commit

Permalink
Add the UserRenamed#from_rc_doc method (fixes #3)
Browse files Browse the repository at this point in the history
  • Loading branch information
phuedx committed Aug 13, 2014
1 parent d85e6df commit aa5a961
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 1 deletion.
37 changes: 37 additions & 0 deletions mwevents/types/events/tests/test_user_renamed.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from nose.tools import eq_

from ..user_renamed import UserRenamed
from ... import Timestamp, User, Unavailable


def test_from_rc_doc():
rc_doc = {
'type': 'log',
'ns': 2,
'title': 'User:Tuhin Karmakar',
'rcid': 615891880,
'pageid': 0,
'revid': 0,
'old_revid': 0,
'user': 'Andrevan',
'userid': '13732',
'oldlen': 0,
'newlen': 0,
'timestamp': '2013-11-10T12:04:41Z',
'comment': 'WP:CHU',
'logid': 52520596,
'logtype': 'renameuser',
'logaction': 'renameuser',
'olduser': 'Tuhin Karmakar',
'newuser': 'Anonymous23648762289',
'edits': 19,
'tags': []
}

user_renamed = UserRenamed.from_rc_doc(rc_doc)

eq_(user_renamed.timestamp, Timestamp(rc_doc['timestamp']))
eq_(user_renamed.user, User(rc_doc['userid'], rc_doc['user']))
eq_(user_renamed.comment, rc_doc['comment'])
eq_(user_renamed.old, User(Unavailable, rc_doc['olduser']))
eq_(user_renamed.new, User(Unavailable, rc_doc['newuser']))
47 changes: 46 additions & 1 deletion mwevents/types/events/user_renamed.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from ... import configuration
from .event import Event
from .match import Match
from .. import User, Timestamp, Unavailable


class UserRenamed(Event):
Expand Down Expand Up @@ -58,5 +59,49 @@ def from_api_doc(cls, api_doc, config=configuration.DEFAULT):
doc['newuser']
)
)


@classmethod
def from_rc_doc(cls, rc_doc, config=configuration.DEFAULT):
"""
Example:
{
"logtype": "renameuser",
"pageid": 0,
"edits": 1,
"userid": "1795359",
"logid": 57568951,
"logaction": "renameuser",
"type": "log",
"newuser": "Whitedr9gon",
"comment": "user request",
"newlen": 0,
"ns": 2,
"old_revid": 0,
"rcid": 668780651,
"title": "User:Tomahawke",
"user": "Xeno",
"oldlen": 0,
"revid": 0,
"olduser": "Tomahawke",
"timestamp": "2014-07-14T13:22:06Z"
}
"""
return cls(
Timestamp(rc_doc.get('timestamp')),
User(
rc_doc.get('userid'),
rc_doc.get('user')
),
rc_doc.get('comment'),
User(
Unavailable, # Not available
rc_doc.get('olduser')
),
User(
Unavailable, # Not available
rc_doc.get('newuser')
)
)


Event.register(UserRenamed)

0 comments on commit aa5a961

Please sign in to comment.