-
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
14 changed files
with
461 additions
and
40 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
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,15 @@ | ||
version: "3.4" | ||
|
||
services: | ||
redis: | ||
image: redis:5-alpine | ||
ports: | ||
- "6379:6379" | ||
|
||
postgresql: | ||
image: postgres:11 | ||
environment: | ||
POSTGRES_PASSWORD: main | ||
POSTGRES_USER: main | ||
ports: | ||
- "5432:5432" |
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 |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
|
||
REDIS_URL = os.getenv("REDIS_URL", "redis://127.0.0.1:6379/0") | ||
|
||
POSTGRESQL_DSN = os.getenv("POSTGRESQL_DSN") | ||
POSTGRESQL_DSN = os.getenv("POSTGRESQL_DSN", "postgresql://main:[email protected]:5432/main") | ||
|
||
SENTRY_DSN = os.getenv("SENTRY_DSN") | ||
|
||
|
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 |
---|---|---|
@@ -1,6 +1,10 @@ | ||
from marshmallow import Schema, fields | ||
|
||
|
||
def validate_true(field): | ||
return bool(field) | ||
|
||
|
||
class InviteSchema(Schema): | ||
email = fields.Email(required=True) | ||
agree_tos = fields.Boolean(required=True) | ||
agree_tos = fields.Boolean(required=True, validate=validate_true) |
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,76 @@ | ||
import json | ||
import pytest | ||
import aioredis | ||
import asynctest | ||
|
||
import pyslackersweb | ||
import pyslackersweb.website.tasks | ||
|
||
pytest_plugins = ("slack.tests.plugin",) | ||
|
||
|
||
def pytest_addoption(parser): | ||
parser.addoption("--redis", action="store_true", default=False) | ||
parser.addoption("--postgresql", action="store_true", default=False) | ||
|
||
|
||
@pytest.fixture | ||
async def app(pytestconfig): | ||
application = await pyslackersweb.app_factory() | ||
|
||
if not pytestconfig.getoption("postgresql"): | ||
application.cleanup_ctx.remove(pyslackersweb.contexts.postgresql_pool) | ||
|
||
if not pytestconfig.getoption("redis"): | ||
application.cleanup_ctx.remove(pyslackersweb.contexts.redis_pool) | ||
|
||
return application | ||
|
||
|
||
@pytest.fixture | ||
async def redis(loop, pytestconfig): | ||
|
||
if pytestconfig.getoption("redis"): | ||
redis = await aioredis.create_redis_pool(pyslackersweb.settings.REDIS_URL) | ||
else: | ||
redis = FakeRedis() | ||
|
||
yield redis | ||
|
||
if pytestconfig.getoption("redis"): | ||
redis.close() | ||
await redis.wait_closed() | ||
|
||
|
||
class FakeRedis: | ||
async def get(self, key, *args, **kwargs): | ||
if key == pyslackersweb.website.tasks.GITHUB_REPO_CACHE_KEY: | ||
return json.dumps( | ||
{ | ||
"name": "foo", | ||
"descriptions": "bar", | ||
"href": "https://github.com/pyslackers/website", | ||
"stars": 20, | ||
"topics": ["foo", "bar", "baz"], | ||
} | ||
) | ||
elif key == pyslackersweb.website.tasks.SLACK_COUNT_CACHE_KEY: | ||
return 10 | ||
elif key == pyslackersweb.website.tasks.SLACK_TZ_CACHE_KEY: | ||
return {"foo": 10, "bar": 20} | ||
else: | ||
raise RuntimeError(f"Mock redis key not found: {key}") | ||
|
||
async def hgetall(self, key, *args, **kwargs): | ||
if key == pyslackersweb.website.tasks.SLACK_TZ_CACHE_KEY: | ||
return {"foo": 10, "bar": 20} | ||
else: | ||
raise RuntimeError(f"Mock redis key not found: {key}") | ||
|
||
async def set(self, key, *args, **kwargs): | ||
pass | ||
|
||
def multi_exec(self): | ||
tx = asynctest.Mock() | ||
tx.execute = asynctest.CoroutineMock() | ||
return tx |
Oops, something went wrong.