File: person_test.py

package info (click to toggle)
python-pypump 0.7-6
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 560 kB
  • sloc: python: 3,153; makefile: 134
file content (168 lines) | stat: -rw-r--r-- 6,159 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# -*- coding: utf-8 -*-
from __future__ import absolute_import

import six

from pypump.models.place import Place
from tests import PyPumpTest


class PersonTest(PyPumpTest):
    def setUp(self):
        super(PersonTest, self).setUp()
        self.response.data = {
            "id": "acct:TestUser@example.com",
            "preferredUsername": "TestUser",
            "url": "http://example.com/TestUser",
            "displayName": "Test Userson",
            "links": {
                "self": {
                    "href": "http://example.com/api/user/TestUser/profile",
                },
                "activity-inbox": {
                    "href": "http://example.com/api/user/TestUser/inbox",
                },
                "activity-outbox": {
                    "href": "http://example.com/api/user/TestUser/feed",
                },
            },
            "objectType": "person",
            "followers": {
                "url": "http://example.com/api/user/TestUser/followers",
                "totalItems": 72,
            },
            "following": {
                "url": "http://example.com/api/user/TestUser/following",
                "totalItems": 27,
            },
            "favorites": {
                "url": "http://example.com/api/user/TestUser/favorites",
                "totalItems": 720,
            },
            "location": {
                "objectType": "place",
                "displayName": "Home Tree, Pandora",
            },
            "summary": "I am a PyPump Test user, I am used for testing!",
            "image": {
                "url": "http://example.com/uploads/TestUser/some_image.jpg",
                "width": 96,
                "height": 96,
            },
            "pump_io": {
                "shared": False,
                "followed": False,
            },
            "updated": "2013-08-13T10:26:54Z",
            "liked": False,
            "shares": {
                "url": "http://example.com/api/person/BlahBlah/shares",
                "items": [],
            }
        }

    def test_person(self):
        person = self.pump.Person("TestUser@example.com")
        # is a Person object
        self.assertTrue(isinstance(person, type(self.pump.Person())))
        # repr
        self.assertEqual(person.__repr__(), '<Person: TestUser@example.com>')
        # string
        self.assertEqual(person.__str__(), self.response['displayName'])
        # unicode
        person.display_name = u'Test användarson'
        if six.PY3:
            self.assertEqual(person.__str__(), person.display_name)
        else:
            self.assertEqual(person.__str__(), person.display_name.encode('utf-8'))

    def test_follow(self):
        """ Tests that pypump sends correct data when attempting to follow a person """
        person = self.pump.Person("TestUser@example.com")

        # PyPump now expects the object returned back to it
        self.response.data = {
            "actor": {"objectType": "person", "id": "acct:foo@bar"},
            "verb": "follow",
            "object": self.response.data
        }
        person.follow()

        # Test verb is 'follow'
        self.assertEqual(self.request["verb"], "follow")

        # Test ID is the correct ID
        self.assertEqual(person.id, self.request["object"]["id"])

        # Ensure object type is correct
        self.assertEqual(person.object_type, self.request["object"]["objectType"])

    def test_update(self):
        """ Test that a update works """
        person = self.pump.Person("TestUser@example.com")
        person.summary = "New summary!"
        person.display_name = "New user"

        self.response.data = {
            "verb": "update",
            "actor": {"objectType": "person", "id": person.id},
            "object": {
                "id": person.id,
                "summary": person.summary,
                "displayName": person.display_name,
                "objectType": "person",
            },
        }

        person.update()

        self.assertEqual(self.request["verb"], "update")
        self.assertEqual(self.request["object"]["id"], person.id)
        self.assertEqual(self.request["object"]["objectType"], person.object_type)
        self.assertEqual(self.request["object"]["summary"], person.summary)
        self.assertEqual(self.request["object"]["displayName"], person.display_name)

    def test_unfollow(self):
        """ Test that you can unfollow a person """
        person = self.pump.Person("TestUser@example.com")

        self.response.data = {
            "actor": {"objectType": "person", "id": "acct:foo@bar"},
            "verb": "stop-following",
            "object": self.response.data
        }
        person.unfollow()

        self.assertEqual(self.request["verb"], "stop-following")
        self.assertEqual(self.request["object"]["id"], person.id)
        self.assertEqual(self.request["object"]["objectType"], person.object_type)

    def test_minimal_unserialize(self):
        """ Test the smallest amount of data can be given to unserialize """
        self.response.data = {
            "id": "acct:TestUser@example.com",
            "objectType": "person",
        }

        person = self.pump.Person("TestUser@example.com")

        self.assertEqual(self.response["id"], person.id)
        self.assertEqual(self.response["objectType"], person.object_type)

    def test_unserialize(self):
        """ Tests person unserialization is successful """
        # Make the person object
        person = self.pump.Person("TestUser@example.com")

        # Test unserialization is correct
        self.assertEqual(person.id, self.response["id"])
        self.assertEqual(person.username, self.response["preferredUsername"])
        self.assertEqual(person.display_name, self.response["displayName"])
        self.assertEqual(person.url, self.response["url"])
        self.assertEqual(person.summary, self.response["summary"])

        # Test image model was made
        #self.assertTrue(isinstance(person.image, self.pump.Image))

        # Test place model was made
        self.assertTrue(isinstance(person.location, Place))