-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Basic keywords
- Loading branch information
Showing
15 changed files
with
435 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -99,3 +99,5 @@ ENV/ | |
|
||
# mypy | ||
.mypy_cache/ | ||
|
||
.pre-commit-config.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
language: python | ||
python: | ||
- "2.7" | ||
- "3.3" | ||
- "3.4" | ||
- "3.5" | ||
- "3.6" | ||
|
||
services: | ||
- docker | ||
|
||
before_install: | ||
- docker build --pull -t jenkins-test atest/docker | ||
- docker run -p 127.0.0.1:8080:8080 -e JAVA_OPTS=-Djenkins.install.runSetupWizard=false -d jenkins-test | ||
|
||
install: | ||
- pip install . | ||
|
||
script: | ||
- robot --loglevel DEBUG atest/ | ||
|
||
notifications: | ||
webhooks: | ||
- https://fathomless-fjord-24024.herokuapp.com/notify |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
[](https://travis-ci.org/okgolove/robotframework-jenkins) | ||
|
||
JenkinsLibrary for Robot Framework | ||
============================== | ||
|
||
Introduction | ||
------------ | ||
|
||
JenkinsLibrary is a Robot Framework test | ||
library which helps you to involve Jenkins in your tests. | ||
|
||
|
||
Installation | ||
------------ | ||
|
||
Just run: | ||
|
||
pip install robotframework-jenkins |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
*** Settings *** | ||
Library JenkinsLibrary | ||
Suite Setup Global Setup | ||
|
||
*** Variables *** | ||
${url} http://127.0.0.1:8080 | ||
|
||
*** Keywords *** | ||
Wait For Container | ||
Wait Until Keyword Succeeds 2 min 5 sec\ | ||
... Is Jenkins Up url=${jenkins_address} | ||
|
||
Global Setup | ||
Set Global Variable ${jenkins_address} ${url} | ||
Wait For Container |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
*** Settings *** | ||
Library JenkinsLibrary | ||
|
||
*** Test Cases *** | ||
Keyword Without Init | ||
[Tags] init auth | ||
Run Keyword And Expect Error Jenkins server was not initialized Get Jenkins Job By Name example | ||
|
||
Normal Init Jenkins | ||
[Tags] init auth | ||
Set Jenkins Server url=${jenkins_address} username=admin password=admin | ||
|
||
Wrong Username | ||
[Tags] init auth | ||
Run Keyword And Expect Error Can't connect to Jenkins: Error in request. Possibly authentication failed [401]: Invalid password/token for user: nimda\ | ||
... Set Jenkins Server url=${jenkins_address} username=nimda password=admin | ||
|
||
Wrong Password | ||
[Tags] init auth | ||
Run Keyword And Expect Error Can't connect to Jenkins: Error in request. Possibly authentication failed [401]: Invalid password/token for user: admin\ | ||
... Set Jenkins Server url=${jenkins_address} username=admin password=nimda | ||
|
||
Wrong URL | ||
[Tags] init auth | ||
Run Keyword And Expect Error Can't connect to Jenkins: Error in request: [Errno 111] Connection refused\ | ||
... Set Jenkins Server url=http://127.1.1.1 username=admin password=admin | ||
|
||
All Of These Are Wrong | ||
[Tags] init auth | ||
Run Keyword And Expect Error Can't connect to Jenkins: Error in request: [Errno 111] Connection refused\ | ||
... Set Jenkins Server url=http://127.0.0.1:11111 username=nimda password=nimda |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
*** Settings *** | ||
Library JenkinsLibrary | ||
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 | ||
[Teardown] Delete Jenkins Job ${test_job_name} | ||
${builds} = Get Jenkins Job Builds ${test_job_name} | ||
Should Be True ${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']} | ||
|
||
Get Builds (existent jobs, no builds) | ||
[Tags] job build | ||
[Setup] Create Jenkins Job ${test_job_name} | ||
[Teardown] Delete Jenkins Job ${test_job_name} | ||
${builds} = Get Jenkins Job Builds ${test_job_name} | ||
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} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
FROM jenkins/jenkins:latest | ||
|
||
COPY set_password.groovy /usr/share/jenkins/ref/init.groovy.d/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!groovy | ||
import hudson.security.* | ||
import jenkins.model.* | ||
|
||
def instance = Jenkins.getInstance() | ||
def hudsonRealm = new HudsonPrivateSecurityRealm(false) | ||
def users = hudsonRealm.getAllUsers() | ||
users_s = users.collect { it.toString() } | ||
if ('admin' in users_s) { | ||
println "Admin user already exists" | ||
} else { | ||
println "--> creating local admin user" | ||
|
||
hudsonRealm.createAccount('admin', 'admin') | ||
instance.setSecurityRealm(hudsonRealm) | ||
|
||
def strategy = new FullControlOnceLoggedInAuthorizationStrategy() | ||
instance.setAuthorizationStrategy(strategy) | ||
instance.save() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
*** Settings *** | ||
Library Collections | ||
Library JenkinsLibrary | ||
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 | ||
[Setup] Create Jenkins Job ${test_job_name} | ||
[Teardown] Delete Jenkins Job ${test_job_name} | ||
Run Keyword And Expect Error Params must be a dictionary, not *\ | ||
... Start Jenkins Job ${test_job_name} test_string | ||
|
||
Run Existent 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 | ||
[Tags] execute | ||
Run Keyword And Expect Error There is no specified job in Jenkins: ${test_job_name}\ | ||
... Start Jenkins Job ${test_job_name} | ||
|
||
|
||
# TODO: Test with params, also add functionality for methods (params) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
*** Settings *** | ||
Library Collections | ||
Library JenkinsLibrary | ||
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 | ||
[Setup] Create Jenkins Job ${test_job_name} | ||
[Teardown] Delete Jenkins Job ${test_job_name} | ||
${job} = Get Jenkins Job By Name ${test_job_name} | ||
Should Be True ${job} | ||
|
||
Get Inexistent Job | ||
[Tags] job | ||
Run Keyword And Expect Error Can't find specified job: ${test_job_name}\ | ||
... Get Jenkins Job By Name ${test_job_name} | ||
|
||
Get Jobs (empty Jenkins) | ||
[Tags] job | ||
${jobs} = Get Jenkins Jobs | ||
Should Not Be True ${jobs} | ||
|
||
Get Jobs (multiple jobs) | ||
[Tags] job | ||
[Setup] Create Multiple Jobs | ||
[Teardown] Delete Multiple Jobs | ||
Check Multiple Jobs | ||
|
||
Create Existent Job | ||
[Tags] job | ||
[Setup] Create Jenkins Job ${test_job_name} | ||
[Teardown] Delete Jenkins Job ${test_job_name} | ||
Run Keyword And Expect Error Specified job already exists: ${test_job_name}\ | ||
... Create Jenkins Job ${test_job_name} | ||
|
||
Delete Inexistent Job | ||
[Tags] job | ||
Run Keyword And Expect Error There is no specified job in Jenkins: ${test_job_name}\ | ||
... Delete Jenkins Job ${test_job_name} | ||
|
||
Disable Inexistent Job | ||
[Tags] job | ||
Run Keyword And Expect Error There is no specified job in Jenkins: ${test_job_name}\ | ||
... Disable Jenkins Job ${test_job_name} | ||
|
||
Enable Inexistent Job | ||
[Tags] job | ||
Run Keyword And Expect Error There is no specified job in Jenkins: ${test_job_name}\ | ||
... Disable Jenkins Job ${test_job_name} | ||
|
||
Enable Disabled Job | ||
[Tags] job | ||
[Setup] Create And Disable Job | ||
[Teardown] Delete Jenkins Job ${test_job_name} | ||
Enable Jenkins Job ${test_job_name} | ||
|
||
Disable Enabled Job | ||
[Tags] job | ||
[Setup] Create Jenkins Job ${test_job_name} | ||
[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} | ||
|
||
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}/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from os.path import join, dirname | ||
from setuptools import setup | ||
|
||
exec(open(join(dirname(__file__), | ||
'src', 'JenkinsLibrary', 'version.py')).read()) | ||
PACKAGE = 'robotframework-jenkins' | ||
DESCRIPTION = '''Library for Robot Framework for Jenkins interaction''' | ||
REQUIREMENTS = [ | ||
'python-jenkins==0.4.15', | ||
'robotframework==3.0.2', | ||
'requests==2.18.4' | ||
] | ||
|
||
setup( | ||
name=PACKAGE, | ||
package_dir={'': 'src'}, | ||
packages=['JenkinsLibrary'], | ||
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 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .library import JenkinsLibrary |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import requests | ||
from .server import Server | ||
from .version import VERSION | ||
|
||
__version__ = VERSION | ||
|
||
|
||
class JenkinsLibrary(object): | ||
ROBOT_LIBRARY_SCOPE = 'GLOBAL' | ||
ROBOT_LIBRARY_VERSION = __version__ | ||
|
||
def __init__(self): | ||
self.jenkins = Server() | ||
|
||
def set_jenkins_server(self, url, username, password): | ||
self.jenkins.initialize(url=url, username=username, password=password) | ||
|
||
def is_jenkins_up(self, url): | ||
try: | ||
r = requests.get("{0}/login".format(url)) | ||
except requests.ConnectionError: | ||
raise RuntimeError('Jenkins server {0} is not available') | ||
else: | ||
if r.status_code != 200: | ||
raise RuntimeError( | ||
'Jenkins server {0} is not available, status code:{1}'. | ||
format(url, r.status_code)) | ||
|
||
def get_jenkins_jobs(self): | ||
return self.jenkins.get_jobs() | ||
|
||
def get_jenkins_job_by_name(self, name): | ||
return self.jenkins.get_job(name) | ||
|
||
def create_jenkins_job(self, name): | ||
self.jenkins.create_job(name) | ||
|
||
def delete_jenkins_job(self, name): | ||
self.jenkins.delete_job(name) | ||
|
||
def disable_jenkins_job(self, name): | ||
self.jenkins.disable_job(name) | ||
|
||
def enable_jenkins_job(self, name): | ||
self.jenkins.enable_job(name) | ||
|
||
def start_jenkins_job(self, name, params={}): | ||
self.jenkins.build_job(name, params) | ||
|
||
def get_jenkins_job_builds(self, name): | ||
return self.jenkins.get_builds(name) |
Oops, something went wrong.