コード例 #1
0
ファイル: test_zotero.py プロジェクト: mikpim01/pyzotero
 def testRequestBuilder(self):
     """ Should url-encode all added parameters
     """
     zot = z.Zotero("myuserID", "user", "myuserkey")
     zot.add_parameters(limit=0, start=7)
     self.assertEqual(parse_qs("start=7&limit=100&format=json"),
                      parse_qs(zot.url_params))
コード例 #2
0
ファイル: test_zotero.py プロジェクト: mikpim01/pyzotero
 def testRequestBuilderLimitNegativeOne(self):
     """ Should skip limit = 100 param if limit is set to -1
     """
     zot = z.Zotero("myuserID", "user", "myuserkey")
     zot.add_parameters(limit=-1, start=7)
     self.assertEqual(parse_qs("start=7&format=json"),
                      parse_qs(zot.url_params))
コード例 #3
0
ファイル: test_zotero.py プロジェクト: djs52/pyzotero
 def testRequestBuilder(self):
     """ Should url-encode all added parameters
     """
     zot = z.Zotero('myuserID', 'user', 'myuserkey')
     zot.add_parameters(limit=0, start=7)
     self.assertEqual(parse_qs('start=7&limit=0&format=json'),
                      parse_qs(zot.url_params))
コード例 #4
0
 def testCreateCollectionError(self):
     """ Ensure that collection creation fails with the wrong dict
     """
     zot = z.Zotero('myuserID', 'user', 'myuserkey')
     t = [{'foo': 'bar'}]
     with self.assertRaises(z.ze.ParamNotPassed):
         t = zot.create_collections(t)
コード例 #5
0
 def testCreateCollectionError(self):
     """ Ensure that collection creation fails with the wrong dict
     """
     zot = z.Zotero("myuserID", "user", "myuserkey")
     t = [{"foo": "bar"}]
     with self.assertRaises(z.ze.ParamNotPassed):
         t = zot.create_collections(t)
コード例 #6
0
 def testTooManyItems(self):
     """ Should fail because we're passing too many items
     """
     itms = [i for i in range(51)]
     zot = z.Zotero('myuserID', 'user', 'myuserkey')
     with self.assertRaises(z.ze.TooManyItems):
         zot.create_items(itms)
コード例 #7
0
 def testRequestBuilderLimitNone(self):
     """ Should skip limit = 100 param if limit is set to None
     """
     zot = z.Zotero('myuserID', 'user', 'myuserkey')
     zot.add_parameters(limit=None, start=7)
     self.assertEqual(
         parse_qs('start=7&format=json'),
         parse_qs(zot.url_params))
コード例 #8
0
ファイル: test_zotero.py プロジェクト: igcxl/pyzotero
 def testGetItems(self):
     """ Ensure that we can retrieve a list of all items """
     zot = z.Zotero('myuserID', 'user', 'myuserkey')
     HTTPretty.register_uri(
         HTTPretty.GET,
         'https://api.zotero.org/itemTypes',
         body=self.item_types)
     t = json.loads(zot.item_types())
     self.assertEqual(t[0]['itemType'], 'artwork')
コード例 #9
0
ファイル: test_zotero.py プロジェクト: mikpim01/pyzotero
 def testParamsReset(self):
     """ Should successfully reset URL parameters after a query string
         is built
     """
     zot = z.Zotero("myuserID", "user", "myuserkey")
     zot.add_parameters(start=5, limit=10)
     zot._build_query("/whatever")
     zot.add_parameters(start=2)
     self.assertEqual(parse_qs("start=2&format=json&limit=100"),
                      parse_qs(zot.url_params))
コード例 #10
0
ファイル: test_zotero.py プロジェクト: djs52/pyzotero
 def testParamsReset(self):
     """ Should successfully reset URL parameters after a query string
         is built
     """
     zot = z.Zotero('myuserID', 'user', 'myuserkey')
     zot.add_parameters(start=5, limit=10)
     zot._build_query('/whatever')
     zot.add_parameters(start=2)
     self.assertEqual(parse_qs('start=2&format=json'),
                      parse_qs(zot.url_params))
コード例 #11
0
ファイル: test_zotero.py プロジェクト: djs52/pyzotero
 def testParamsBlankAfterCall(self):
     """ self.url_params should be blank after an API call
     """
     zot = z.Zotero('myuserID', 'user', 'myuserkey')
     HTTPretty.register_uri(HTTPretty.GET,
                            'https://api.zotero.org/users/myuserID/items',
                            content_type='application/json',
                            body=self.items_doc)
     _ = zot.items()
     self.assertEqual(None, zot.url_params)
