This repository was archived by the owner on Dec 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 228
/
Copy pathdocs_test.py
executable file
·158 lines (132 loc) · 6.72 KB
/
docs_test.py
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
#!/usr/bin/python
#
# Copyright (C) 2006 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
__author__ = ('api.jfisher (Jeff Fisher), '
'[email protected] (Eric Bidelman)')
import unittest
from gdata import test_data
import gdata.docs
class DocumentListEntryTest(unittest.TestCase):
def setUp(self):
self.dl_entry = gdata.docs.DocumentListEntryFromString(
test_data.DOCUMENT_LIST_ENTRY)
def testToAndFromStringWithData(self):
entry = gdata.docs.DocumentListEntryFromString(str(self.dl_entry))
self.assertEqual(entry.author[0].name.text, 'test.user')
self.assertEqual(entry.author[0].email.text, '[email protected]')
self.assertEqual(entry.GetDocumentType(), 'spreadsheet')
self.assertEqual(entry.id.text,
'https://docs.google.com/feeds/documents/private/full/' +\
'spreadsheet%3Asupercalifragilisticexpealidocious')
self.assertEqual(entry.title.text,'Test Spreadsheet')
self.assertEqual(entry.resourceId.text,
'spreadsheet:supercalifragilisticexpealidocious')
self.assertEqual(entry.lastModifiedBy.name.text,'test.user')
self.assertEqual(entry.lastModifiedBy.email.text,'[email protected]')
self.assertEqual(entry.lastViewed.text,'2009-03-05T07:48:21.493Z')
self.assertEqual(entry.writersCanInvite.value, 'true')
class DocumentListFeedTest(unittest.TestCase):
def setUp(self):
self.dl_feed = gdata.docs.DocumentListFeedFromString(
test_data.DOCUMENT_LIST_FEED)
def testToAndFromString(self):
self.assert_(len(self.dl_feed.entry) == 2)
for an_entry in self.dl_feed.entry:
self.assert_(isinstance(an_entry, gdata.docs.DocumentListEntry))
new_dl_feed = gdata.docs.DocumentListFeedFromString(str(self.dl_feed))
for an_entry in new_dl_feed.entry:
self.assert_(isinstance(an_entry, gdata.docs.DocumentListEntry))
def testConvertActualData(self):
for an_entry in self.dl_feed.entry:
self.assertEqual(an_entry.author[0].name.text, 'test.user')
self.assertEqual(an_entry.author[0].email.text, '[email protected]')
self.assertEqual(an_entry.lastModifiedBy.name.text, 'test.user')
self.assertEqual(an_entry.lastModifiedBy.email.text,
self.assertEqual(an_entry.lastViewed.text,'2009-03-05T07:48:21.493Z')
if(an_entry.GetDocumentType() == 'spreadsheet'):
self.assertEqual(an_entry.title.text, 'Test Spreadsheet')
self.assertEqual(an_entry.writersCanInvite.value, 'true')
elif(an_entry.GetDocumentType() == 'document'):
self.assertEqual(an_entry.title.text, 'Test Document')
self.assertEqual(an_entry.writersCanInvite.value, 'false')
def testLinkFinderFindsLinks(self):
for entry in self.dl_feed.entry:
# All Document List entries should have a self link
self.assert_(entry.GetSelfLink() is not None)
# All Document List entries should have an HTML link
self.assert_(entry.GetHtmlLink() is not None)
self.assert_(entry.feedLink.href is not None)
class DocumentListAclEntryTest(unittest.TestCase):
def setUp(self):
self.acl_entry = gdata.docs.DocumentListAclEntryFromString(
test_data.DOCUMENT_LIST_ACL_ENTRY)
def testToAndFromString(self):
self.assert_(isinstance(self.acl_entry, gdata.docs.DocumentListAclEntry))
self.assert_(isinstance(self.acl_entry.role, gdata.docs.Role))
self.assert_(isinstance(self.acl_entry.scope, gdata.docs.Scope))
self.assertEqual(self.acl_entry.scope.value, '[email protected]')
self.assertEqual(self.acl_entry.scope.type, 'user')
self.assertEqual(self.acl_entry.role.value, 'writer')
acl_entry_str = str(self.acl_entry)
new_acl_entry = gdata.docs.DocumentListAclEntryFromString(acl_entry_str)
self.assert_(isinstance(new_acl_entry, gdata.docs.DocumentListAclEntry))
self.assert_(isinstance(new_acl_entry.role, gdata.docs.Role))
self.assert_(isinstance(new_acl_entry.scope, gdata.docs.Scope))
self.assertEqual(new_acl_entry.scope.value, self.acl_entry.scope.value)
self.assertEqual(new_acl_entry.scope.type, self.acl_entry.scope.type)
self.assertEqual(new_acl_entry.role.value, self.acl_entry.role.value)
def testCreateNewAclEntry(self):
cat = gdata.atom.Category(
term='http://schemas.google.com/acl/2007#accessRule',
scheme='http://schemas.google.com/g/2005#kind')
acl_entry = gdata.docs.DocumentListAclEntry(category=[cat])
acl_entry.scope = gdata.docs.Scope(value='[email protected]', type='user')
acl_entry.role = gdata.docs.Role(value='writer')
self.assert_(isinstance(acl_entry, gdata.docs.DocumentListAclEntry))
self.assert_(isinstance(acl_entry.role, gdata.docs.Role))
self.assert_(isinstance(acl_entry.scope, gdata.docs.Scope))
self.assertEqual(acl_entry.scope.value, '[email protected]')
self.assertEqual(acl_entry.scope.type, 'user')
self.assertEqual(acl_entry.role.value, 'writer')
class DocumentListAclFeedTest(unittest.TestCase):
def setUp(self):
self.feed = gdata.docs.DocumentListAclFeedFromString(
test_data.DOCUMENT_LIST_ACL_FEED)
def testToAndFromString(self):
for entry in self.feed.entry:
self.assert_(isinstance(entry, gdata.docs.DocumentListAclEntry))
feed = gdata.docs.DocumentListAclFeedFromString(str(self.feed))
for entry in feed.entry:
self.assert_(isinstance(entry, gdata.docs.DocumentListAclEntry))
def testConvertActualData(self):
entries = self.feed.entry
self.assert_(len(entries) == 2)
self.assertEqual(entries[0].title.text,
'Document Permission - [email protected]')
self.assertEqual(entries[0].role.value, 'owner')
self.assertEqual(entries[0].scope.type, 'user')
self.assertEqual(entries[0].scope.value, '[email protected]')
self.assert_(entries[0].GetSelfLink() is not None)
self.assert_(entries[0].GetEditLink() is not None)
self.assertEqual(entries[1].title.text,
'Document Permission - [email protected]')
self.assertEqual(entries[1].role.value, 'writer')
self.assertEqual(entries[1].scope.type, 'domain')
self.assertEqual(entries[1].scope.value, 'google.com')
self.assert_(entries[1].GetSelfLink() is not None)
self.assert_(entries[1].GetEditLink() is not None)
if __name__ == '__main__':
unittest.main()