This repository has been archived by the owner on May 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: more cov chore: disable consider-using-with
- Loading branch information
Showing
6 changed files
with
212 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,133 @@ | ||
name: CICD | ||
|
||
on: | ||
push: | ||
branches: main | ||
pull_request: | ||
|
||
jobs: | ||
setup: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
python: [3.7, 3.8, 3.9] | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-python@v2 | ||
with: | ||
python-version: ${{ matrix.python }} | ||
- uses: abatilo/actions-poetry@v2.0.0 | ||
with: | ||
poetry-version: 1.1.7 | ||
- uses: actions/cache@v2 | ||
id: dep-cache | ||
with: | ||
key: ${{ runner.os }}-py${{ matrix.python }}-${{ hashFiles('poetry.lock') }} | ||
path: | | ||
/home/runner/.cache/pypoetry/virtualenvs | ||
- name: Setup dependencies | ||
if: steps.dep-cache.outputs.cache-hit != 'true' | ||
run: | | ||
poetry install | ||
test: | ||
runs-on: ubuntu-latest | ||
needs: setup | ||
strategy: | ||
matrix: | ||
python: [3.7, 3.8, 3.9] | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-python@v2 | ||
with: | ||
python-version: ${{ matrix.python }} | ||
- uses: abatilo/actions-poetry@v2.0.0 | ||
with: | ||
poetry-version: 1.1.7 | ||
- uses: actions/cache@v2 | ||
id: dep-cache | ||
with: | ||
key: ${{ runner.os }}-py${{matrix.python }}-${{ hashFiles('poetry.lock') }} | ||
path: | | ||
/home/runner/.cache/pypoetry/virtualenvs | ||
- name: Setup dependencies | ||
if: steps.dep-cache.outputs.cache-hit != 'true' | ||
run: | | ||
poetry install | ||
- name: Tests | ||
run: | | ||
poetry run pytest --cov | ||
- uses: actions/upload-artifact@v2 | ||
with: | ||
name: coverage-report | ||
path: ./coverage.xml | ||
|
||
coverage: | ||
runs-on: ubuntu-latest | ||
needs: test | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/download-artifact@v2 | ||
with: | ||
name: coverage-report | ||
path: ./ | ||
- name: Upload coverage | ||
uses: codecov/codecov-action@v2 | ||
with: | ||
token: ${{ secrets.CODECOV_TOKEN }} | ||
files: ./coverage.xml | ||
fail_ci_if_error: true | ||
verbose: true | ||
lint: | ||
runs-on: ubuntu-latest | ||
needs: setup | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-python@v2 | ||
with: | ||
python-version: 3.9 | ||
- uses: abatilo/actions-poetry@v2.0.0 | ||
with: | ||
poetry-version: 1.1.7 | ||
- uses: actions/cache@v2 | ||
id: dep-cache | ||
with: | ||
key: ${{ runner.os }}-py3.9-${{ hashFiles('poetry.lock') }} | ||
path: | | ||
/home/runner/.cache/pypoetry/virtualenvs | ||
- name: Setup dependencies | ||
if: steps.dep-cache.outputs.cache-hit != 'true' | ||
run: | | ||
poetry install | ||
- name: Lint and format | ||
run: | | ||
poetry run pylint **/*.py | ||
poetry run black . --check | ||
build: | ||
runs-on: ubuntu-latest | ||
needs: setup | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-python@v2 | ||
with: | ||
python-version: 3.9 | ||
- uses: abatilo/actions-poetry@v2.0.0 | ||
with: | ||
poetry-version: 1.1.7 | ||
- uses: actions/cache@v2 | ||
id: dep-cache | ||
with: | ||
key: ${{ runner.os }}-py3.9-${{ hashFiles('poetry.lock') }} | ||
path: | | ||
/home/runner/.cache/pypoetry/virtualenvs | ||
- name: Setup dependencies | ||
if: steps.dep-cache.outputs.cache-hit != 'true' | ||
run: | | ||
poetry install | ||
- name: Lint and format | ||
run: | | ||
poetry build | ||
- uses: actions/upload-artifact@v2 | ||
with: | ||
name: current-build | ||
path: 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,7 @@ | ||
[MESSAGES CONTROL] | ||
disable=consider-using-f-string, | ||
broad-except, | ||
invalid-name, | ||
missing-module-docstring, | ||
missing-function-docstring, | ||
consider-using-with |
Empty file.
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,7 @@ | ||
# name: test_sends_request_to_slack_api_on_success | ||
<class 'dict'> { | ||
'profile': <class 'list'> [ | ||
"{'status_text': 'test', 'status_emoji': '', 'status_expiration': 0}", | ||
], | ||
} | ||
--- |
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,6 @@ | ||
import pytest | ||
|
||
|
||
@pytest.fixture | ||
def slack_api_token(): | ||
return "mock-slack-token" |
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,59 @@ | ||
import unittest.mock | ||
import urllib.parse | ||
import os | ||
import sys | ||
import typing | ||
|
||
import slack_status_cli.main | ||
|
||
|
||
class MockResponse(typing.NamedTuple): | ||
""" | ||
Stand-in for http.client.HTTPResponse. | ||
""" | ||
|
||
status: int | ||
response_text: str | ||
|
||
def read(self): | ||
return self.response_text | ||
|
||
|
||
def test_errors_if_no_slack_token_provided(monkeypatch): | ||
monkeypatch.setattr(sys, "argv", ["slack-status-cli", "set", "--text", "test"]) | ||
|
||
with unittest.mock.patch("sys.exit", autospec=True) as mock_exit: | ||
slack_status_cli.main.run() | ||
|
||
mock_exit.assert_called_with(1) | ||
|
||
|
||
def test_sends_request_to_slack_api_on_success( | ||
slack_api_token, monkeypatch, snapshot, tmp_path | ||
): | ||
env = os.environ.copy() | ||
env["SLACK_TOKEN"] = slack_api_token | ||
|
||
mock_response = MockResponse(status=200, response_text='{ "ok": true }') | ||
|
||
monkeypatch.setenv("SLACK_TOKEN", slack_api_token) | ||
monkeypatch.setattr(sys, "argv", ["slack-status-cli", "set", "--text", "test"]) | ||
|
||
with unittest.mock.patch( | ||
"urllib.request.urlopen", | ||
autospec=True, | ||
return_value=mock_response, | ||
) as mock_request, unittest.mock.patch( | ||
"pathlib.Path.home", autospec=True, return_value=tmp_path | ||
): | ||
slack_status_cli.main.run() | ||
|
||
request = mock_request.call_args_list[0][0][0] | ||
|
||
assert request.get_full_url() == "https://slack.com/api/users.profile.set" | ||
assert request.get_method() == "POST" | ||
assert request.get_header("Authorization") == "Bearer %s" % slack_api_token | ||
|
||
request_body = urllib.parse.parse_qs(request.data.decode()) | ||
|
||
assert request_body == snapshot |