コード例 #12
0
 def testParseChildItems(self):
     """ Try and parse child items """
     zot = z.Zotero('myuserid', 'user', 'myuserkey')
     HTTPretty.register_uri(
         HTTPretty.GET,
         'https://api.zotero.org/users/myuserid/items/ABC123/children',
         content_type='application/json',
         body=self.items_doc)
     items_data = zot.children('ABC123')
     self.assertEqual(u'NM66T6EF', items_data[0]['key'])
コード例 #13
0
 def testGetItems(self):
     """ Ensure that we can retrieve a list of all items """
     zot = z.Zotero('myuserID', 'user', 'myuserkey')
     HTTPretty.register_uri(
         HTTPretty.GET,
         'https://api.zotero.org/itemTypes',
         content_type='application/json',
         body=self.item_types)
     resp = zot.item_types()
     self.assertEqual(resp[0]['itemType'], 'artwork')
コード例 #14
0
 def testParseAttachmentsJSONDoc(self):
     """ Ensure that attachments are being correctly parsed """
     zot = z.Zotero('myuserid', 'user', 'myuserkey')
     HTTPretty.register_uri(
         HTTPretty.GET,
         'https://api.zotero.org/users/myuserid/items',
         content_type='application/json',
         body=self.attachments_doc)
     attachments_data = zot.items()
     self.assertEqual(u'1641 Depositions', attachments_data['data']['title'])
コード例 #15
0
 def testGetItems(self):
     """ Ensure that we can retrieve a list of all items """
     zot = z.Zotero("myuserID", "user", "myuserkey")
     HTTPretty.register_uri(
         HTTPretty.GET,
         "https://api.zotero.org/itemTypes",
         content_type="application/json",
         body=self.item_types,
     )
     resp = zot.item_types()
     self.assertEqual(resp[0]["itemType"], "artwork")
コード例 #16
0
 def testParseAttachmentsJSONDoc(self):
     """ Ensure that attachments are being correctly parsed """
     zot = z.Zotero("myuserid", "user", "myuserkey")
     HTTPretty.register_uri(
         HTTPretty.GET,
         "https://api.zotero.org/users/myuserid/items",
         content_type="application/json",
         body=self.attachments_doc,
     )
     attachments_data = zot.items()
     self.assertEqual(u"1641 Depositions", attachments_data["data"]["title"])
コード例 #17
0
ファイル: test_zotero.py プロジェクト: djs52/pyzotero
 def testResponseNotFound(self):
     """ Ensure that an error is properly raised for 404
     """
     zot = z.Zotero('myuserID', 'user', 'myuserkey')
     HTTPretty.register_uri(HTTPretty.GET,
                            'https://api.zotero.org/users/myuserID/items',
                            body=self.items_doc,
                            content_type='application/json',
                            status=404)
     with self.assertRaises(z.ze.ResourceNotFound):
         zot.items()
コード例 #18
0
 def testGetTemplate(self):
     """ Ensure that item templates are retrieved and converted into dicts
     """
     zot = z.Zotero('myuserID', 'user', 'myuserkey')
     HTTPretty.register_uri(
         HTTPretty.GET,
         'https://api.zotero.org/items/new?itemType=book',
         content_type='application/json',
         body=self.item_templt)
     t = zot.item_template('book')
     self.assertEqual('book', t['itemType'])
コード例 #19
0
 def testParseTagsJSON(self):
     """ Should successfully return a list of tags
     """
     zot = z.Zotero('myuserID', 'user', 'myuserkey')
     HTTPretty.register_uri(
         HTTPretty.GET,
         'https://api.zotero.org/users/myuserID/tags?limit=1',
         content_type='application/json',
         body=self.tags_doc)
     tags_data = zot.tags()
     self.assertEqual(u'Community / Economic Development', tags_data[0])
コード例 #20
0
 def testParseKeysResponse(self):
     """ Check that parsing plain keys returned by format = keys works """
     zot = z.Zotero('myuserid', 'user', 'myuserkey')
     zot.url_params = 'format=keys'
     HTTPretty.register_uri(
         HTTPretty.GET,
         'https://api.zotero.org/users/myuserid/items?format=keys',
         content_type='text/plain',
         body=self.keys_response)
     response = zot.items()
     self.assertEqual('JIFWQ4AN', response[:8].decode("utf-8"))
コード例 #21
0
 def testParseChildItems(self):
     """ Try and parse child items """
     zot = z.Zotero("myuserid", "user", "myuserkey")
     HTTPretty.register_uri(
         HTTPretty.GET,
         "https://api.zotero.org/users/myuserid/items/ABC123/children",
         content_type="application/json",
         body=self.items_doc,
     )
     items_data = zot.children("ABC123")
     self.assertEqual(u"NM66T6EF", items_data[0]["key"])
