From 55d0e0dcb802be32604ed5f0db55bd6b7002999c Mon Sep 17 00:00:00 2001 From: Piotr Zalewa Date: Thu, 4 Feb 2010 18:18:57 +0000 Subject: [PATCH] amo and person added, amo with fake auth --- flightdeck/amo/__init__.py | 0 flightdeck/amo/authentication.py | 50 ++++++++++++++++++++++++++++++++ flightdeck/amo/models.py | 3 ++ flightdeck/amo/tests.py | 23 +++++++++++++++ flightdeck/amo/views.py | 1 + flightdeck/person/__init__.py | 0 flightdeck/person/models.py | 5 ++++ flightdeck/person/tests.py | 23 +++++++++++++++ flightdeck/person/views.py | 1 + scripts/django-admin.sh | 7 +++++ 10 files changed, 113 insertions(+) create mode 100644 flightdeck/amo/__init__.py create mode 100644 flightdeck/amo/authentication.py create mode 100644 flightdeck/amo/models.py create mode 100644 flightdeck/amo/tests.py create mode 100644 flightdeck/amo/views.py create mode 100644 flightdeck/person/__init__.py create mode 100644 flightdeck/person/models.py create mode 100644 flightdeck/person/tests.py create mode 100644 flightdeck/person/views.py create mode 100755 scripts/django-admin.sh diff --git a/flightdeck/amo/__init__.py b/flightdeck/amo/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/flightdeck/amo/authentication.py b/flightdeck/amo/authentication.py new file mode 100644 index 00000000..78636ad0 --- /dev/null +++ b/flightdeck/amo/authentication.py @@ -0,0 +1,50 @@ +from django.contrib.auth.models import User +from person.models import Profile + +class AMOAuthentication: + + def authenticate(self, username, password): + """ + Authenticate user by contacting with AMO + """ + + # Try to retrieve AMO session info from db + try: + user = User.objects.get(username=username) + except User.DoesNotExist: + user = None + amo_session = None + if user: + amo_session = user.get_profile().amo_session + + # TODO: here contact AMO and receive authentication status + authenticated = False + if username != 'fake': + authenticated = True + + # TODO: "steal" session cookie from AMO and save in profile + amo_session = "fake" + + if not authenticated: + return False + + # save user into the database + if not user: + user = User( + username=username, + password='saved in AMO', + # TODO: retrieve from AMO + first_name="John", + last_name="Doe", + email='fake@email.com' + ) + user.save() + try: + profile = user.get_profile() + except Profile.DoesNotExist: + profile = Profile() + + profile.amo_session = amo_session + profile.save() + + return user diff --git a/flightdeck/amo/models.py b/flightdeck/amo/models.py new file mode 100644 index 00000000..71a83623 --- /dev/null +++ b/flightdeck/amo/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/flightdeck/amo/tests.py b/flightdeck/amo/tests.py new file mode 100644 index 00000000..2247054b --- /dev/null +++ b/flightdeck/amo/tests.py @@ -0,0 +1,23 @@ +""" +This file demonstrates two different styles of tests (one doctest and one +unittest). These will both pass when you run "manage.py test". + +Replace these with more appropriate tests for your application. +""" + +from django.test import TestCase + +class SimpleTest(TestCase): + def test_basic_addition(self): + """ + Tests that 1 + 1 always equals 2. + """ + self.failUnlessEqual(1 + 1, 2) + +__test__ = {"doctest": """ +Another way to test that 1 + 1 is equal to 2. + +>>> 1 + 1 == 2 +True +"""} + diff --git a/flightdeck/amo/views.py b/flightdeck/amo/views.py new file mode 100644 index 00000000..60f00ef0 --- /dev/null +++ b/flightdeck/amo/views.py @@ -0,0 +1 @@ +# Create your views here. diff --git a/flightdeck/person/__init__.py b/flightdeck/person/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/flightdeck/person/models.py b/flightdeck/person/models.py new file mode 100644 index 00000000..50f5a624 --- /dev/null +++ b/flightdeck/person/models.py @@ -0,0 +1,5 @@ +from django.db import models +from django.contrib.auth.models import User + +class Profile(models.Model): + amo_session = models.CharField(max_length=255, blank=True, null=True) diff --git a/flightdeck/person/tests.py b/flightdeck/person/tests.py new file mode 100644 index 00000000..2247054b --- /dev/null +++ b/flightdeck/person/tests.py @@ -0,0 +1,23 @@ +""" +This file demonstrates two different styles of tests (one doctest and one +unittest). These will both pass when you run "manage.py test". + +Replace these with more appropriate tests for your application. +""" + +from django.test import TestCase + +class SimpleTest(TestCase): + def test_basic_addition(self): + """ + Tests that 1 + 1 always equals 2. + """ + self.failUnlessEqual(1 + 1, 2) + +__test__ = {"doctest": """ +Another way to test that 1 + 1 is equal to 2. + +>>> 1 + 1 == 2 +True +"""} + diff --git a/flightdeck/person/views.py b/flightdeck/person/views.py new file mode 100644 index 00000000..60f00ef0 --- /dev/null +++ b/flightdeck/person/views.py @@ -0,0 +1 @@ +# Create your views here. diff --git a/scripts/django-admin.sh b/scripts/django-admin.sh new file mode 100755 index 00000000..83eb900b --- /dev/null +++ b/scripts/django-admin.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +source scripts/environment.sh + +# run server +cd $PROJECT_DIR/$PROJECT_NAME/ +django-admin.py $@