зеркало из https://github.com/mozilla/FlightDeck.git
Merge pull request #135 from zalun/bug-724648-amo_user_api
* Add AMOOAuth.get_user_by_email which uses new API
This commit is contained in:
Коммит
20ed5ca1ae
|
@ -7,6 +7,7 @@ from django.conf import settings
|
|||
|
||||
from amo.helpers import get_amo_cursor
|
||||
from person.models import Profile
|
||||
from utils.amo import AMOOAuth
|
||||
|
||||
DEFAULT_AMO_PASSWORD = 'saved in AMO'
|
||||
|
||||
|
@ -104,7 +105,7 @@ class AMOAuthentication:
|
|||
username = user_data['id']
|
||||
self.user_data = user_data
|
||||
return username
|
||||
|
||||
|
||||
@staticmethod
|
||||
def auth_browserid_authenticate(email):
|
||||
"""
|
||||
|
@ -112,25 +113,11 @@ class AMOAuthentication:
|
|||
browserid
|
||||
"""
|
||||
return AMOAuthentication.fetch_amo_user(email)
|
||||
|
||||
|
||||
@staticmethod
|
||||
def fetch_amo_user(email):
|
||||
columns = ('id', 'email', 'username', 'password',
|
||||
'display_name', 'homepage')
|
||||
auth_cursor = get_amo_cursor()
|
||||
|
||||
SQL = ('SELECT %s FROM %s WHERE email=%%s') % (
|
||||
','.join(columns), settings.AUTH_DATABASE['TABLE'])
|
||||
auth_cursor.execute(SQL, email)
|
||||
data = auth_cursor.fetchone()
|
||||
if data == None:
|
||||
return None
|
||||
|
||||
user_data = {}
|
||||
for i in range(len(data)):
|
||||
user_data[columns[i]] = data[i]
|
||||
|
||||
return user_data
|
||||
amo = AMOOAuth()
|
||||
return amo.get_user_by_email(email) or None
|
||||
|
||||
|
||||
def get_hexdigest(algorithm, salt, raw_password):
|
||||
|
|
|
@ -2,10 +2,21 @@ from django.conf import settings
|
|||
from django.test import TestCase
|
||||
from django.contrib.auth import authenticate
|
||||
|
||||
from mock import Mock
|
||||
from nose import SkipTest
|
||||
from nose.tools import eq_
|
||||
|
||||
from amo.authentication import AMOAuthentication
|
||||
from utils.amo import AMOOAuth
|
||||
|
||||
|
||||
OLD_AMOOAUTH_SEND = AMOOAuth._send
|
||||
|
||||
class AuthTest(TestCase):
|
||||
|
||||
def tearDown(self):
|
||||
AMOOAuth._send = OLD_AMOOAUTH_SEND
|
||||
|
||||
def test_failing_login(self):
|
||||
# testing failed authentication on AMO
|
||||
# this test assumes FlightDeck has access to AMO database
|
||||
|
@ -16,7 +27,8 @@ class AuthTest(TestCase):
|
|||
password='user')
|
||||
)
|
||||
|
||||
def test_successful_login(self):
|
||||
@staticmethod
|
||||
def test_successful_login():
|
||||
# if settings_local contains AMO user data check if login is
|
||||
# successful
|
||||
# assumes that FlightDeck has access to AMO database
|
||||
|
@ -25,3 +37,20 @@ class AuthTest(TestCase):
|
|||
assert authenticate(
|
||||
username=settings.TEST_AMO_USERNAME,
|
||||
password=settings.TEST_AMO_PASSWORD)
|
||||
|
||||
@staticmethod
|
||||
def test_get_user():
|
||||
|
||||
AMOOAuth._send = Mock(return_value={
|
||||
"username": "some",
|
||||
"display_name": "Some User",
|
||||
"created": "2007-03-05 13:09:38",
|
||||
"modified": "2012-01-31 12:38:50",
|
||||
"id": 12345,
|
||||
"location": "Portland, OR",
|
||||
"homepage": "http://example.com",
|
||||
"email": "some@example.com",
|
||||
"occupation": "addon developer"
|
||||
})
|
||||
eq_(AMOAuthentication.fetch_amo_user('some@example.com')['username'],
|
||||
'some')
|
||||
|
|
|
@ -20,6 +20,8 @@ from utils.amo import AMOOAuth
|
|||
log = commonware.log.getLogger('f.test')
|
||||
|
||||
|
||||
OLD_AMOOAUTH_SEND = AMOOAuth._send
|
||||
|
||||
class UploadTest(TestCase):
|
||||
fixtures = ['mozilla_user', 'users', 'core_sdk', 'packages']
|
||||
ADDON_AMO_ID = 1
|
||||
|
@ -35,6 +37,8 @@ class UploadTest(TestCase):
|
|||
protocol=settings.AMOOAUTH_PROTOCOL,
|
||||
prefix=settings.AMOOAUTH_PREFIX)
|
||||
|
||||
def tearDown(self):
|
||||
AMOOAuth._send = OLD_AMOOAUTH_SEND
|
||||
|
||||
def test_create_new_amo_addon(self):
|
||||
AMOOAuth._send = Mock(return_value={
|
||||
|
|
|
@ -214,6 +214,9 @@ class AMOOAuth:
|
|||
def get_user(self):
|
||||
return self._send(self.url('user'), 'GET', {})
|
||||
|
||||
def get_user_by_email(self, email):
|
||||
return self._send(self.url('user'), 'GET', {'email': email})
|
||||
|
||||
def create_addon(self, data):
|
||||
return self._send(self.url('addon'), 'POST', data)
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче