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 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583
|
#!/usr/bin/python
#
# Copyright (C) 2007 SIOS Technology, 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__ = 'tmatsuo@sios.com (Takashi MATSUO)'
import unittest
try:
from xml.etree import ElementTree
except ImportError:
from elementtree import ElementTree
import atom
import gdata
from gdata import test_data
import gdata.apps
class AppsEmailListRecipientFeedTest(unittest.TestCase):
def setUp(self):
self.rcpt_feed = gdata.apps.EmailListRecipientFeedFromString(
test_data.EMAIL_LIST_RECIPIENT_FEED)
def testEmailListRecipientEntryCount(self):
"""Count EmailListRecipient entries in EmailListRecipientFeed"""
self.assertEquals(len(self.rcpt_feed.entry), 2)
def testLinkFinderFindsHtmlLink(self):
"""Tests the return value of GetXXXLink() methods"""
self.assert_(self.rcpt_feed.GetSelfLink() is not None)
self.assert_(self.rcpt_feed.GetNextLink() is not None)
self.assert_(self.rcpt_feed.GetEditLink() is None)
self.assert_(self.rcpt_feed.GetHtmlLink() is None)
def testStartItem(self):
"""Tests the existence of <openSearch:startIndex> in
EmailListRecipientFeed and verifies the value"""
self.assert_(isinstance(self.rcpt_feed.start_index, gdata.StartIndex),
"EmailListRecipient feed <openSearch:startIndex> element must be " +
"an instance of gdata.OpenSearch: %s" % self.rcpt_feed.start_index)
self.assertEquals(self.rcpt_feed.start_index.text, "1")
def testEmailListRecipientEntries(self):
"""Tests the existence of <atom:entry> in EmailListRecipientFeed
and simply verifies the value"""
for a_entry in self.rcpt_feed.entry:
self.assert_(isinstance(a_entry, gdata.apps.EmailListRecipientEntry),
"EmailListRecipient Feed <atom:entry> must be an instance of " +
"apps.EmailListRecipientEntry: %s" % a_entry)
self.assertEquals(self.rcpt_feed.entry[0].who.email, "joe@example.com")
self.assertEquals(self.rcpt_feed.entry[1].who.email, "susan@example.com")
class AppsEmailListFeedTest(unittest.TestCase):
def setUp(self):
self.list_feed = gdata.apps.EmailListFeedFromString(
test_data.EMAIL_LIST_FEED)
def testEmailListEntryCount(self):
"""Count EmailList entries in EmailListFeed"""
self.assertEquals(len(self.list_feed.entry), 2)
def testLinkFinderFindsHtmlLink(self):
"""Tests the return value of GetXXXLink() methods"""
self.assert_(self.list_feed.GetSelfLink() is not None)
self.assert_(self.list_feed.GetNextLink() is not None)
self.assert_(self.list_feed.GetEditLink() is None)
self.assert_(self.list_feed.GetHtmlLink() is None)
def testStartItem(self):
"""Tests the existence of <openSearch:startIndex> in EmailListFeed
and verifies the value"""
self.assert_(isinstance(self.list_feed.start_index, gdata.StartIndex),
"EmailList feed <openSearch:startIndex> element must be an instance " +
"of gdata.OpenSearch: %s" % self.list_feed.start_index)
self.assertEquals(self.list_feed.start_index.text, "1")
def testUserEntries(self):
"""Tests the existence of <atom:entry> in EmailListFeed and simply
verifies the value"""
for a_entry in self.list_feed.entry:
self.assert_(isinstance(a_entry, gdata.apps.EmailListEntry),
"EmailList Feed <atom:entry> must be an instance of " +
"apps.EmailListEntry: %s" % a_entry)
self.assertEquals(self.list_feed.entry[0].email_list.name, "us-sales")
self.assertEquals(self.list_feed.entry[1].email_list.name, "us-eng")
class AppsUserFeedTest(unittest.TestCase):
def setUp(self):
self.user_feed = gdata.apps.UserFeedFromString(test_data.USER_FEED)
def testUserEntryCount(self):
"""Count User entries in UserFeed"""
self.assertEquals(len(self.user_feed.entry), 2)
def testLinkFinderFindsHtmlLink(self):
"""Tests the return value of GetXXXLink() methods"""
self.assert_(self.user_feed.GetSelfLink() is not None)
self.assert_(self.user_feed.GetNextLink() is not None)
self.assert_(self.user_feed.GetEditLink() is None)
self.assert_(self.user_feed.GetHtmlLink() is None)
def testStartItem(self):
"""Tests the existence of <openSearch:startIndex> in UserFeed and
verifies the value"""
self.assert_(isinstance(self.user_feed.start_index, gdata.StartIndex),
"User feed <openSearch:startIndex> element must be an instance " +
"of gdata.OpenSearch: %s" % self.user_feed.start_index)
self.assertEquals(self.user_feed.start_index.text, "1")
def testUserEntries(self):
"""Tests the existence of <atom:entry> in UserFeed and simply
verifies the value"""
for a_entry in self.user_feed.entry:
self.assert_(isinstance(a_entry, gdata.apps.UserEntry),
"User Feed <atom:entry> must be an instance of " +
"apps.UserEntry: %s" % a_entry)
self.assertEquals(self.user_feed.entry[0].login.user_name, "TestUser")
self.assertEquals(self.user_feed.entry[0].who.email,
"TestUser@example.com")
self.assertEquals(self.user_feed.entry[1].login.user_name, "JohnSmith")
self.assertEquals(self.user_feed.entry[1].who.email,
"JohnSmith@example.com")
class AppsNicknameFeedTest(unittest.TestCase):
def setUp(self):
self.nick_feed = gdata.apps.NicknameFeedFromString(test_data.NICK_FEED)
def testNicknameEntryCount(self):
"""Count Nickname entries in NicknameFeed"""
self.assertEquals(len(self.nick_feed.entry), 2)
def testId(self):
"""Tests the existence of <atom:id> in NicknameFeed and verifies
the value"""
self.assert_(isinstance(self.nick_feed.id, atom.Id),
"Nickname feed <atom:id> element must be an instance of " +
"atom.Id: %s" % self.nick_feed.id)
self.assertEquals(self.nick_feed.id.text,
"http://apps-apis.google.com/a/feeds/example.com/nickname/2.0")
def testStartItem(self):
"""Tests the existence of <openSearch:startIndex> in NicknameFeed
and verifies the value"""
self.assert_(isinstance(self.nick_feed.start_index, gdata.StartIndex),
"Nickname feed <openSearch:startIndex> element must be an instance " +
"of gdata.OpenSearch: %s" % self.nick_feed.start_index)
self.assertEquals(self.nick_feed.start_index.text, "1")
def testItemsPerPage(self):
"""Tests the existence of <openSearch:itemsPerPage> in
NicknameFeed and verifies the value"""
self.assert_(isinstance(self.nick_feed.items_per_page, gdata.ItemsPerPage),
"Nickname feed <openSearch:itemsPerPage> element must be an " +
"instance of gdata.ItemsPerPage: %s" % self.nick_feed.items_per_page)
self.assertEquals(self.nick_feed.items_per_page.text, "2")
def testLinkFinderFindsHtmlLink(self):
"""Tests the return value of GetXXXLink() methods"""
self.assert_(self.nick_feed.GetSelfLink() is not None)
self.assert_(self.nick_feed.GetEditLink() is None)
self.assert_(self.nick_feed.GetHtmlLink() is None)
def testNicknameEntries(self):
"""Tests the existence of <atom:entry> in NicknameFeed and simply
verifies the value"""
for a_entry in self.nick_feed.entry:
self.assert_(isinstance(a_entry, gdata.apps.NicknameEntry),
"Nickname Feed <atom:entry> must be an instance of " +
"apps.NicknameEntry: %s" % a_entry)
self.assertEquals(self.nick_feed.entry[0].nickname.name, "Foo")
self.assertEquals(self.nick_feed.entry[1].nickname.name, "Bar")
class AppsEmailListRecipientEntryTest(unittest.TestCase):
def setUp(self):
self.rcpt_entry = gdata.apps.EmailListRecipientEntryFromString(
test_data.EMAIL_LIST_RECIPIENT_ENTRY)
def testId(self):
"""Tests the existence of <atom:id> in EmailListRecipientEntry and
verifies the value"""
self.assert_(
isinstance(self.rcpt_entry.id, atom.Id),
"EmailListRecipient entry <atom:id> element must be an instance of " +
"atom.Id: %s" %
self.rcpt_entry.id)
self.assertEquals(
self.rcpt_entry.id.text,
'https://apps-apis.google.com/a/feeds/example.com/emailList/2.0/us-sales/' +
'recipient/TestUser%40example.com')
def testUpdated(self):
"""Tests the existence of <atom:updated> in
EmailListRecipientEntry and verifies the value"""
self.assert_(
isinstance(self.rcpt_entry.updated, atom.Updated),
"EmailListRecipient entry <atom:updated> element must be an instance " +
"of atom.Updated: %s" % self.rcpt_entry.updated)
self.assertEquals(self.rcpt_entry.updated.text,
'1970-01-01T00:00:00.000Z')
def testCategory(self):
"""Tests the existence of <atom:category> in
EmailListRecipientEntry and verifies the value"""
for a_category in self.rcpt_entry.category:
self.assert_(
isinstance(a_category, atom.Category),
"EmailListRecipient entry <atom:category> element must be an " +
"instance of atom.Category: %s" % a_category)
self.assertEquals(a_category.scheme,
"http://schemas.google.com/g/2005#kind")
self.assertEquals(a_category.term,
"http://schemas.google.com/apps/2006#" +
"emailList.recipient")
def testTitle(self):
"""Tests the existence of <atom:title> in EmailListRecipientEntry
and verifies the value"""
self.assert_(
isinstance(self.rcpt_entry.title, atom.Title),
"EmailListRecipient entry <atom:title> element must be an instance of " +
"atom.Title: %s" % self.rcpt_entry.title)
self.assertEquals(self.rcpt_entry.title.text, 'TestUser')
def testLinkFinderFindsHtmlLink(self):
"""Tests the return value of GetXXXLink() methods"""
self.assert_(self.rcpt_entry.GetSelfLink() is not None)
self.assert_(self.rcpt_entry.GetEditLink() is not None)
self.assert_(self.rcpt_entry.GetHtmlLink() is None)
def testWho(self):
"""Tests the existence of a <gdata:who> in EmailListRecipientEntry
and verifies the value"""
self.assert_(isinstance(self.rcpt_entry.who, gdata.apps.Who),
"EmailListRecipient entry <gdata:who> must be an instance of " +
"apps.Who: %s" % self.rcpt_entry.who)
self.assertEquals(self.rcpt_entry.who.email, 'TestUser@example.com')
class AppsEmailListEntryTest(unittest.TestCase):
def setUp(self):
self.list_entry = gdata.apps.EmailListEntryFromString(
test_data.EMAIL_LIST_ENTRY)
def testId(self):
"""Tests the existence of <atom:id> in EmailListEntry and verifies
the value"""
self.assert_(
isinstance(self.list_entry.id, atom.Id),
"EmailList entry <atom:id> element must be an instance of atom.Id: %s" %
self.list_entry.id)
self.assertEquals(
self.list_entry.id.text,
'https://apps-apis.google.com/a/feeds/example.com/emailList/2.0/testlist')
def testUpdated(self):
"""Tests the existence of <atom:updated> in EmailListEntry and
verifies the value"""
self.assert_(
isinstance(self.list_entry.updated, atom.Updated),
"EmailList entry <atom:updated> element must be an instance of " +
"atom.Updated: %s" % self.list_entry.updated)
self.assertEquals(self.list_entry.updated.text,
'1970-01-01T00:00:00.000Z')
def testCategory(self):
"""Tests the existence of <atom:category> in EmailListEntry and
verifies the value"""
for a_category in self.list_entry.category:
self.assert_(
isinstance(a_category, atom.Category),
"EmailList entry <atom:category> element must be an instance " +
"of atom.Category: %s" % a_category)
self.assertEquals(a_category.scheme,
"http://schemas.google.com/g/2005#kind")
self.assertEquals(a_category.term,
"http://schemas.google.com/apps/2006#emailList")
def testTitle(self):
"""Tests the existence of <atom:title> in EmailListEntry and verifies
the value"""
self.assert_(
isinstance(self.list_entry.title, atom.Title),
"EmailList entry <atom:title> element must be an instance of " +
"atom.Title: %s" % self.list_entry.title)
self.assertEquals(self.list_entry.title.text, 'testlist')
def testLinkFinderFindsHtmlLink(self):
"""Tests the return value of GetXXXLink() methods"""
self.assert_(self.list_entry.GetSelfLink() is not None)
self.assert_(self.list_entry.GetEditLink() is not None)
self.assert_(self.list_entry.GetHtmlLink() is None)
def testEmailList(self):
"""Tests the existence of a <apps:emailList> in EmailListEntry and
verifies the value"""
self.assert_(isinstance(self.list_entry.email_list, gdata.apps.EmailList),
"EmailList entry <apps:emailList> must be an instance of " +
"apps.EmailList: %s" % self.list_entry.email_list)
self.assertEquals(self.list_entry.email_list.name, 'testlist')
def testFeedLink(self):
"""Test the existence of a <gdata:feedLink> in EmailListEntry and
verifies the value"""
for an_feed_link in self.list_entry.feed_link:
self.assert_(isinstance(an_feed_link, gdata.FeedLink),
"EmailList entry <gdata:feedLink> must be an instance of " +
"gdata.FeedLink: %s" % an_feed_link)
self.assertEquals(self.list_entry.feed_link[0].rel,
'http://schemas.google.com/apps/2006#' +
'emailList.recipients')
self.assertEquals(self.list_entry.feed_link[0].href,
'http://apps-apis.google.com/a/feeds/example.com/emailList/' +
'2.0/testlist/recipient/')
class AppsNicknameEntryTest(unittest.TestCase):
def setUp(self):
self.nick_entry = gdata.apps.NicknameEntryFromString(test_data.NICK_ENTRY)
def testId(self):
"""Tests the existence of <atom:id> in NicknameEntry and verifies
the value"""
self.assert_(
isinstance(self.nick_entry.id, atom.Id),
"Nickname entry <atom:id> element must be an instance of atom.Id: %s" %
self.nick_entry.id)
self.assertEquals(
self.nick_entry.id.text,
'https://apps-apis.google.com/a/feeds/example.com/nickname/2.0/Foo')
def testCategory(self):
"""Tests the existence of <atom:category> in NicknameEntry and
verifies the value"""
for a_category in self.nick_entry.category:
self.assert_(
isinstance(a_category, atom.Category),
"Nickname entry <atom:category> element must be an instance " +
"of atom.Category: %s" % a_category)
self.assertEquals(a_category.scheme,
"http://schemas.google.com/g/2005#kind")
self.assertEquals(a_category.term,
"http://schemas.google.com/apps/2006#nickname")
def testTitle(self):
"""Tests the existence of <atom:title> in NicknameEntry and
verifies the value"""
self.assert_(isinstance(self.nick_entry.title, atom.Title),
"Nickname entry <atom:title> element must be an instance " +
"of atom.Title: %s" % self.nick_entry.title)
self.assertEquals(self.nick_entry.title.text, "Foo")
def testLogin(self):
"""Tests the existence of <apps:login> in NicknameEntry and
verifies the value"""
self.assert_(isinstance(self.nick_entry.login, gdata.apps.Login),
"Nickname entry <apps:login> element must be an instance " +
"of apps.Login: %s" % self.nick_entry.login)
self.assertEquals(self.nick_entry.login.user_name, "TestUser")
def testNickname(self):
"""Tests the existence of <apps:nickname> in NicknameEntry and
verifies the value"""
self.assert_(isinstance(self.nick_entry.nickname, gdata.apps.Nickname),
"Nickname entry <apps:nickname> element must be an instance " +
"of apps.Nickname: %s" % self.nick_entry.nickname)
self.assertEquals(self.nick_entry.nickname.name, "Foo")
def testLinkFinderFindsHtmlLink(self):
"""Tests the return value of GetXXXLink() methods"""
self.assert_(self.nick_entry.GetSelfLink() is not None)
self.assert_(self.nick_entry.GetEditLink() is not None)
self.assert_(self.nick_entry.GetHtmlLink() is None)
class AppsUserEntryTest(unittest.TestCase):
def setUp(self):
self.user_entry = gdata.apps.UserEntryFromString(test_data.USER_ENTRY)
def testId(self):
"""Tests the existence of <atom:id> in UserEntry and verifies the
value"""
self.assert_(
isinstance(self.user_entry.id, atom.Id),
"User entry <atom:id> element must be an instance of atom.Id: %s" %
self.user_entry.id)
self.assertEquals(
self.user_entry.id.text,
'https://apps-apis.google.com/a/feeds/example.com/user/2.0/TestUser')
def testUpdated(self):
"""Tests the existence of <atom:updated> in UserEntry and verifies
the value"""
self.assert_(
isinstance(self.user_entry.updated, atom.Updated),
"User entry <atom:updated> element must be an instance of " +
"atom.Updated: %s" % self.user_entry.updated)
self.assertEquals(self.user_entry.updated.text,
'1970-01-01T00:00:00.000Z')
def testCategory(self):
"""Tests the existence of <atom:category> in UserEntry and
verifies the value"""
for a_category in self.user_entry.category:
self.assert_(
isinstance(a_category, atom.Category),
"User entry <atom:category> element must be an instance " +
"of atom.Category: %s" % a_category)
self.assertEquals(a_category.scheme,
"http://schemas.google.com/g/2005#kind")
self.assertEquals(a_category.term,
"http://schemas.google.com/apps/2006#user")
def testTitle(self):
"""Tests the existence of <atom:title> in UserEntry and verifies
the value"""
self.assert_(
isinstance(self.user_entry.title, atom.Title),
"User entry <atom:title> element must be an instance of atom.Title: %s" %
self.user_entry.title)
self.assertEquals(self.user_entry.title.text, 'TestUser')
def testLinkFinderFindsHtmlLink(self):
"""Tests the return value of GetXXXLink() methods"""
self.assert_(self.user_entry.GetSelfLink() is not None)
self.assert_(self.user_entry.GetEditLink() is not None)
self.assert_(self.user_entry.GetHtmlLink() is None)
def testLogin(self):
"""Tests the existence of <apps:login> in UserEntry and verifies
the value"""
self.assert_(isinstance(self.user_entry.login, gdata.apps.Login),
"User entry <apps:login> element must be an instance of apps.Login: %s"
% self.user_entry.login)
self.assertEquals(self.user_entry.login.user_name, 'TestUser')
self.assertEquals(self.user_entry.login.password, 'password')
self.assertEquals(self.user_entry.login.suspended, 'false')
self.assertEquals(self.user_entry.login.ip_whitelisted, 'false')
self.assertEquals(self.user_entry.login.hash_function_name, 'SHA-1')
def testName(self):
"""Tests the existence of <apps:name> in UserEntry and verifies
the value"""
self.assert_(isinstance(self.user_entry.name, gdata.apps.Name),
"User entry <apps:name> element must be an instance of apps.Name: %s"
% self.user_entry.name)
self.assertEquals(self.user_entry.name.family_name, 'Test')
self.assertEquals(self.user_entry.name.given_name, 'User')
def testQuota(self):
"""Tests the existence of <apps:quota> in UserEntry and verifies
the value"""
self.assert_(isinstance(self.user_entry.quota, gdata.apps.Quota),
"User entry <apps:quota> element must be an instance of apps.Quota: %s"
% self.user_entry.quota)
self.assertEquals(self.user_entry.quota.limit, '1024')
def testFeedLink(self):
"""Test the existence of a <gdata:feedLink> in UserEntry and
verifies the value"""
for an_feed_link in self.user_entry.feed_link:
self.assert_(isinstance(an_feed_link, gdata.FeedLink),
"User entry <gdata:feedLink> must be an instance of gdata.FeedLink" +
": %s" % an_feed_link)
self.assertEquals(self.user_entry.feed_link[0].rel,
'http://schemas.google.com/apps/2006#user.nicknames')
self.assertEquals(self.user_entry.feed_link[0].href,
'https://apps-apis.google.com/a/feeds/example.com/nickname/' +
'2.0?username=Test-3121')
self.assertEquals(self.user_entry.feed_link[1].rel,
'http://schemas.google.com/apps/2006#user.emailLists')
self.assertEquals(self.user_entry.feed_link[1].href,
'https://apps-apis.google.com/a/feeds/example.com/emailList/' +
'2.0?recipient=testlist@example.com')
def testUpdate(self):
"""Tests for modifing attributes of UserEntry"""
self.user_entry.name.family_name = 'ModifiedFamilyName'
self.user_entry.name.given_name = 'ModifiedGivenName'
self.user_entry.quota.limit = '2048'
self.user_entry.login.password = 'ModifiedPassword'
self.user_entry.login.suspended = 'true'
modified = gdata.apps.UserEntryFromString(self.user_entry.ToString())
self.assertEquals(modified.name.family_name, 'ModifiedFamilyName')
self.assertEquals(modified.name.given_name, 'ModifiedGivenName')
self.assertEquals(modified.quota.limit, '2048')
self.assertEquals(modified.login.password, 'ModifiedPassword')
self.assertEquals(modified.login.suspended, 'true')
if __name__ == '__main__':
unittest.main()
|