This repository has been archived by the owner on Nov 14, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from the-scouts/testing
Testing
- Loading branch information
Showing
7 changed files
with
404 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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
name: testing | ||
|
||
on: | ||
pull_request: | ||
push: | ||
branches: [master] | ||
|
||
jobs: | ||
testing: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set up Python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: 3.9 | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install -r requirements.txt | ||
- name: Install pytest-cov, codecov | ||
run: | | ||
pip install pytest-cov codecov | ||
- name: Test with pytest | ||
run: | | ||
python -m pytest --cov=./ | ||
- name: Upload to CodeCov | ||
uses: codecov/codecov-action@v1 |
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
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 |
---|---|---|
|
@@ -7,6 +7,9 @@ pydantic | |
email-validator | ||
phonenumbers | ||
|
||
# testing | ||
pytest | ||
|
||
# dev | ||
ipython | ||
black | ||
|
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,83 @@ | ||
import pytest | ||
|
||
from compass.core import errors | ||
|
||
|
||
class TestErrors: | ||
def test_compass_error(self): | ||
# Given | ||
data = "message" | ||
|
||
# Then | ||
with pytest.raises(errors.CompassError, match=data): | ||
# When | ||
raise errors.CompassError(data) | ||
|
||
def test_compass_authentication_error(self): | ||
# Given | ||
data = "message" | ||
|
||
# Then | ||
with pytest.raises(errors.CompassAuthenticationError, match=data): | ||
# When | ||
raise errors.CompassAuthenticationError(data) | ||
|
||
def test_compass_report_error(self): | ||
# Given | ||
data = "message" | ||
|
||
# Then | ||
with pytest.raises(errors.CompassReportError, match=data): | ||
# When | ||
raise errors.CompassReportError(data) | ||
|
||
def test_compass_report_permission_error(self): | ||
# Given | ||
data = "message" | ||
|
||
# Then | ||
with pytest.raises(errors.CompassReportPermissionError, match=data): | ||
# When | ||
raise errors.CompassReportPermissionError(data) | ||
|
||
def test_compass_authentication_error_inheritance(self): | ||
# Given | ||
data = "message" | ||
|
||
# When | ||
try: | ||
raise errors.CompassAuthenticationError(data) | ||
# Then | ||
except errors.CompassError as err: | ||
assert str(err) == data | ||
|
||
def test_compass_report_error_inheritance(self): | ||
# Given | ||
data = "message" | ||
|
||
# When | ||
try: | ||
raise errors.CompassReportError(data) | ||
# Then | ||
except errors.CompassError as err: | ||
assert str(err) == data | ||
|
||
def test_compass_report_permission_error_inheritance(self): | ||
# Given | ||
data = "message" | ||
|
||
# Dual inheritance: | ||
|
||
# When | ||
try: | ||
raise errors.CompassReportPermissionError(data) | ||
# Then | ||
except PermissionError as err: | ||
assert str(err) == data | ||
|
||
# When | ||
try: | ||
raise errors.CompassReportPermissionError(data) | ||
# Then | ||
except errors.CompassError as err: | ||
assert str(err) == data |
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,62 @@ | ||
from pytest import MonkeyPatch | ||
import requests | ||
|
||
from compass.core.interface_base import InterfaceBase | ||
from compass.core.settings import Settings | ||
|
||
|
||
class TestInterfaceBase: | ||
def test_get(self, monkeypatch: MonkeyPatch): | ||
# Given | ||
data = "https://example.org" | ||
reqs = Settings.total_requests | ||
|
||
# When | ||
s = requests.Session() | ||
monkeypatch.setattr(s, "get", lambda *args, **kwargs: dict(args=args, kwargs=kwargs)) | ||
result = InterfaceBase(s)._get(data) # pylint: disable=protected-access | ||
|
||
# Then | ||
assert result["args"][0] == data | ||
assert reqs + 1 == Settings.total_requests | ||
|
||
def test_post(self, monkeypatch: MonkeyPatch): | ||
# Given | ||
data = "https://example.org" | ||
json = {"abc": 123, "xyz": 321} | ||
reqs = Settings.total_requests | ||
|
||
# When | ||
s = requests.Session() | ||
monkeypatch.setattr(s, "post", lambda *args, **kwargs: dict(args=args, kwargs=kwargs)) | ||
result = InterfaceBase(s)._post(data, json=json) # pylint: disable=protected-access | ||
|
||
# Then | ||
assert result["args"][0] == data | ||
assert result["kwargs"]["json"] == json | ||
assert reqs + 1 == Settings.total_requests | ||
|
||
def test_head(self, monkeypatch: MonkeyPatch): | ||
# Given | ||
data = "https://example.org" | ||
reqs = Settings.total_requests | ||
|
||
# When | ||
s = requests.Session() | ||
monkeypatch.setattr(s, "head", lambda *args, **kwargs: dict(args=args, kwargs=kwargs)) | ||
result = InterfaceBase(s)._head(data) # pylint: disable=protected-access | ||
|
||
# Then | ||
assert result["args"][0] == data | ||
assert reqs + 1 == Settings.total_requests | ||
|
||
def test_update_headers(self): | ||
# Given | ||
data = {"header_one": 123, "abc_xyz": 321} | ||
|
||
# When | ||
ib = InterfaceBase(requests.Session()) | ||
ib._update_headers(data) # pylint: disable=protected-access | ||
|
||
# Then | ||
assert data.items() <= ib.s.headers.items() |
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,56 @@ | ||
from urllib.parse import urlparse | ||
|
||
import _strptime | ||
|
||
from compass.core.settings import Settings | ||
|
||
|
||
class TestSettings: | ||
def test_base_url(self): | ||
# Given | ||
data = Settings.base_url | ||
|
||
# When | ||
result = urlparse(data) | ||
|
||
# Then | ||
assert isinstance(data, str) | ||
assert bool(result.scheme) and bool(result.hostname) | ||
|
||
def test_date_format(self): | ||
# Given | ||
data = Settings.date_format | ||
|
||
# When | ||
result = _strptime._TimeRE_cache.pattern(data) # pylint: disable=protected-access | ||
|
||
# Then | ||
assert isinstance(data, str) | ||
assert bool(result) | ||
|
||
def test_org_number(self): | ||
# Given When | ||
data = Settings.org_number | ||
|
||
# Then | ||
assert isinstance(data, int) | ||
assert 0 < data < 100_000_000 # IDs are between 1 and 99,999,999 | ||
|
||
def test_wcf_json_endpoint(self): | ||
# Given When | ||
data = Settings.wcf_json_endpoint | ||
|
||
assert isinstance(data, str) | ||
assert data[0] == "/" | ||
assert ".svc" in data | ||
|
||
def test_web_service_path(self): | ||
# Given | ||
data = Settings.web_service_path | ||
|
||
# When | ||
result = urlparse(data) | ||
|
||
# Then | ||
assert isinstance(data, str) | ||
assert bool(result.scheme) and bool(result.hostname) and bool(result.path) |
Oops, something went wrong.