Beispiel #1
0
 def test_get_activities_304_not_modified(self):
   """Requests with matching ETags return 304 Not Modified."""
   self.init(requestBuilder=http.RequestMockBuilder({
         'plus.activities.list': (httplib2.Response({'status': 304}), '{}'),
         }))
   self.assert_equals([], self.googleplus.get_activities(
         fetch_replies=True, fetch_likes=True, fetch_shares=True))
Beispiel #2
0
    def test_get_comment(self):
        self.init(requestBuilder=http.RequestMockBuilder({
            'plus.comments.get': (None,
                                  json.dumps(COMMENT_GP))  # None means 200 OK
        }))

        self.assert_equals(COMMENT_AS, self.googleplus.get_comment('234'))
Beispiel #3
0
  def test_get_activity(self):
    self.init(requestBuilder=http.RequestMockBuilder({
          'plus.activities.get': (None, json.dumps(ACTIVITY_GP))
          }))

    self.assert_equals([ACTIVITY_AS],
                       self.googleplus.get_activities(activity_id='234'))
Beispiel #4
0
 def setUpClass(cls):
     # The apiclient library has support for mocking requests for
     # testing, but it doesn't extend to the discovery document
     # itself. For now, bring up an API server that will serve
     # a discovery document.
     # FIXME: Figure out a better way to stub this out.
     run_test_server.run()
     mock_responses = {
         'arvados.humans.delete':
         (fake_httplib2_response(500, **cls.ERROR_HEADERS), ""),
         'arvados.humans.get':
         cls.api_error_response(422, "Bad UUID format",
                                "Bad output format"),
         'arvados.humans.list':
         (None, json.dumps({
             'items_available': 0,
             'items': []
         })),
     }
     req_builder = apiclient_http.RequestMockBuilder(mock_responses)
     cls.api = arvados.api('v1',
                           host=os.environ['ARVADOS_API_HOST'],
                           token='discovery-doc-only-no-token-needed',
                           insecure=True,
                           requestBuilder=req_builder)
Beispiel #5
0
 def test_get_activities_response_etag(self):
   self.init(requestBuilder=http.RequestMockBuilder({
         'plus.activities.list': (httplib2.Response({'status': 200}),
                                  json.dumps({'etag': '"my etag"'})),
         }))
   resp = self.googleplus.get_activities_response(
     fetch_replies=True, fetch_likes=True, fetch_shares=True)
   self.assertEquals('"my etag"', resp['etag'])
Beispiel #6
0
 def test_get_activities_search(self):
     self.init(requestBuilder=http.RequestMockBuilder({
         'plus.activities.search': (None,
                                    json.dumps({'items': [ACTIVITY_GP]})),
     }))
     self.assert_equals(
         [ACTIVITY_AS],
         self.googleplus.get_activities(search_query='qwert'))
Beispiel #7
0
 def test_exceptions_without_errors_have_basic_info(self):
     mock_responses = {
         'arvados.humans.delete':
         (fake_httplib2_response(500, **self.ERROR_HEADERS), b"")
     }
     req_builder = apiclient_http.RequestMockBuilder(mock_responses)
     api = arvados.api('v1', requestBuilder=req_builder)
     with self.assertRaises(apiclient_errors.HttpError) as err_ctx:
         api.humans().delete(uuid='xyz-xyz-abcdef').execute()
     self.assertIn("500", str(err_ctx.exception))
Beispiel #8
0
 def test_exceptions_include_errors(self):
     mock_responses = {
         'arvados.humans.get': self.api_error_response(
             422, "Bad UUID format", "Bad output format"),
         }
     req_builder = apiclient_http.RequestMockBuilder(mock_responses)
     api = arvados.api('v1', requestBuilder=req_builder)
     with self.assertRaises(apiclient_errors.HttpError) as err_ctx:
         api.humans().get(uuid='xyz-xyz-abcdef').execute()
     err_s = str(err_ctx.exception)
     for msg in ["Bad UUID format", "Bad output format"]:
         self.assertIn(msg, err_s)
Beispiel #9
0
  def test_get_activities_no_extras_to_fetch(self):
    self.init(requestBuilder=http.RequestMockBuilder({
          'plus.activities.list': (None, json.dumps({
                'items': [ACTIVITY_GP, ACTIVITY_GP],
                })),
          },
          # ACTIVITY_GP doesn't say there are any comments, +1s, or shares (via
          # totalItems), so we shouldn't ask for them.
          check_unexpected=True))

    got = self.googleplus.get_activities(fetch_replies=True, fetch_likes=True,
                                         fetch_shares=True)
    self.assert_equals([ACTIVITY_AS, ACTIVITY_AS], got)
Beispiel #10
0
 def test_ordered_json_model(self):
     mock_responses = {
         'arvados.humans.get':
         (None,
          json.dumps(
              collections.OrderedDict(
                  (c, int(c, 16)) for c in string.hexdigits))),
     }
     req_builder = apiclient_http.RequestMockBuilder(mock_responses)
     api = arvados.api('v1',
                       requestBuilder=req_builder,
                       model=OrderedJsonModel())
     result = api.humans().get(uuid='test').execute()
     self.assertEqual(string.hexdigits, ''.join(result.keys()))
Beispiel #11
0
  def test_search_for_links(self):
    # should only search for urls without paths
    for urls in [], [], ['http://a/b'], ['https://c/d/e', 'https://f.com/g']:
      self.gp.domain_urls = urls
      self.assertEqual([], self.gp.search_for_links())

    # TODO: actually check search query. (still haven't figured out how with
    # RequestMockBuilder etc. :/ see granary/test/test_googleplus.py for more.)
    self.gp.domain_urls = ['http://a', 'https://b/', 'http://c/d/e']
    oauth_googleplus.json_service = discovery.build_from_document(
      gr_test_googleplus.DISCOVERY_DOC, requestBuilder=http.RequestMockBuilder({
        'plus.activities.search':
          (None, json.dumps({'items': [gr_test_googleplus.ACTIVITY_GP]})),
      }))
    self.assertEqual([gr_test_googleplus.ACTIVITY_AS], self.gp.search_for_links())
Beispiel #12
0
 def test_ordered_json_model(self):
     mock_responses = {
         'arvados.humans.get':
         (None,
          json.dumps(
              collections.OrderedDict(
                  (c, int(c, 16)) for c in string.hexdigits))),
     }
     req_builder = apiclient_http.RequestMockBuilder(mock_responses)
     api = arvados.api('v1',
                       host=os.environ['ARVADOS_API_HOST'],
                       token='discovery-doc-only-no-token-needed',
                       insecure=True,
                       requestBuilder=req_builder,
                       model=OrderedJsonModel())
     result = api.humans().get(uuid='test').execute()
     self.assertEqual(string.hexdigits, ''.join(result.keys()))