-
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.
- Loading branch information
Showing
6 changed files
with
123 additions
and
13 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,11 @@ | ||
# Run flake8 (pycodestyle + pyflakes) check. | ||
# https://pycodestyle.readthedocs.io/en/latest/intro.html#error-codes | ||
# Ignored errors: | ||
# - E501: line too long | ||
# - E265: block comment should start with '# ' (makes it easier to enable/disable code) | ||
# - W503: line break before binary operator (deprecated rule) | ||
# - W505: doc line too long | ||
|
||
[flake8] | ||
ignore = E501,E265,W503,W505 | ||
exclude = .git/,.virtualenv/,__pycache__/,build/,dist/ |
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,38 @@ | ||
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions | ||
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions | ||
|
||
name: Python CI | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
pull_request: | ||
branches: [ main ] | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
python-version: [3.7, 3.9] | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
- name: Install dependencies | ||
run: | | ||
python3 -m pip install --upgrade pip | ||
python3 -m pip install flake8 | ||
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi | ||
python3 setup.py install | ||
- name: Lint code with Python ${{ matrix.python-version }} | ||
run: | | ||
make lint | ||
- name: Test code with Python ${{ matrix.python-version }} | ||
run: | | ||
make test |
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
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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
''' | ||
Miris Manager client test file. | ||
''' | ||
from unittest.mock import patch | ||
import json | ||
import logging | ||
import os | ||
import sys | ||
import unittest | ||
import urllib3 | ||
|
||
CONFIG = { | ||
'SERVER_URL': 'https://mmctest' | ||
} | ||
|
||
|
||
def mocked_requests_get(*args, **kwargs): | ||
class MockResponse: | ||
def __init__(self, json_data, status_code): | ||
self.text = json.dumps(json_data) | ||
self.json_data = json_data | ||
self.status_code = status_code | ||
|
||
def json(self): | ||
return self.json_data | ||
|
||
if kwargs['url'] == CONFIG['SERVER_URL'] + '/api/': | ||
return MockResponse({'version': '8.0.0'}, 200) | ||
|
||
return MockResponse(None, 404) | ||
|
||
|
||
class MMClientTest(unittest.TestCase): | ||
maxDiff = None | ||
|
||
def setUp(self): | ||
print('\n\033[96m----- %s.%s -----\033[0m' % (self.__class__.__name__, self._testMethodName)) | ||
# Setup logging | ||
logging.basicConfig( | ||
level=logging.DEBUG, | ||
format='%(asctime)s %(name)s %(levelname)s %(message)s', | ||
stream=sys.stdout | ||
) | ||
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) | ||
# Setup sys path | ||
sys.path.pop(0) # Remove current dir | ||
src_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) | ||
sys.path.insert(0, src_dir) | ||
|
||
@patch('requests.get', side_effect=mocked_requests_get) | ||
def test_client(self, mock_get): | ||
from mm_client.client import MirisManagerClient | ||
mmc = MirisManagerClient(local_conf=CONFIG) | ||
response = mmc.api_request('PING') | ||
self.assertTrue(isinstance(response, dict)) | ||
self.assertEqual(response['version'], '8.0.0') | ||
|
||
self.assertEqual(len(mock_get.call_args_list), 1) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |