Skip to content

Commit

Permalink
feat: Add e2e flask test with nest-asyncio for circleci
Browse files Browse the repository at this point in the history
  • Loading branch information
KShivendu committed Sep 21, 2023
1 parent b9a0b44 commit 92329b9
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 8 deletions.
16 changes: 16 additions & 0 deletions .circleci/config_continue.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,22 @@ jobs:
- run: make with-django2x
- run: (cd .circleci/ && ./websiteDjango2x.sh)
- slack/status
test-website-flask-nest-asyncio:
docker:
- image: rishabhpoddar/supertokens_python_driver_testing
resource_class: large
environment:
SUPERTOKENS_NEST_ASYNCIO: "1"
steps:
- checkout
- run: update-alternatives --install "/usr/bin/java" "java" "/usr/java/jdk-15.0.1/bin/java" 2
- run: update-alternatives --install "/usr/bin/javac" "javac" "/usr/java/jdk-15.0.1/bin/javac" 2
- run: git config --global url."https://github.com/".insteadOf ssh://[email protected]/
- run: echo "127.0.0.1 localhost.org" >> /etc/hosts
- run: make with-flask
- run: python -m pip install nest-asyncio
- run: (cd .circleci/ && ./websiteFlask.sh)
- slack/status
test-authreact-fastapi:
docker:
- image: rishabhpoddar/supertokens_python_driver_testing
Expand Down
11 changes: 3 additions & 8 deletions supertokens_python/async_to_sync_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,8 @@
_T = TypeVar("_T")


def is_nest_asyncio_enabled():
try:
import nest_asyncio as _ # type: ignore

return getenv("SUPERTOKENS_NEST_ASYNCIO", "") == "1"
except Exception:
return False
def nest_asyncio_enabled():
return getenv("SUPERTOKENS_NEST_ASYNCIO", "") == "1"


def create_or_get_event_loop() -> asyncio.AbstractEventLoop:
Expand All @@ -35,7 +30,7 @@ def create_or_get_event_loop() -> asyncio.AbstractEventLoop:
if "There is no current event loop in thread" in str(ex):
loop = asyncio.new_event_loop()

if is_nest_asyncio_enabled():
if nest_asyncio_enabled():
import nest_asyncio # type: ignore

nest_asyncio.apply(loop) # type: ignore
Expand Down
25 changes: 25 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import asyncio

from pytest import mark
from unittest.mock import MagicMock
from supertokens_python import InputAppInfo, SupertokensConfig, init
Expand Down Expand Up @@ -800,3 +802,26 @@ async def test_cookie_samesite_with_ec2_public_url():
assert SessionRecipe.get_instance().config.cookie_domain is None
assert SessionRecipe.get_instance().config.cookie_same_site == "lax"
assert SessionRecipe.get_instance().config.cookie_secure is False


def test_nest_asyncio_import():
from supertokens_python.async_to_sync_wrapper import nest_asyncio_enabled, sync
from os import getenv

circleci = getenv("CIRCLECI", "false") == "true"

if not circleci:
return

# Has to be circleci
if nest_asyncio_enabled():
# nest-asyncio should be installed
sync(asyncio.sleep(0.1))
else:
# nest-asyncio shouldn't be installed and sync() should throw error
try:
sync(asyncio.sleep(0.1))
assert False, "Shouldn't come here"
except ModuleNotFoundError:
# should be missing
assert True

0 comments on commit 92329b9

Please sign in to comment.