Skip to content

Commit

Permalink
Release 0.1.1 (#4)
Browse files Browse the repository at this point in the history
Release 0.1.1
  • Loading branch information
okgolove authored Mar 7, 2018
1 parent 00837b1 commit 3fa8e51
Show file tree
Hide file tree
Showing 13 changed files with 263 additions and 60 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
Expand Down Expand Up @@ -101,3 +100,5 @@ ENV/
.mypy_cache/

.pre-commit-config.yaml
Pipfile

26 changes: 24 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,34 @@ Introduction
------------

JenkinsLibrary is a Robot Framework test
library which helps you to involve Jenkins in your tests.

library which helps you to involve Jenkins in your tests.

Installation
------------

Just run:

pip install robotframework-jenkins

Usage
------------

You need to import Jenkins library:

*** Settings ***
Library JenkinsLibrary
Then, you need to initialize Jenkins server with keyword:

Set Jenkins Server url=http://example.com:8080 username=admin password=admin

Example
------------
*** Settings ***
Library JenkinsLibrary

*** Test Cases ***
Jenkins Create And Run Job
[Setup] Set Jenkins Server url=http://example.com:8080 username=admin password=admin
Create Jenkins Job test_job
Start Jenkins Job test_job

11 changes: 11 additions & 0 deletions atest/__init__.robot
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ Suite Setup Global Setup

*** Variables ***
${url} http://127.0.0.1:8080
${templates_dir} templates
${job_parameterized_scratch} job_parameterized_scratch.xml
&{job_parameterized_scratch_parameters} param_string=expected_string param_bool=False
${test_job_name} test_job
${second_test_job_name} blablabla_job


*** Keywords ***
Wait For Container
Expand All @@ -12,4 +18,9 @@ Wait For Container

Global Setup
Set Global Variable ${jenkins_address} ${url}
Set Global Variable ${templates_dir} atest/${templates_dir}
Set Global Variable ${job_parameterized_scratch} ${job_parameterized_scratch}
Set Global Variable ${test_job_name} ${test_job_name}
Set Global Variable ${second_test_job_name} ${second_test_job_name}
Set Global Variable ${job_parameterized_scratch_parameters} &{job_parameterized_scratch_parameters}
Wait For Container
1 change: 1 addition & 0 deletions atest/basic.robot
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
*** Settings ***
Library JenkinsLibrary
Resource lib/jenkins_keywords.robot

*** Test Cases ***
Keyword Without Init
Expand Down
25 changes: 14 additions & 11 deletions atest/builds.robot
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
*** Settings ***
Library JenkinsLibrary
Resource lib/jenkins_keywords.robot
Suite Setup Set Jenkins Server url=${jenkins_address} username=admin password=admin

*** Variables ***
${test_job_name} test_job

*** Test Cases ***
Get Builds (inexistent job)
[Tags] job build
Run Keyword And Expect Error There is no specified job in Jenkins: ${test_job_name}\
... Get Jenkins Job Builds ${test_job_name}

Get Builds (existent jobs, multiple builds)
[Tags] job build
[Setup] Create Job And Run Multiple Builds
[Setup] Create Job And Run Multiple Builds ${test_job_name} count=3
[Teardown] Delete Jenkins Job ${test_job_name}
${builds} = Get Jenkins Job Builds ${test_job_name}
Should Be True ${builds}
Log ${builds}
Should Be Equal As Integers 1 ${builds['builds'][2]['number']}
Should Be Equal As Integers 2 ${builds['builds'][1]['number']}
Should Be Equal As Integers 3 ${builds['builds'][0]['number']}
Expand All @@ -29,9 +27,14 @@ Get Builds (existent jobs, no builds)
Should Not Be True ${builds['lastBuild']}
Should Be Equal As Integers 1 ${builds['nextBuildNumber']}

*** Keywords ***
Create Job And Run Multiple Builds
Create Jenkins Job ${test_job_name}
Start Jenkins Job ${test_job_name}
Start Jenkins Job ${test_job_name}
Start Jenkins Job ${test_job_name}
Get Next Build Number
[Tags] job build
[Setup] Create Jenkins Job ${test_job_name}
[Teardown] Delete Jenkins Job ${test_job_name}
${random_int} = Evaluate random.randint(2, 10) modules=random
:FOR ${run} IN RANGE ${random_int}
\ ${next_build_before} = Get Next Build Number ${test_job_name}
\ Should Be Equal As Integers ${run + 1} ${next_build_before}
\ Start Jenkins Job ${test_job_name}
\ ${next_build_after} = Get Next Build Number ${test_job_name}
\ Should Be Equal As Integers ${run + 2} ${next_build_after}
39 changes: 31 additions & 8 deletions atest/execute.robot
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
*** Settings ***
Library Collections
Library JenkinsLibrary
Resource lib/jenkins_keywords.robot
Suite Setup Set Jenkins Server url=${jenkins_address} username=admin password=admin

*** Variables ***
${test_job_name} test_job

*** Test Cases ***
Wrong Params Type
[Tags] execute
Expand All @@ -14,16 +12,41 @@ Wrong Params Type
Run Keyword And Expect Error Params must be a dictionary, not *\
... Start Jenkins Job ${test_job_name} test_string

Run Existent Job Without Params
Run Inexistent Job
[Tags] execute
Run Keyword And Expect Error Can't find specified job: ${test_job_name}\
... Start Jenkins Job ${test_job_name}

Run Existent Unparameterized Job Without Params
[Tags] execute
[Setup] Create Jenkins Job ${test_job_name}
[Teardown] Delete Jenkins Job ${test_job_name}
Start Jenkins Job ${test_job_name}

Run Inexistent Job
Run Existent Unparameterized Job With Params
[Tags] execute
Run Keyword And Expect Error There is no specified job in Jenkins: ${test_job_name}\
... Start Jenkins Job ${test_job_name}
[Setup] Create Jenkins Job ${test_job_name}
[Teardown] Delete Jenkins Job ${test_job_name}
Run Keyword And Expect Error This is not parameterized job, you don't have to no specify params dicitionary\
... Start Jenkins Job ${test_job_name} ${job_parameterized_scratch_parameters}

Run Existent Parameterized Job With Params
[Tags] execute
[Setup] Create Job From Template ${test_job_name} ${job_parameterized_scratch}
[Teardown] Delete Jenkins Job ${test_job_name}
${build} = Start Jenkins Job ${test_job_name} ${job_parameterized_scratch_parameters}

# TODO: Test with params, also add functionality for methods (params)
Run Existent Parameterized Job Without Params
[Tags] execute
[Setup] Create Job From Template ${test_job_name} ${job_parameterized_scratch}
[Teardown] Delete Jenkins Job ${test_job_name}
Run Keyword And Expect Error This is parameterized job, you have to specify params dicitionary\
... Start Jenkins Job ${test_job_name}

Compare Nuild Number
[Tags] execute
[Setup] Create Jenkins Job ${test_job_name}
[Teardown] Delete Jenkins Job ${test_job_name}
${build_number} = Start Jenkins Job ${test_job_name}
${next_build_before} = Get Next Build Number ${test_job_name}
Should Be Equal As Integers ${next_build_before} ${build_number + 1}
54 changes: 30 additions & 24 deletions atest/jobs.robot
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
*** Settings ***
Library Collections
Library OperatingSystem
Library JenkinsLibrary
Resource lib/jenkins_keywords.robot
Suite Setup Set Jenkins Server url=${jenkins_address} username=admin password=admin

*** Variables ***
${test_job_name} test_job
${second_test_job_name} blablabla_job

*** Test Cases ***
Get One Existent Job
[Tags] job
Expand Down Expand Up @@ -38,6 +36,15 @@ Create Existent Job
Run Keyword And Expect Error Specified job already exists: ${test_job_name}\
... Create Jenkins Job ${test_job_name}

Create Job From Template
[Tags] job
[Setup] Create Job From Template ${test_job_name} ${job_parameterized_scratch}
[Teardown] Delete Jenkins Job ${test_job_name}
${parameters} = Get Jenkins Job Parameters ${test_job_name}
Should Be True ${parameters}
Should Be Equal param_string ${parameters[0]['name']}
Should Be Equal param_bool ${parameters[1]['name']}

Delete Inexistent Job
[Tags] job
Run Keyword And Expect Error There is no specified job in Jenkins: ${test_job_name}\
Expand Down Expand Up @@ -65,25 +72,24 @@ Disable Enabled Job
[Teardown] Delete Jenkins Job ${test_job_name}
Disable Jenkins Job ${test_job_name}

*** Keywords ***
Create And Disable Job
Create Jenkins Job ${test_job_name}
Disable Jenkins Job ${test_job_name}

Create Multiple Jobs
Create Jenkins Job ${test_job_name}
Create Jenkins Job ${second_test_job_name}
Get Job XML
[Tags] job
[Setup] Create Jenkins Job ${test_job_name}
[Teardown] Delete Jenkins Job ${test_job_name}
${job_xml} = Get Jenkins Job XML ${test_job_name}
Should Start With ${job_xml} <?xml version=

Delete Multiple Jobs
Delete Jenkins Job ${test_job_name}
Delete Jenkins Job ${second_test_job_name}
Get Job And Compare XML
[Tags] job
[Setup] Create Job From Template ${test_job_name} ${job_parameterized_scratch}
[Teardown] Delete Jenkins Job ${test_job_name}
${job_xml} = Get Jenkins Job XML ${test_job_name}
${template_xml} = Get File ${templates_dir}/${job_parameterized_scratch}
Should Be Equal As Strings ${job_xml} ${template_xml}

Check Multiple Jobs
${jobs} = Get Jenkins Jobs
Should Be True ${jobs}
${second_job} = Get From List ${jobs} 0
Should Be Equal ${second_job['name']} ${second_test_job_name}
Should Be Equal ${second_job['url']} ${jenkins_address}/job/${second_test_job_name}/
${first_job} = Get From List ${jobs} 1
Should Be Equal ${first_job['name']} ${test_job_name}
Should Be Equal ${first_job['url']} ${jenkins_address}/job/${test_job_name}/
Check Job Parameters (parameters is inexistent)
[Tags] job
[Setup] Create Jenkins Job ${test_job_name}
[Teardown] Delete Jenkins Job ${test_job_name}
${parameters} = Get Jenkins Job Parameters ${test_job_name}
Should Not Be True ${parameters}
38 changes: 38 additions & 0 deletions atest/lib/jenkins_keywords.robot
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
*** Settings ***
Library Collections
Library OperatingSystem
Library JenkinsLibrary

*** Keywords ***
Create And Disable Job
Create Jenkins Job ${test_job_name}
Disable Jenkins Job ${test_job_name}

Create Multiple Jobs
Create Jenkins Job ${test_job_name}
Create Jenkins Job ${second_test_job_name}

Delete Multiple Jobs
Delete Jenkins Job ${test_job_name}
Delete Jenkins Job ${second_test_job_name}

Check Multiple Jobs
${jobs} = Get Jenkins Jobs
Should Be True ${jobs}
${second_job} = Get From List ${jobs} 0
Should Be Equal ${second_job['name']} ${second_test_job_name}
Should Be Equal ${second_job['url']} ${jenkins_address}/job/${second_test_job_name}/
${first_job} = Get From List ${jobs} 1
Should Be Equal ${first_job['name']} ${test_job_name}
Should Be Equal ${first_job['url']} ${jenkins_address}/job/${test_job_name}/

Create Job From Template
[Arguments] ${job_name} ${template_file}
${template} = Get File ${templates_dir}/${template_file}
Create Jenkins Job ${job_name} ${template}

Create Job And Run Multiple Builds
[Arguments] ${job_name} ${count}=2
Create Jenkins Job ${job_name}
:FOR ${run} IN RANGE ${count}
\ Start Jenkins Job ${job_name}
37 changes: 37 additions & 0 deletions atest/templates/job_parameterized_scratch.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.1" encoding="UTF-8"?><project>
<description/>
<keepDependencies>false</keepDependencies>
<properties>
<hudson.model.ParametersDefinitionProperty>
<parameterDefinitions>
<hudson.model.StringParameterDefinition>
<name>param_string</name>
<description/>
<defaultValue>param_string</defaultValue>
<trim>false</trim>
</hudson.model.StringParameterDefinition>
<hudson.model.BooleanParameterDefinition>
<name>param_bool</name>
<description/>
<defaultValue>true</defaultValue>
</hudson.model.BooleanParameterDefinition>
</parameterDefinitions>
</hudson.model.ParametersDefinitionProperty>
</properties>
<scm class="hudson.scm.NullSCM"/>
<canRoam>true</canRoam>
<disabled>false</disabled>
<blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
<blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
<triggers/>
<concurrentBuild>false</concurrentBuild>
<builders>
<hudson.tasks.Shell>
<command>echo $param_shell
echo $param_bool
sleep 15</command>
</hudson.tasks.Shell>
</builders>
<publishers/>
<buildWrappers/>
</project>
21 changes: 18 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from os.path import join, dirname
from setuptools import setup
from setuptools import setup, find_packages

exec(open(join(dirname(__file__),
'src', 'JenkinsLibrary', 'version.py')).read())
Expand All @@ -11,15 +11,30 @@
'requests==2.18.4'
]

CLASSIFIERS = '''
License :: OSI Approved :: Apache Software License
Development Status :: 5 - Production/Stable
Programming Language :: Python :: 2
Programming Language :: Python :: 2.7
Programming Language :: Python :: 3
Programming Language :: Python :: 3.3
Programming Language :: Python :: 3.4
Programming Language :: Python :: 3.5
Programming Language :: Python :: 3.6
Topic :: Software Development :: Testing
Framework :: Robot Framework
'''

setup(
name=PACKAGE,
package_dir={'': 'src'},
packages=['JenkinsLibrary'],
packages=find_packages('src'),
version=VERSION,
description=DESCRIPTION,
author='Mikhail Naletov',
author_email='[email protected]',
url='https://github.com/okgolove/robotframework-jenkins',
keywords=['jenkins', 'robotframework', 'robot', 'testing'],
install_requires=REQUIREMENTS
classifiers=CLASSIFIERS,
install_requires=REQUIREMENTS,
)
Loading

0 comments on commit 3fa8e51

Please sign in to comment.