Skip to content

Commit 285c156

Browse files
committed
Initial Commit
0 parents  commit 285c156

File tree

8 files changed

+257
-0
lines changed

8 files changed

+257
-0
lines changed

.gitignore

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
.idea**
2+
*.iml
3+
.pytest_cache
4+
**__pycache__**
5+
reports/
6+
rerun.txt
7+
venv*
8+
reports/
9+
features/
10+
download_steps*
11+
reconnect*
12+
dist/*
13+
dist/
14+
Makefile
15+
MANIFEST

LICENSE.txt

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020 AssertThat
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# assertthat-bdd
2+
Python plugin for interaction with [AssertThat BDD Jira plugin](https://marketplace.atlassian.com/1219033)
3+
4+
# Main features are:
5+
6+
Download feature files before test run
7+
Filter features to download based on mode (automated/manual/both), or/and JQL
8+
Upload cucumber json after the run to AsserTthat Jira plugin
9+
10+
# Installation
11+
To add the library to your project:
12+
13+
```pip install assertthat-bdd```
14+
15+
Full plugin configuration below, optional properties can be omitted.
16+
17+
project_id, access_key secret_key can be found from the [asserthat configuration page](https://assertthat.atlassian.net/wiki/spaces/ABTM/pages/725385217/Configuration)
18+
19+
```
20+
from assertthat_bdd.jira_integration import JiraConnector
21+
22+
JiraConnector.download_features(
23+
# Jira project id e.g. 10001
24+
project_id='PROJECT_ID',
25+
# Optional can be supplied as environment variable ASSERTTHAT_ACCESS_KEY
26+
access_key='ASSERTTHAT_ACCESS_KEY',
27+
# Optional can be supplied as environment variable ASSERTTHAT_SECRET_KEY
28+
secret_key='ASSERTTHAT_SECRET_KEY',
29+
# Optional - default ./features
30+
output_folder='./features',
31+
# Optional - all features downloaded by default - should be a valid JQL
32+
# jql = 'project = XX AND key in ('XXX-1')',
33+
# Optional - default automated (can be one of: manual/automated/both)
34+
mode='both',
35+
# Optional - Detail the proxy with the specific scheme e.g.'10.10.10.10:1010'
36+
# proxy_uri='proxyip:port',
37+
proxy_uri= 'proxy_uri',
38+
# Optional - user name which will be used for proxy authentication.*/
39+
proxy_username='username',
40+
# Optional - password which will be used for proxy authentication.*/
41+
proxy_password='password'
42+
)
43+
44+
JiraConnector.upload_report(
45+
# Jira project id e.g. 10001
46+
project_id='PROJECT_ID',
47+
# Optional can be supplied as environment variable ASSERTTHAT_ACCESS_KEY
48+
access_key='ASSERTTHAT_ACCESS_KEY',
49+
# Optional can be supplied as environment variable ASSERTTHAT_SECRET_KEY
50+
secret_key='ASSERTTHAT_SECRET_KEY',
51+
# The name of the run - default 'Test run dd MMM yyyy HH:mm:ss'
52+
run_name= 'Dry Tests Run',
53+
# Json report folder - default ./reports
54+
json_report_folder='./reports',
55+
# Regex to search for cucumber reports - default "\.json$"
56+
json_report_include_pattern='\.json$',
57+
# Optional - default cucumber (can be one of: cucumber/karate)
58+
type='cucumber'',
59+
# Optional - Detail the proxy with the specific scheme e.g.'10.10.10.10:1010'
60+
# proxy_uri='proxyip:port',
61+
# Optional - user name which will be used for proxy authentication.*/
62+
proxy_username='username',
63+
# Optional - password which will be used for proxy authentication.*/
64+
proxy_password='password'
65+
)
66+
```
67+
68+
# Usage
69+
We recommend running cucumber tests on integration-test phase as
70+
71+
- download features is running on pre-integration-test phase
72+
- report submission on post-integration-test
73+
74+
# Example project
75+
Refer to example project - https://github.com/assertthat/assertthat-behave-example

assertthat_bdd/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from assertthat_bdd.jira_integration import JiraConnector

assertthat_bdd/jira_integration.py

+118
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
import requests
2+
from zipfile import ZipFile
3+
from io import BytesIO
4+
import datetime
5+
import os
6+
import json
7+
import re
8+
9+
class JiraConnector:
10+
11+
def download_features(project_id, access_key=None, secret_key=None, output_folder='./features/', jql=None, mode='automated',
12+
proxy_uri=None, proxy_username=None, proxy_password=None):
13+
14+
if access_key is None:
15+
if os.environ.get("ASSERTTHAT_ACCESS_KEY") is None:
16+
print("[ERROR] ASSERTTHAT_ACCESS_KEY is missing, should be provided as environment variable or parameter")
17+
else:
18+
access_key = os.environ.get("ASSERTTHAT_ACCESS_KEY")
19+
20+
if secret_key is None:
21+
if os.environ.get("ASSERTTHAT_SECRET_KEY") is None:
22+
print("[ERROR] ASSERTTHAT_SECRET_KEY is missing, should be provided as environment variable or parameter")
23+
else:
24+
secret_key = os.environ.get("ASSERTTHAT_SECRET_KEY")
25+
26+
path = 'https://bdd.assertthat.com/rest/api/1/project/' + project_id + '/features'
27+
headers = {}
28+
payload = {'mode': mode,
29+
'jql': jql
30+
}
31+
print('Fetching from: ' + path)
32+
33+
if proxy_uri is None:
34+
proxies = None
35+
36+
elif proxy_uri is not None:
37+
if proxy_username is None:
38+
proxy_http = "http://%s" % (proxy_uri)
39+
proxy_https = "https://%s" % (proxy_uri)
40+
elif proxy_username is not None:
41+
proxy_http = "http://%s:%s@%s" % (proxy_username, proxy_password, proxy_uri)
42+
proxy_https = "https://%s:%s@%s" % (proxy_username, proxy_password, proxy_uri)
43+
proxies = {'http': proxy_http,
44+
'https': proxy_https
45+
}
46+
47+
try:
48+
response = requests.get(path, auth=(access_key, secret_key), headers=headers, params=payload,
49+
proxies=proxies)
50+
51+
if response.status_code == 200:
52+
print('Fetched.')
53+
print('Preparing to extract...')
54+
zip = ZipFile(BytesIO(response.content))
55+
infolist = zip.infolist()
56+
zip.extractall(path=output_folder)
57+
print('[INFO] Downloaded ' + str(infolist.__len__()) + ' feature files into "' + output_folder + '"')
58+
59+
response.raise_for_status()
60+
61+
except requests.exceptions.HTTPError as errh:
62+
response_content = response.content
63+
print("[ERROR] Failed to download features %s" % (response_content))
64+
65+
except requests.exceptions.RequestException as err:
66+
print("[ERROR] Failed to download features", err)
67+
68+
def upload_report(project_id, access_key, secret_key,
69+
run_name='Test run ' + datetime.datetime.now().strftime("%d %b %Y %H:%M:%S"),
70+
json_report_folder='./reports/', json_report_include_pattern='\.json$', type='cucumber',
71+
proxy_uri=None, proxy_username=None, proxy_password=None):
72+
73+
path = 'https://bdd.assertthat.com/rest/api/1/project/' + project_id + '/report'
74+
75+
if proxy_uri is None:
76+
proxies = None
77+
78+
elif proxy_uri is not None:
79+
if proxy_username is None:
80+
proxy_http = "http://%s" % proxy_uri
81+
proxy_https = "https://%s" % proxy_uri
82+
elif proxy_username is not None:
83+
proxy_http = "http://%s:%s@%s" % (proxy_username, proxy_password, proxy_uri)
84+
proxy_https = "https://%s:%s@%s" % (proxy_username, proxy_password, proxy_uri)
85+
proxies = {'http': proxy_http,
86+
'https': proxy_https
87+
}
88+
89+
runId = '-1'
90+
for subdir, dirs, files in os.walk(json_report_folder):
91+
print("[INFO] Uploading json reports to AssertThat for %s " % files)
92+
for file in files:
93+
if re.search(r"%s" % json_report_include_pattern, file):
94+
report_file = os.path.join(subdir, file)
95+
upload_file = {'file': open(report_file, 'rb')}
96+
97+
headers = {}
98+
payload = {'runName': run_name,
99+
'type': type,
100+
'runId': runId
101+
}
102+
103+
try:
104+
response = requests.post(path, auth=(access_key, secret_key), headers=headers, params=payload,
105+
files=upload_file, proxies=proxies)
106+
response_content = json.loads(response.content)
107+
108+
if response.status_code == 200:
109+
runId = response_content['runId']
110+
print("[INFO] Uploaded report file %s to AssertThat" % file)
111+
112+
response.raise_for_status()
113+
114+
except requests.exceptions.HTTPError as errh:
115+
print("[ERROR] %s while uploading %s" % (response_content['message'], file))
116+
117+
except requests.exceptions.RequestException as err:
118+
print("[ERROR] Failed to send request", err)

requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
requests

setup.cfg

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Inside of setup.cfg
2+
[metadata]
3+
description-file = README.md

setup.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from distutils.core import setup
2+
setup(
3+
name = 'assertthat-bdd', # How you named your package folder (MyLib)
4+
packages = ['assertthat_bdd'], # Chose the same as "name"
5+
version = '1.0', # Start with a small number and increase it with every change you make
6+
license='MIT', # Chose a license from here: https://help.github.com/articles/licensing-a-repository
7+
description = 'Python tools for integration with AssertThat BDD plugin for Jira', # Give a short description about your library
8+
author = 'Nick Iles', # Type in your name
9+
author_email = '[email protected]', # Type in your E-Mail
10+
url = 'https://github.com/assertthat/assertthat-bdd-python', # Provide either the link to your github or to your website
11+
download_url = 'https://github.com/assertthat/assertthat-bdd-python/archive/1.tar.gz',
12+
keywords = ['assertthat', 'bdd', 'Jira', 'download features', 'upload features'], # Keywords that define your package best
13+
install_requires=[
14+
'requests',
15+
],
16+
classifiers=[
17+
'Development Status :: 3 - Alpha', # Chose either "3 - Alpha", "4 - Beta" or "5 - Production/Stable" as the current state of your package
18+
'Intended Audience :: Developers', # Define that your audience are developers or testers
19+
'Topic :: Software Development :: Build Tools',
20+
'License :: OSI Approved :: MIT License', # Again, pick a license
21+
'Programming Language :: Python :: 3', #Specify which pyhton versions that you want to support
22+
],
23+
)

0 commit comments

Comments
 (0)