Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

{
"name": "3sc API",
"repository": "https://github.com/3-strand-code/3sc-api",
"env": {
"DJANGO_SETTINGS_MODULE": "threestrandcode.settings.production"
},
"addons": [
"heroku-postgresql:hobby-dev"
]
}
3 changes: 2 additions & 1 deletion threestrandcode/apps/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ class Meta:
'first_name',
'last_name',
'email',
'essay'
'essay',
'github_name',
)


Expand Down
19 changes: 11 additions & 8 deletions threestrandcode/apps/api/tests/assignments.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import random

from django.conf import settings
from django.contrib.auth.models import User
from django.contrib.auth import get_user_model
from django.core.urlresolvers import reverse
from django.test import TestCase
from faker import Factory
Expand All @@ -13,6 +13,9 @@
from homework.recipes import MakeGHPage


User = get_user_model()


class TestAssignments(TestCase):

def setUp(self):
Expand All @@ -27,10 +30,10 @@ def setUp(self):
course=self.course,
)

def test_create_assignment_hooks_github_repo(self):
# create user and all that shit
# post to assignment endpoint
# it should call "create_hook" on that repo
self.client.login(username="test", password="test")
self.client.post()
pass
# def test_create_assignment_hooks_github_repo(self):
# # create user and all that shit
# # post to assignment endpoint
# # it should call "create_hook" on that repo
# self.client.login(username="test", password="test")
# self.client.post()
# pass
5 changes: 4 additions & 1 deletion threestrandcode/apps/api/tests/login.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import json

from django.contrib.auth.models import User
from django.contrib.auth import get_user_model
from django.core.urlresolvers import reverse
from django.test import TestCase


User = get_user_model()


class TestLogin(TestCase):

def setUp(self):
Expand Down
5 changes: 4 additions & 1 deletion threestrandcode/apps/api/tests/permissions.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import random

from django.conf import settings
from django.contrib.auth.models import User
from django.contrib.auth import get_user_model
from django.core.urlresolvers import reverse
from django.test import TestCase
from faker import Factory
from loremipsum import generate_paragraph


User = get_user_model()


class TestPermissions(TestCase):

def test_check_admin_priviledges_are_required_for_applicants_list(self):
Expand Down
23 changes: 19 additions & 4 deletions threestrandcode/apps/applicants/models.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
from django.conf import settings
from django.contrib.auth.models import User
from django.db import models
from django.contrib.auth import get_user_model
from django.db import models, IntegrityError
from django.db.models.signals import post_save


class Applicant(models.Model):
user = models.OneToOneField(
to=settings.AUTH_USER_MODEL,
null=True,
blank=True,
on_delete=models.CASCADE,
help_text="When an Applicant is given a user account, that basically means they've been accepted into 3SC"
)
first_name = models.CharField(max_length=64)
Expand All @@ -23,9 +25,22 @@ def save(self, *args, **kwargs):
super().save(*args, **kwargs)
if created:
# creating new Applicant so also make user and shoot out activation/registration
User = get_user_model()
self.user, _ = User.objects.get_or_create(email=self.email)
self.save()


# Add some helpers to User class so we can get applicant info easily
User.application = property(lambda u: Applicant.objects.get_or_create(user=u)[0])
# Connect to User model just in case for some reason we make a User without
# first submitting an application
def create_profile(sender, **kwargs):
user = kwargs["instance"]
if kwargs["created"]:
try:
Applicant.objects.get_or_create(user=user, email=user.email)
except IntegrityError:
# Sometimes email may already exist and although get_or_create should succeed, it
# fails here?
pass


post_save.connect(create_profile, sender=settings.AUTH_USER_MODEL)
8 changes: 8 additions & 0 deletions threestrandcode/apps/applicants/tests/applicant_models.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
from django.contrib.auth import get_user_model
from django.test import TestCase
from model_mommy import mommy

from ..models import Applicant


User = get_user_model()


class ApplicantModelTests(TestCase):
def test_saving_applicant_creates_user(self):
applicant = mommy.make(Applicant)
assert applicant.user
assert applicant.user.email == applicant.email

def creating_user_creates_applicant(self):
user = mommy.make(User)
assert user.applicant
2 changes: 1 addition & 1 deletion threestrandcode/apps/homework/recipes/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class SignUp(BaseRecipe):

@classmethod
def do_completed_check(cls, user):
return user.application.github_name is not None
return user.applicant.github_name is not None


class MakeRepository(BaseRecipe):
Expand Down
5 changes: 4 additions & 1 deletion threestrandcode/apps/homework/tests/github.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.contrib.auth.models import User
from django.contrib.auth import get_user_model
from django.test import TestCase

from model_mommy import mommy
Expand All @@ -8,6 +8,9 @@
from applicants.models import Applicant


User = get_user_model()


class GithubAssignmentTests(TestCase):

def setUp(self):
Expand Down
5 changes: 4 additions & 1 deletion threestrandcode/apps/homework/tests/model_tests.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.contrib.auth.models import User
from django.contrib.auth import get_user_model
from django.test import TestCase

from model_mommy import mommy
Expand All @@ -8,6 +8,9 @@
from ..recipes.github import SignUp, MakeRepository, MakeGHPage


User = get_user_model()


class PreReqCheckTests(TestCase):

def setUp(self):
Expand Down
1 change: 1 addition & 0 deletions threestrandcode/settings/production.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

# Rest auth stuff
CORS_ORIGIN_WHITELIST = (
# "localhost:8080",
'3strandcode.com',
'threesc-api.herokuapp.com',
)