Ejemplo n.º 1
0
  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)
Ejemplo n.º 2
0
  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)
Ejemplo n.º 3
0
  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)