コード例 #1
0
ファイル: test_client.py プロジェクト: Komeil1978/grok-py
  def testCreateProject(self):
    '''
    Creating a project should make a well formatted call to the API
    '''

    # Create our client
    grok = Client(key = self.mockKey, connection = self.mockConnection)

    # Update the response for the next request
    response = {"project": {
                  "name": "API Doc project for retrieval",
                  "id": "dbbfc567-c409-4e7a-b06f-941f752e2f55",
                }}

    self.mockConnection.request.return_value = response

    # Make the call
    projectName = 'Foo'
    returnValue = grok.createProject(projectName)

    self.mockConnection.request.assert_called_with('POST',
                                                   self.projectsUrl,
                                                   {'project': {'name': projectName}})

    self.assertIsInstance(returnValue, Project)
コード例 #2
0
ファイル: test_client.py プロジェクト: Komeil1978/grok-py
  def testGetProject(self):
    '''
    Errors should be raised if called with default values
    Project should be returned
    '''
    # Inputs
    badId = 'YOUR_PROJECT_ID'
    goodId = 23887
    projectName = 'Foo'

    # Create our client
    grok = Client(key = self.mockKey, connection = self.mockConnection)

    # Update our mock's repsonse for the next request
    response = {'project': {'name': projectName, 'id': goodId}}
    self.mockConnection.request.return_value = response

    # Make the call that should error
    self.assertRaises(GrokError, grok.getProject, badId)

    # Make the good call
    returnValue = grok.getProject(goodId)

    expectedUrl = self.projectsUrl + '/' + str(goodId)
    self.mockConnection.request.assert_called_with('GET', expectedUrl)

    self.assertIsInstance(returnValue, Project)
コード例 #3
0
ファイル: test_client.py プロジェクト: Komeil1978/grok-py
  def testListProjects(self):
    '''
    Should make a well formatted call and return a list of Project instances
    '''

    # Create our client
    grok = Client(key = self.mockKey, connection = self.mockConnection)

    # Update our mock's repsonse for the next request
    response = {'projects': [{'name': 'project1', 'id': 1}, {'name': 'project2', 'id': 2}]}
    self.mockConnection.request.return_value = response

    # Make the call
    projects = grok.listProjects()

    self.mockConnection.request.assert_called_with('GET', self.projectsUrl,
                                                   params = {'all': True})

    self.assertIsInstance(projects, type([]))

    for project in projects:
      self.assertIsInstance(project, Project)