python-twitter icon indicating copy to clipboard operation
python-twitter copied to clipboard

testNewFromJsonDict from test_status.py is incomplete and hides missing functionality: 'entities' dict

Open SecsAndCyber opened this issue 8 years ago • 1 comments
trafficstars

The test string does not include nested objects which the twitter JSON delivers in 'entities'. The AsJsonString [via AsDict] places those aspects directly within the json dict root.

AsDict automatically generates the dictionary without accounting for values with lists should be inside the 'entities' dict

Post = api.GetStatus(851223203167039492)
PP = twitter.Status.NewFromJsonDict(json.loads( str(Post.AsJsonString() ) ) )
>>> print Post.urls
[URL(URL=https://t.co/uUG61G1wPn, ExpandedURL=https://www.propublica.org/article/minority-neighborhoods-higher-car-insurance-premiums-white-areas-same-risk)]
>>> print PP.urls
None

SecsAndCyber avatar Apr 10 '17 00:04 SecsAndCyber

Kiiiiinda. So what happens is the Twitter JSON data gets deconstructed starting here https://github.com/bear/python-twitter/blob/master/twitter/models.py#L471 and then the the individual nodes values are passed as kwargs to super().NewFromJsonDict(), essentially flattening the JSON dict and setting those node values as instance attributes.

If you want the raw JSON data from Twitter to pass back into NewFromJsonDict, use ._json instance attribute. Making those two functions symmetrical might be a good enhancement, though.

jeremylow avatar Apr 10 '17 01:04 jeremylow