-
Notifications
You must be signed in to change notification settings - Fork 96
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
13 changed files
with
217 additions
and
53 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 |
---|---|---|
|
@@ -6,6 +6,13 @@ jobs: | |
working_directory: ~/app | ||
docker: | ||
- image: circleci/python:3.7.3-node-browsers | ||
- image: circleci/redis:5.0.5-alpine | ||
- image: circleci/postgres:11.4-alpine | ||
environment: | ||
POSTGRES_USER: main | ||
POSTGRES_DB: main | ||
POSTGRES_PASSWORD: main | ||
|
||
steps: | ||
- checkout | ||
- restore_cache: | ||
|
@@ -22,9 +29,12 @@ jobs: | |
key: 'venv-{{ checksum "requirements/base.txt" }}-{{ checksum "requirements/testing.txt" }}-{{ checksum "requirements/development.txt" }}-{{ checksum "requirements/production.txt" }}' | ||
paths: | ||
- .venv | ||
- run: | | ||
source .venv/bin/activate | ||
tox | ||
- run: | ||
environment: | ||
POSTGRESQL_DSN: postgresql://main:[email protected]:5432/main | ||
command: | | ||
source .venv/bin/activate | ||
tox | ||
- save_cache: | ||
key: 'tox-{{ checksum "requirements/base.txt" }}-{{ checksum "requirements/testing.txt" }}-{{ checksum "requirements/development.txt" }}-{{ checksum "requirements/production.txt" }}' | ||
paths: | ||
|
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
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 |
---|---|---|
|
@@ -7,3 +7,4 @@ pytest-cov==2.7.1 | |
pytest-aiohttp==0.3.0 | ||
tox==3.13.2 | ||
mypy==0.720 | ||
asynctest==0.13.0 |
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,18 @@ | ||
import pytest | ||
|
||
import pyslackersweb | ||
import pyslackersweb.website.tasks | ||
|
||
pytest_plugins = ("slack.tests.plugin",) | ||
|
||
|
||
@pytest.fixture | ||
async def client(aiohttp_client, slack_client): | ||
|
||
application = await pyslackersweb.app_factory() | ||
|
||
app_client = await aiohttp_client(application) | ||
app_client.app["scheduler"].shutdown() | ||
app_client.app["website_app"]["slack_client"] = slack_client | ||
|
||
return app_client |
This file was deleted.
Oops, something went wrong.
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,111 @@ | ||
import logging | ||
|
||
from collections import namedtuple | ||
|
||
import pytest | ||
import aiohttp.web | ||
|
||
from pyslackersweb.website import tasks | ||
|
||
SlackInviteTestParam = namedtuple("Param", "response data expected") | ||
|
||
|
||
async def test_endpoint_index(client): | ||
r = await client.get("/") | ||
|
||
assert r.history[0].url.path == "/" | ||
assert r.history[0].status == 302 | ||
|
||
assert r.status == 200 | ||
assert r.url.path == "/web" | ||
|
||
|
||
async def test_endpoint_slack(client): | ||
r = await client.get("/web/slack") | ||
assert r.status == 200 | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"slack_client,data,expected", | ||
( | ||
SlackInviteTestParam( | ||
response={}, | ||
data={"email": "[email protected]", "agree_tos": True}, | ||
expected="successAlert", | ||
), | ||
SlackInviteTestParam( | ||
response={}, data={"agree_tos": True}, expected="Missing data for required field" | ||
), | ||
SlackInviteTestParam( | ||
response={}, | ||
data={"email": "[email protected]", "agree_tos": False}, | ||
expected="There was an error processing your invite", | ||
), | ||
SlackInviteTestParam( | ||
response={}, | ||
data={"email": "foobar", "agree_tos": True}, | ||
expected="Not a valid email address", | ||
), | ||
SlackInviteTestParam( | ||
response={"body": {"ok": False, "error": "already_in_team"}}, | ||
data={"email": "[email protected]", "agree_tos": True}, | ||
expected="Reason: already_in_team", | ||
), | ||
SlackInviteTestParam( | ||
response={"body": {"ok": False, "error": "not_authed"}}, | ||
data={"email": "[email protected]", "agree_tos": True}, | ||
expected="Reason: not_authed", | ||
), | ||
SlackInviteTestParam( | ||
response={"status": 500}, | ||
data={"email": "[email protected]", "agree_tos": True}, | ||
expected="Reason: Error contacting slack API", | ||
), | ||
), | ||
indirect=["slack_client"], | ||
) | ||
async def test_endpoint_slack_invite(client, data, expected): | ||
r = await client.post(path="/web/slack", data=data) | ||
html = await r.text() | ||
|
||
assert r.status == 200 | ||
assert expected in html | ||
|
||
|
||
async def test_task_sync_github_repositories(client, caplog): | ||
|
||
async with aiohttp.ClientSession() as session: | ||
result = await tasks.sync_github_repositories(session, client.app["redis"]) | ||
|
||
assert result | ||
|
||
for record in caplog.records: | ||
assert record.levelno <= logging.INFO | ||
|
||
|
||
@pytest.mark.parametrize("slack_client", ({"body": ["users_iter", "users"]},), indirect=True) | ||
async def test_task_sync_slack_users(client, caplog): | ||
|
||
result = await tasks.sync_slack_users( | ||
client.app["website_app"]["slack_client"], client.app["redis"] | ||
) | ||
|
||
assert result | ||
assert len(result) == 1 | ||
assert result["America/Los_Angeles"] == 2 | ||
|
||
for record in caplog.records: | ||
assert record.levelno <= logging.INFO | ||
|
||
|
||
@pytest.mark.parametrize("slack_client", ({"body": ["channels_iter", "channels"]},), indirect=True) | ||
async def test_task_sync_slack_channels(client, caplog): | ||
|
||
result = await tasks.sync_slack_channels( | ||
client.app["website_app"]["slack_client"], client.app["redis"] | ||
) | ||
|
||
assert result | ||
|
||
for record in caplog.records: | ||
assert record.levelno <= logging.INFO |
Oops, something went wrong.