← Back to team overview

python-jenkins-developers team mailing list archive

[Bug 1317232] Re: Mock for job creation and editing methods

 

Marc Abramowitz setup a complete suite of unit tests for python-jenkins:
https://review.openstack.org/#/c/90500

We are currently at about 98% coverage for this package.  Would this
provide anything extra?

** Changed in: python-jenkins
     Assignee: (unassigned) => Khai Do (zaro0508)

-- 
You received this bug notification because you are a member of Python
Jenkins Developers, which is subscribed to Python Jenkins.
https://bugs.launchpad.net/bugs/1317232

Title:
  Mock for job creation and editing methods

Status in Python API for Jenkins:
  New

Bug description:
  I created this mock, but I have since opted to use Jenkins Job Builder
  instead of using python-jenkins directly.  I add it here as a "bug"
  not as a request for action, but so that it will be found if and when
  someone does request a mock.

  The mock works fine and comes with documentation and a unit test.  The
  thing that makes it unworthy of release is that it is limited to the
  job creation and editing methods.  The methods that control jobs and
  nodes are not implemented.

  Here is the docstring for the mock, so you can see what it does:
      
      Get the URL of the mocked Jenkins server:
      
      >>> jenkins = JenkinsMock('http://example.com')
      >>> jenkins.server
      'http://example.com/'

      >>> jenkins = JenkinsMock('http://example.com/')
      >>> jenkins.server
      'http://example.com/'
      
      Get the authorization headers:
      
      >>> jenkins = JenkinsMock('http://example.com/')
      >>> jenkins.auth   # Returns None
      
      >>> jenkins = JenkinsMock('http://example.com/',
      ...                       username='jmcgehee', password='secret')
      >>> jenkins.auth
      'Basic am1jZ2VoZWU6c2VjcmV0'
      
      Get the info on a job:
      
      >>> jenkins = JenkinsMock('http://example.com', job_infos={
      ...                       'job1': {'info1': 'dataw', 'info2': 'datax'},
      ...                       'job2': {'info1': 'datay', 'info2': 'dataz'}})
      >>> jenkins.get_job_info('job1')
      {'info1': 'dataw', 'info2': 'datax'}
      >>> jenkins.debug_job_info('job1')
      info1 dataw
      info2 datax
      
      Check whether a job exists.  Use ``job_exists()``.  ``get_job_name()``
      works, but it's weird:
      
      >>> jenkins = JenkinsMock('http://example.com', job_configs={
      ...                       'job1': EMPTY_CONFIG_XML,
      ...                       'job2': EMPTY_CONFIG_XML})
      >>> jenkins.job_exists('job1')
      True
      >>> jenkins.job_exists('nonexistent')
      False
      >>>
      >>> jenkins.get_job_name('job1')
      'job1'
      >>> jenkins.get_job_name('nonexistent')    # Returns None
     
      Copy a job:
      
       >>> jenkins = JenkinsMock('http://example.com',
       ...                       job_configs={'job1': EMPTY_CONFIG_XML,
       ...                                    'job2': EMPTY_CONFIG_XML},
       ...                       job_infos={
       ...                                  'job1': {'info1': 'dataw', 'info2': 'datax'},
       ...                                  'job2': {'info1': 'datay', 'info2': 'dataz'}})
      
      >>> jenkins.job_exists('newjob')
      False
      >>> jenkins.copy_job('job1', 'newjob')
      >>> jenkins.job_exists('newjob')
      True
      >>> jenkins.get_job_info('newjob')
      {'info1': 'dataw', 'info2': 'datax'}
      >>> jenkins.get_job_config('newjob') == EMPTY_CONFIG_XML
      True
      
       Rename a job:
      
       >>> jenkins = JenkinsMock('http://example.com',
       ...                       job_configs={'job1': EMPTY_CONFIG_XML,
       ...                                    'job2': EMPTY_CONFIG_XML},
       ...                       job_infos={
       ...                                  'job1': {'info1': 'dataw', 'info2': 'datax'},
       ...                                  'job2': {'info1': 'datay', 'info2': 'dataz'}})
      
      >>> jenkins.rename_job('job1', 'newjob')
      >>> jenkins.get_job_info('newjob')
      {'info1': 'dataw', 'info2': 'datax'}
      >>> jenkins.get_job_config('newjob') == EMPTY_CONFIG_XML
      True
      
      Delete a job:
      
       >>> jenkins = JenkinsMock('http://example.com',
       ...                       job_configs={'job1': EMPTY_CONFIG_XML,
       ...                                    'job2': EMPTY_CONFIG_XML},
       ...                       job_infos={
       ...                                  'job1': {'info1': 'dataw', 'info2': 'datax'},
       ...                                  'job2': {'info1': 'datay', 'info2': 'dataz'}})
      
      >>> jenkins.job_exists('job1')
      True
      >>> jenkins.delete_job('job1')
      >>> jenkins.job_exists('job1')
      False
      
      Create a job:
      
      >>> jenkins = JenkinsMock('http://example.com/')
      >>> jenkins.job_exists('newjob')
      False
      >>> jenkins.create_job('newjob',
      ...     "<?xml version='1.0' encoding='UTF-8'?><project/>")
      >>> jenkins.job_exists('newjob')
      True
      >>> jenkins.get_job_info('newjob') == EMPTY_INFO
      True
      >>> jenkins.get_job_config('newjob')
      "<?xml version='1.0' encoding='UTF-8'?><project/>"
      
      Change a job's config.xml configuration XML file:
      
      >>> jenkins = JenkinsMock('http://example.com/',
      ...                        job_configs={'job1': EMPTY_CONFIG_XML,
      ...                                     'job2': EMPTY_CONFIG_XML},
      ...                        job_infos={
      ...                                   'job1': {'info1': 'dataw', 'info2': 'datax'},
      ...                                   'job2': {'info1': 'datay', 'info2': 'dataz'}})
      >>> jenkins.get_job_config('job1') == EMPTY_CONFIG_XML
      True
      >>> jenkins.reconfig_job('job1',
      ...     "<?xml version='1.0' encoding='UTF-8'?><project/>")
      >>> jenkins.get_job_config('job1')
      "<?xml version='1.0' encoding='UTF-8'?><project/>"
      >>> jenkins.get_job_info('job1')
      {'info1': 'dataw', 'info2': 'datax'}

To manage notifications about this bug go to:
https://bugs.launchpad.net/python-jenkins/+bug/1317232/+subscriptions


References