Esempio n. 1
0
    def test_search_documents(self):
        response = {'items': [{'id': 'abcdef'}, {'id': '1234'}]}

        requestBuilder = RequestMockBuilder({
            'drive.files.list': (None, json.dumps(response)),
        })

        GoogleDriveHelper.get_docs_client = Mock()
        GoogleDriveHelper.get_docs_client.return_value = apiclient.discovery.build(
            "drive", "v2", requestBuilder=requestBuilder)

        creator = User.objects.create_user('test-user')
        Training.objects.create(resource_id='resource_id_test',
                                title='toto',
                                creator=creator,
                                is_displayed=True,
                                is_deleted=False)
        Training.objects.create(resource_id='resource_id_test2',
                                title='tata',
                                creator=creator,
                                is_displayed=True,
                                is_deleted=False)

        search_results = GoogleDriveHelper.search_documents('toto')

        self.assertGreater(len(search_results), 0)
        self.assertIn('abcdef', search_results)
        self.assertIn('1234', search_results)
        self.assertIn('resource_id_test', search_results)
        self.assertNotIn('resource_id_test2', search_results)
Esempio n. 2
0
  def test_simple_response(self):
    requestBuilder = RequestMockBuilder({
        'plus.activities.get': (None, '{"data": {"foo": "bar"}}')
        })
    plus = build('plus', 'v1', http=self.http, requestBuilder=requestBuilder)

    activity = plus.activities().get(activityId='tag:blah').execute()
    self.assertEqual({"foo": "bar"}, activity)
Esempio n. 3
0
 def test_default_response(self):
     requestBuilder = RequestMockBuilder({})
     plus = build('plus',
                  'v1',
                  http=self.http,
                  requestBuilder=requestBuilder)
     activity = plus.activities().get(activityId='tag:blah').execute()
     self.assertEqual({}, activity)
Esempio n. 4
0
 def test_default_response(self):
     requestBuilder = RequestMockBuilder({})
     buzz = build('buzz',
                  'v1',
                  http=self.http,
                  requestBuilder=requestBuilder)
     activity = buzz.activities().get(postId='tag:blah',
                                      userId='@me').execute()
     self.assertEqual({}, activity)
Esempio n. 5
0
  def test_unexpected_call(self):
    requestBuilder = RequestMockBuilder({}, check_unexpected=True)

    plus = build('plus', 'v1', http=self.http, requestBuilder=requestBuilder)

    try:
      plus.activities().get(activityId='tag:blah').execute()
      self.fail('UnexpectedMethodError should have been raised')
    except UnexpectedMethodError:
      pass
Esempio n. 6
0
  def test_simple_matching_dict_body(self):
    requestBuilder = RequestMockBuilder({
        'zoo.animals.insert': (None, '{"data": {"foo": "bar"}}',
                                    {'data': {'foo': 'bar'}})
        })
    zoo = build('zoo', 'v1', http=self.zoo_http, requestBuilder=requestBuilder)

    activity = zoo.animals().insert(
        body={'data': {'foo': 'bar'}}).execute()
    self.assertEqual({'foo': 'bar'}, activity)
Esempio n. 7
0
  def test_simple_expected_body(self):
    requestBuilder = RequestMockBuilder({
        'zoo.animals.insert': (None, '{"data": {"foo": "bar"}}', '{}')
        })
    zoo = build('zoo', 'v1', http=self.zoo_http, requestBuilder=requestBuilder)

    try:
      zoo.animals().insert(body='').execute()
      self.fail('UnexpectedBodyError should have been raised')
    except UnexpectedBodyError:
      pass
Esempio n. 8
0
    def test_simple_response(self):
        requestBuilder = RequestMockBuilder(
            {'chili.activities.get': (None, '{"data": {"foo": "bar"}}')})
        buzz = build('buzz',
                     'v1',
                     http=self.http,
                     requestBuilder=requestBuilder)

        activity = buzz.activities().get(postId='tag:blah',
                                         userId='@me').execute()
        self.assertEqual({"foo": "bar"}, activity)
Esempio n. 9
0
    def setUp(self):
        super(ActivityViewTest, self).setUp()

        self.logger = LoggingHelper.getDebugLogger()

        response = {'items': [{'id': 'abcdef'}, {'id': '1234'}]}
        requestBuilder = RequestMockBuilder({
            'drive.files.list': (None, json.dumps(response)),
        })

        GoogleDriveHelper.get_docs_client = Mock()
        GoogleDriveHelper.get_docs_client.return_value = apiclient.discovery.build(
            "drive", "v2", requestBuilder=requestBuilder)
Esempio n. 10
0
  def test_errors(self):
    errorResponse = httplib2.Response({'status': 500, 'reason': 'Server Error'})
    requestBuilder = RequestMockBuilder({
        'plus.activities.list': (errorResponse, '{}')
        })
    plus = build('plus', 'v1', http=self.http, requestBuilder=requestBuilder)

    try:
      activity = plus.activities().list(collection='public', userId='me').execute()
      self.fail('An exception should have been thrown')
    except HttpError, e:
      self.assertEqual('{}', e.content)
      self.assertEqual(500, e.resp.status)
      self.assertEqual('Server Error', e.resp.reason)
Esempio n. 11
0
    def test_create_unistar_folder(self):
        response = {'id': 'abcdef'}

        requestBuilder = RequestMockBuilder({
            'drive.files.insert': (None, json.dumps(response)),
        })

        GoogleDriveHelper.get_docs_client = Mock()
        GoogleDriveHelper.get_docs_client.return_value = apiclient.discovery.build(
            "drive", "v2", requestBuilder=requestBuilder)

        user = User.objects.create_user('arnaud.breton', '*****@*****.**')
        self.assertEqual(GoogleDriveHelper.create_unistar_folder(user),
                         'abcdef')
Esempio n. 12
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 = RequestMockBuilder(mock_responses)
     cls.api = arvados.api('v1', cache=False,
                           host=os.environ['ARVADOS_API_HOST'],
                           token='discovery-doc-only-no-token-needed',
                           insecure=True,
                           requestBuilder=req_builder)