blob: 539796f207f1b8510e22b1bf2b119ea922498cb4 [file] [log] [blame]
Joe Gregorioba9ea7f2010-08-19 15:49:04 -04001#!/usr/bin/python2.4
2#
Joe Gregorio6d5e94f2010-08-25 23:49:30 -04003# Copyright 2010 Google Inc.
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
Joe Gregorioba9ea7f2010-08-19 15:49:04 -040017
18"""Discovery document tests
19
20Unit tests for objects created from discovery documents.
21"""
22
23__author__ = 'jcgregorio@google.com (Joe Gregorio)'
24
25from apiclient.discovery import build
26import httplib2
27import os
28import unittest
29
30DATA_DIR = os.path.join(os.path.dirname(__file__), 'data')
31
32class HttpMock(object):
33
34 def __init__(self, filename, headers):
35 f = file(os.path.join(DATA_DIR, filename), 'r')
36 self.data = f.read()
37 f.close()
38 self.headers = headers
39
40 def request(self, uri, method="GET", body=None, headers=None, redirections=1, connection_type=None):
41 return httplib2.Response(self.headers), self.data
42
43
44class Discovery(unittest.TestCase):
45 def test_method_error_checking(self):
46 self.http = HttpMock('buzz.json', {'status': '200'})
47 buzz = build('buzz', 'v1', self.http)
48
49 # Missing required parameters
50 try:
51 buzz.activities().list()
52 self.fail()
53 except TypeError, e:
54 self.assertTrue('Missing' in str(e))
55
56 # Parameter doesn't match regex
57 try:
58 buzz.activities().list(scope='@self', userId='')
59 self.fail()
60 except TypeError, e:
61 self.assertTrue('does not match' in str(e))
62
63 # Parameter doesn't match regex
64 try:
65 buzz.activities().list(scope='not@', userId='foo')
66 self.fail()
67 except TypeError, e:
68 self.assertTrue('does not match' in str(e))
69
70 # Unexpected parameter
71 try:
72 buzz.activities().list(flubber=12)
73 self.fail()
74 except TypeError, e:
75 self.assertTrue('unexpected' in str(e))
76
ade@google.com850cf552010-08-20 23:24:56 +010077 def test_buzz_resources(self):
Joe Gregorioba9ea7f2010-08-19 15:49:04 -040078 self.http = HttpMock('buzz.json', {'status': '200'})
79 buzz = build('buzz', 'v1', self.http)
80 self.assertTrue(getattr(buzz, 'activities'))
81 self.assertTrue(getattr(buzz, 'search'))
82 self.assertTrue(getattr(buzz, 'feeds'))
83 self.assertTrue(getattr(buzz, 'photos'))
84 self.assertTrue(getattr(buzz, 'people'))
85 self.assertTrue(getattr(buzz, 'groups'))
86 self.assertTrue(getattr(buzz, 'comments'))
87 self.assertTrue(getattr(buzz, 'related'))
88
89
90if __name__ == '__main__':
91 unittest.main()