Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Make it auto generate a test run #11

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .github/scripts/create-pythonenv.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
!/bin/sh
#This script will create an env envirment if it dons't exist, insatll and update [pip wheel setuptools] and install all the nededed dependencies

ENV_DIR="env"
[ -d "${ENV_DIR}" ] && echo "Python Environment $ENV_DIR found." || echo "Python Environment $ENV_DIR not found."
[ ! -d "${ENV_DIR}" ] && python -m venv $ENV_DIR

./$ENV_DIR/Scripts/python -m ./$ENV_DIR/Scripts/pip install -U pip wheel setuptools
./$ENV_DIR/Scripts/pip install -e .[dev]
2 changes: 1 addition & 1 deletion .github/workflows/pyplugin-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [3.6,3.7, 3.8, 3.9]
python-version: [3.7, 3.8, 3.9]

steps:
- uses: actions/checkout@v2
Expand Down
3 changes: 3 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
include .bumpversion.cfg
include pytest.ini
recursive-include tests *.py
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
long_description=LONG_DESCRIPTION,
long_description_content_type=LONG_DESC_TYPE,
py_modules=["pytest_pyqatouch"],
python_requires=">=3.6",
python_requires=">=3.7",
install_requires=PKG_REQUIREMENTS,
extras_require={"dev": DEV_REQUIREMENTS},
packages=find_packages("src"),
Expand All @@ -57,7 +57,6 @@
"Intended Audience :: Developers",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
Expand Down
89 changes: 89 additions & 0 deletions src/pytest_qatouch/apis_calls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
class WrongQatouchStatus(Exception):
"""Exception for passing a wrong test cases status"""

pass


class MissingQatouchData(Exception):
"""Exception for passing a wrong test cases status"""

pass


class ExpectedIntegerValue(Exception):
"""Exception for passing non integer value"""

pass


class QatouchRequestError(Exception):
"""Exception for faild requests"""

pass


import asyncio
import aiohttp
import re, json, time
from aiolimiter import AsyncLimiter

ref = time.time()


async def get_tcs(session, limiter, url, page_num, headers, get_lastlink=False):
await asyncio.sleep(page_num * 0.01)
async with limiter:
print(f"{page_num:>2d}: Drip! {time.time() - ref:>5.2f}")
async with session.get(f"{url}&page={page_num}", headers=headers) as response:
if response.status == 200:
res = await response.json()
if res.get("data"):
tc_keys = []
for tc in res.get("data"):
tc_keys.append(tc["case_key"])

# print(f"\nThe qatouch request updated test run successfully {json.dumps(res)}")
if get_lastlink:
return tc_keys, res["link"]["last"]
else:
return tc_keys

else:
raise QatouchRequestError(f"The qatouch request failed with {[res.get('msg')]}")

else:
raise QatouchRequestError(
f"""Expected to have 200 for the qatoch request but got {response.status},
Please make sure the specified domain and API token are right."""
)


async def get_all_tcs(limiter, url, headers):
pagination_pages = 1
async with aiohttp.ClientSession() as session:
first_tcs_keys, link = await get_tcs(session, limiter, url, 1, headers, get_lastlink=True)
pagination_pages = int(re.search("(?<=page\\=)\\d+", link).group())
print(pagination_pages)
if pagination_pages == 1:
return first_tcs_keys

tasks = [get_tcs(session, limiter, url, i, headers) for i in range(2, pagination_pages + 1)]
groups = await asyncio.gather(*tasks)
tcs_keys = first_tcs_keys
for group in groups:
tcs_keys = tcs_keys + group

return tcs_keys


def get_qatouch_tcs_key(url, headers):
limiter = AsyncLimiter(max_rate=4, time_period=15)
return asyncio.get_event_loop().run_until_complete(get_all_tcs(limiter, url, headers))


URL = "https://api.qatouch.com/api/v1/getAllTestCases/3b9e/?mode=Automation" # 3b9e 1gEb
HEADERS = {
"domain": "symbyo",
"api-token": "476cf2ffc41704a3f222bb1092445d6cabe107d012e442c85c55e1b1424994bc",
}
print(get_qatouch_tcs_key(URL, HEADERS))
8 changes: 3 additions & 5 deletions src/pytest_qatouch/qatouch.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def push_testcase_to_results(self, testcase_id: int, testcase_status: str) -> No
f"Expected to have one of the following status ['passed','skipped','failed'] but we got [{testcase_status}]"
)

def push_results_to_qatouch(self) -> str:
def push_results_to_qatouch(self) -> None:
request_url = QATOUCH_API_END_POINT + "/testRunResults/status/multiple"
request_headers = {"domain": self.domain, "api-token": self.api_token}
request_payload = {
Expand All @@ -41,9 +41,7 @@ def push_results_to_qatouch(self) -> str:
"result": json.dumps(self.results),
}

response = requests.patch(
request_url, headers=request_headers, params=request_payload
)
response = requests.patch(request_url, headers=request_headers, params=request_payload)

if response.status_code == 200:
if response.json().get("success"):
Expand All @@ -52,7 +50,7 @@ def push_results_to_qatouch(self) -> str:
)
else:
raise QatouchRequestError(
f"The qatouch request failed becase {[response.json().get('error_msg')]}"
f"The qatouch request failed with {[response.json().get('error_msg')]}"
)

else:
Expand Down
Loading