Skip to content

Commit

Permalink
Merge pull request #16 from uva-cs3240-s22/develop
Browse files Browse the repository at this point in the history
Release 1.0.0
  • Loading branch information
Marcus Mann authored Mar 12, 2022
2 parents f31e267 + b4d5f7b commit f9d0f62
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 5 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/django.yml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/db.sqlite3
.env
4 changes: 2 additions & 2 deletions Procfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
release: python manage.py migrate
web: gunicorn A07WordOfMouth.wsgi
release: python manage.py migrate && python manage.py make_social_app
web: gunicorn word_of_mouth.wsgi
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
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)
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ gunicorn

django-bootstrap-v5

django-heroku
django-heroku

python-dotenv
31 changes: 31 additions & 0 deletions word_of_mouth/management/commands/make_social_app.py
Original file line number Diff line number Diff line change
@@ -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'))

11 changes: 10 additions & 1 deletion word_of_mouth/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "/"
Expand Down Expand Up @@ -48,6 +49,7 @@
"allauth.socialaccount", # <--
"allauth.socialaccount.providers.google",
"main",
"word_of_mouth",
]

SOCIALACCOUNT_PROVIDERS = {
Expand Down Expand Up @@ -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 = (
Expand Down
7 changes: 7 additions & 0 deletions word_of_mouth/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from django.test import TestCase


class DummyTestCase(TestCase):
def test_dummy(self):
x = 1
self.assertEqual(x, 1)

0 comments on commit f9d0f62

Please sign in to comment.