diff --git a/.github/workflows/django.yml b/.github/workflows/django.yml new file mode 100644 index 0000000..2150c6a --- /dev/null +++ b/.github/workflows/django.yml @@ -0,0 +1,31 @@ +name: Django CI + +on: + push: + branches: [ main, develop, specify-site-id, github-actions-test ] + pull_request: + branches: [ main, develop, specify-site-id, github-actions-test ] + +jobs: + build: + + runs-on: ubuntu-latest + strategy: + max-parallel: 4 + matrix: + python-version: ['3.10'] + + steps: + - uses: actions/checkout@v2 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + - name: Install Dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + - name: Run Tests + run: | + python manage.py migrate + python manage.py test diff --git a/.gitignore b/.gitignore index 3eae80e..150baf8 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /db.sqlite3 +.env diff --git a/Procfile b/Procfile index a48e183..4abcd6c 100644 --- a/Procfile +++ b/Procfile @@ -1,2 +1,2 @@ -release: python manage.py migrate -web: gunicorn A07WordOfMouth.wsgi \ No newline at end of file +release: python manage.py migrate && python manage.py make_social_app +web: gunicorn word_of_mouth.wsgi \ No newline at end of file diff --git a/README.md b/README.md index 11752ed..bff8cf9 100644 --- a/README.md +++ b/README.md @@ -11,4 +11,5 @@ 3. (side note: if you are running into errors, keep in mind that `localhost` and `127.0.0.1` are two different domain names, even though they resolve to the same place) 5. Run migrations: `python manage.py migrate` 6. Create superuser: `python manage.py createsuperuser` -7. Go to `localhost:8000/admin`, go to "Social Applications", and add the application with the "Client ID" and "Secret Key" that we got from our GCP console. \ No newline at end of file +7. Go to `localhost:8000/admin`, go to "Social Applications", and add the application with the "Client ID" and "Secret Key" that we got from our GCP console. +8. In Django Admin, edit `example.com` to be `localhost` (as opposed to editing SITE_ID in settings.py) \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index a7aebd3..2f423fb 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,4 +7,6 @@ gunicorn django-bootstrap-v5 -django-heroku \ No newline at end of file +django-heroku + +python-dotenv \ No newline at end of file diff --git a/word_of_mouth/management/commands/make_social_app.py b/word_of_mouth/management/commands/make_social_app.py new file mode 100644 index 0000000..ed271e3 --- /dev/null +++ b/word_of_mouth/management/commands/make_social_app.py @@ -0,0 +1,31 @@ +from django.core.management.base import BaseCommand, CommandError +from allauth.socialaccount.models import SocialApp +from django.contrib.sites.models import Site +from dotenv import load_dotenv + +import os +load_dotenv() +class Command(BaseCommand): + help = 'Makes a new social app using environment variables.' + + def handle(self, *args, **options): + try: + + our_client_id = os.getenv('CLIENT_ID') + secret_key = os.getenv('SECRET_KEY') + + SocialApp.objects.get(secret=secret_key, client_id=our_client_id) + print('Social App already exists') + except SocialApp.DoesNotExist: + sapp = SocialApp(provider='google', name='any', + client_id=our_client_id, + secret=secret_key) + + sapp.save() + s = Site.objects.get(id=1) + s.domain = 'localhost' + s.save() + sapp.sites.add(1) + sapp.save() + self.stdout.write(self.style.SUCCESS('Successfully made new Social App')) + diff --git a/word_of_mouth/settings.py b/word_of_mouth/settings.py index 235fc73..0b146e1 100644 --- a/word_of_mouth/settings.py +++ b/word_of_mouth/settings.py @@ -9,6 +9,7 @@ For the full list of settings and their values, see https://docs.djangoproject.com/en/4.0/ref/settings/ """ +import os SITE_ID = 1 LOGIN_REDIRECT_URL = "/" @@ -48,6 +49,7 @@ "allauth.socialaccount", # <-- "allauth.socialaccount.providers.google", "main", + "word_of_mouth", ] SOCIALACCOUNT_PROVIDERS = { @@ -141,7 +143,14 @@ DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' -django_heroku.settings(locals()) +# django heroku will assume that we're running tests on Heroku CI if the 'CI' variable +# is set... so check to see if we are running in Github Actions vs Heroku +if 'GITHUB_ACTIONS' not in os.environ and 'DEV' not in os.environ: + DATABASES['default'] = { + 'ENGINE': 'django.db.backends.postgresql_psycopg2', + 'NAME': 'word_of_mouth', + } + django_heroku.settings(locals()) #add this in the end of file AUTHENTICATION_BACKENDS = ( diff --git a/word_of_mouth/test.py b/word_of_mouth/test.py new file mode 100644 index 0000000..fd168b2 --- /dev/null +++ b/word_of_mouth/test.py @@ -0,0 +1,7 @@ +from django.test import TestCase + + +class DummyTestCase(TestCase): + def test_dummy(self): + x = 1 + self.assertEqual(x, 1)