Skip to content

Commit e0ef573

Browse files
authored
Merge pull request #9 from truehostcloud/dev
Fix/ Get AutoLogin Links
2 parents 91c9edb + aebecee commit e0ef573

8 files changed

Lines changed: 253 additions & 132 deletions

File tree

.github/workflows/coverage.yml

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ name: Test Coverage With Deepsource
55

66
on:
77
push:
8-
branches: [ master ]
8+
branches: [master]
99
pull_request:
10-
branches: [ master ]
10+
branches: [master]
1111

1212
jobs:
1313
build:
@@ -16,23 +16,24 @@ jobs:
1616
matrix:
1717
python-version: [3.8]
1818
steps:
19-
- uses: actions/checkout@v2
20-
- name: Set up Python ${{ matrix.python-version }}
21-
uses: actions/setup-python@v2
22-
with:
23-
python-version: ${{ matrix.python-version }}
24-
- name: Install dependencies
25-
run: |
26-
python -m pip install --upgrade pip
27-
pip install pytest pytest-cov requests responses
28-
- name: Generate coverage report
29-
run: |
30-
pytest --cov=./ --cov-report xml
31-
- name: Install deepsource CLI
32-
run: |
33-
curl https://deepsource.io/cli | sh
34-
- name: Run the report coverage
35-
run: |
36-
./bin/deepsource report --analyzer test-coverage --key python --value-file ./coverage.xml
19+
- uses: actions/checkout@v2
20+
- name: Set up Python ${{ matrix.python-version }}
21+
uses: actions/setup-python@v2
22+
with:
23+
python-version: ${{ matrix.python-version }}
24+
- name: Install dependencies
25+
run: |
26+
python -m pip install --upgrade pip
27+
pip install pytest pytest-cov requests responses
28+
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
29+
- name: Generate coverage report
30+
run: |
31+
DJANGO_SETTINGS_MODULE=olittwhmcs.settings pytest --cov=./ --cov-report xml
32+
- name: Install deepsource CLI
33+
run: |
34+
curl https://deepsource.io/cli | sh
35+
- name: Run the report coverage
36+
run: |
37+
./bin/deepsource report --analyzer test-coverage --key python --value-file ./coverage.xml
3738
env:
3839
DEEPSOURCE_DSN: ${{ secrets.DEEPSOURCE_DSN }}

.github/workflows/run_tests.yml

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,34 @@ name: Run Tests
55

66
on:
77
push:
8-
branches: [ master ]
8+
branches: [master]
99
pull_request:
10-
branches: [ master ]
10+
branches: [master]
1111

1212
jobs:
1313
build:
14-
1514
runs-on: ubuntu-latest
1615
strategy:
1716
matrix:
1817
python-version: [3.8]
1918

2019
steps:
21-
- uses: actions/checkout@v2
22-
- name: Set up Python ${{ matrix.python-version }}
23-
uses: actions/setup-python@v2
24-
with:
25-
python-version: ${{ matrix.python-version }}
26-
- name: Install dependencies
27-
run: |
28-
python -m pip install --upgrade pip
29-
pip install flake8 pytest requests responses
30-
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
31-
- name: Lint with flake8
32-
run: |
33-
# stop the build if there are Python syntax errors or undefined names
34-
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
35-
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
36-
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
37-
- name: Test with pytest
38-
run: |
39-
pytest
20+
- uses: actions/checkout@v2
21+
- name: Set up Python ${{ matrix.python-version }}
22+
uses: actions/setup-python@v2
23+
with:
24+
python-version: ${{ matrix.python-version }}
25+
- name: Install dependencies
26+
run: |
27+
python -m pip install --upgrade pip
28+
pip install flake8 pytest requests responses
29+
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
30+
- name: Lint with flake8
31+
run: |
32+
# stop the build if there are Python syntax errors or undefined names
33+
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
34+
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
35+
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
36+
- name: Test with pytest
37+
run: |
38+
DJANGO_SETTINGS_MODULE=olittwhmcs.settings pytest

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ venv
33
build
44
dist
55
.pytest_cache
6+
__pycache__
67
tests/__pycache__
78
olittwhmcs/__pycache__
8-
olittwhmcs.egg-info
9+
olittwhmcs.egg-info
10+
pyproject.toml

olittwhmcs/network.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""This module contains the functions that make networks requests to whmcs."""
22

33
import requests
4+
from django.conf import settings
45
from requests.exceptions import RequestException
56

67
from olittwhmcs.exceptions import WhmcsConnectionError
@@ -16,7 +17,7 @@ def get_whmcs_response(parameters):
1617
try:
1718
response = make_whmcs_network_request(parameters)
1819
response_data = get_response_data(response)
19-
result = response_data.get('result')
20+
result = response_data.get("result")
2021
if response.ok and result == "success":
2122
return True, response_data
2223
error = get_error_message(response_data)
@@ -33,8 +34,11 @@ def make_whmcs_network_request(parameters):
3334
:rtype: requests.Response
3435
:raises WhmcsConnectionError: If the network request fails.
3536
"""
36-
# ToDo: Read this url from consumers or settings.py (or from env variables if not possible)
37-
url = "https://www.olitt.com/billing/includes/api.php"
37+
url = (
38+
f"{settings.WHMCS_BASE_URL}/includes/api.php"
39+
if settings.WHMCS_BASE_URL
40+
else "https://www.olitt.com/billing/includes/api.php"
41+
)
3842
try:
3943
return requests.post(url=url, data=parameters)
4044
except RequestException:
@@ -57,13 +61,14 @@ def get_response_data(response):
5761
def get_error_message(response_data):
5862
"""
5963
Extract an error message from whmcs response data.
60-
:param response_data: Dictionary, data received from whmcs from which to extract the message.
64+
:param response_data: Dictionary, data received from
65+
whmcs from which to extract the message.
6166
:return: Error message in the whmcs response data.
6267
:rtype: String or None
6368
"""
6469
if type(response_data) is dict:
65-
result = response_data.get('result', None)
66-
error = response_data.get('message', None)
70+
result = response_data.get("result", None)
71+
error = response_data.get("message", None)
6772
if result == "error":
6873
return error
6974
return None

olittwhmcs/settings.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import os
2+
3+
WHMCS_BASE_URL = os.environ.get("WHMCS_BASE_URL", "https://www.olitt.com/billing")
4+
SECRET_KEY = "foobar"

0 commit comments

Comments
 (0)