diff --git a/.github/workflows/pythonapp.yml b/.github/workflows/pythonapp.yml new file mode 100644 index 0000000..98f7f84 --- /dev/null +++ b/.github/workflows/pythonapp.yml @@ -0,0 +1,27 @@ +name: DRF Social Oauth2 + +on: + pull_request: + types: [opened, edited] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: Set up Python 3.9 + uses: actions/setup-python@v1 + with: + python-version: 3.9 + + - name: Build docker image for tests + run: | + docker-compose -f docker-compose.tests.yml build --no-cache + + - name: Run dockerised tests + run: | + docker-compose -f docker-compose.tests.yml up --exit-code-from app + + - name: Take down containers + run: | + docker-compose -f docker-compose.tests.yml down diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..19624a8 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,9 @@ +FROM python:3.9.4-slim-buster +ENV PYTHONUNBUFFERED 1 + +RUN mkdir /code +WORKDIR /code + +ADD . /code/ + +RUN apt-get update && apt-get install -y --no-install-recommends wget && rm -rf /var/lib/apt/lists/* && pip install --no-cache-dir -r requirements.test.txt diff --git a/components.sh b/components.sh new file mode 100644 index 0000000..38242f0 --- /dev/null +++ b/components.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash +DOCKERIZE_VERSION="v0.6.1" +wget https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-alpine-linux-amd64-$DOCKERIZE_VERSION.tar.gz \ + && tar -C /usr/local/bin -xzvf dockerize-alpine-linux-amd64-$DOCKERIZE_VERSION.tar.gz \ + && rm dockerize-alpine-linux-amd64-$DOCKERIZE_VERSION.tar.gz +dockerize -wait tcp://db:5432 -timeout 60s diff --git a/docker-compose.tests.yml b/docker-compose.tests.yml new file mode 100644 index 0000000..2b48123 --- /dev/null +++ b/docker-compose.tests.yml @@ -0,0 +1,16 @@ +version: "3.7" + +services: + app: + build: . + command: > + bash -c "sh components.sh && pytest" + depends_on: + - db + db: + image: postgres:13.2 + restart: always + environment: + - POSTGRES_PASSWORD=password + - POSTGRES_USER=user + - POSTGRES_DB=database diff --git a/requirements.test.txt b/requirements.test.txt index a1d8d31..8fbecf8 100644 --- a/requirements.test.txt +++ b/requirements.test.txt @@ -1,4 +1,7 @@ +requests==2.26.0 pytest==6.2.5 -djangorestframework==3.13.1 +djangorestframework>=3.10.3 +django-oauth-toolkit==1.6.1 +social-auth-app-django>=3.1.0 pytest-mock==3.6.1 coverage==6.2 diff --git a/tests/drf_social_oauth2/test_authentication.py b/tests/drf_social_oauth2/test_authentication.py index d1a6a09..58f12b3 100644 --- a/tests/drf_social_oauth2/test_authentication.py +++ b/tests/drf_social_oauth2/test_authentication.py @@ -1,7 +1,5 @@ import os -from requests.exceptions import HTTPError -from requests.models import Response from rest_framework.exceptions import AuthenticationFailed from pytest import raises