コード例 #22
0
 def testNoApiKey(self):
     """ Ensure that pyzotero works when api_key is not set
     """
     zot = z.Zotero('myuserID', 'user')
     HTTPretty.register_uri(
         HTTPretty.GET,
         'https://api.zotero.org/users/myuserID/items',
         content_type='application/json',
         body=self.item_doc)
     items = zot.items()
     self.assertEqual(len(items), 6) # this isn't a very good assertion
コード例 #23
0
ファイル: test_zotero.py プロジェクト: djs52/pyzotero
 def testResponseMiscError(self):
     """ Ensure that an error is properly raised for unspecified errors
     """
     zot = z.Zotero('myuserID', 'user', 'myuserkey')
     HTTPretty.register_uri(HTTPretty.GET,
                            'https://api.zotero.org/users/myuserID/items',
                            content_type='application/json',
                            body=self.items_doc,
                            status=500)
     with self.assertRaises(z.ze.HTTPError):
         zot.items()
コード例 #24
0
 def testGetItemFile(self):
     """
     Should successfully return a binary string with a PDF content
     """
     zot = z.Zotero('myuserid', 'user', 'myuserkey')
     HTTPretty.register_uri(
         HTTPretty.GET,
         'https://api.zotero.org/users/myuserid/items/MYITEMID/file',
         content_type='application/pdf',
         body=self.item_file)
     items_data = zot.file('myitemid')
     self.assertEqual(b'One very strange PDF\n', items_data)
コード例 #25
0
 def testParseTagsJSON(self):
     """ Should successfully return a list of tags
     """
     zot = z.Zotero("myuserID", "user", "myuserkey")
     HTTPretty.register_uri(
         HTTPretty.GET,
         "https://api.zotero.org/users/myuserID/tags?limit=1",
         content_type="application/json",
         body=self.tags_doc,
     )
     tags_data = zot.tags()
     self.assertEqual(u"Community / Economic Development", tags_data[0])
コード例 #26
0
 def testParamsBlankAfterCall(self):
     """ self.url_params should be blank after an API call
     """
     zot = z.Zotero("myuserID", "user", "myuserkey")
     HTTPretty.register_uri(
         HTTPretty.GET,
         "https://api.zotero.org/users/myuserID/items",
         content_type="application/json",
         body=self.items_doc,
     )
     zot.items()
     self.assertEqual(None, zot.url_params)
コード例 #27
0
 def testParseCollectionVersionsResponse(self):
     """ Check that parsing version dict returned by format = versions works """
     zot = z.Zotero('myuserid', 'user', 'myuserkey')
     HTTPretty.register_uri(
         HTTPretty.GET,
         'https://api.zotero.org/users/myuserid/collections?format=versions',
         content_type='application/json',
         body=self.collection_versions)
     iversions = zot.collection_versions()
     self.assertEqual(iversions['RRK27C5F'], 4000)
     self.assertEqual(iversions['EAWCSKSF'], 4087)
     self.assertEqual(len(iversions), 2)
コード例 #28
0
 def testRateLimitWithBackoff(self):
     """ Test 429 response handling when a backoff header is received
     """
     zot = z.Zotero("myuserID", "user", "myuserkey")
     HTTPretty.register_uri(
         HTTPretty.GET,
         "https://api.zotero.org/users/myuserID/items",
         status=429,
         adding_headers={"backoff": 10},
     )
     zot.items()
     self.assertTrue(zot.backoff)
コード例 #29
0
 def testGetTemplate(self):
     """ Ensure that item templates are retrieved and converted into dicts
     """
     zot = z.Zotero("myuserID", "user", "myuserkey")
     HTTPretty.register_uri(
         HTTPretty.GET,
         "https://api.zotero.org/items/new?itemType=book",
         content_type="application/json",
         body=self.item_templt,
     )
     t = zot.item_template("book")
     self.assertEqual("book", t["itemType"])
コード例 #30
0
 def testParseKeysResponse(self):
     """ Check that parsing plain keys returned by format = keys works """
     zot = z.Zotero("myuserid", "user", "myuserkey")
     zot.url_params = "format=keys"
     HTTPretty.register_uri(
         HTTPretty.GET,
         "https://api.zotero.org/users/myuserid/items?format=keys",
         content_type="text/plain",
         body=self.keys_response,
     )
     response = zot.items()
     self.assertEqual("JIFWQ4AN", response[:8].decode("utf-8"))