class Transport: """ Задача: - Поддерживать принятый формат отправки сообщения. """ def __init__(self, config): self.request_factory = RequestFactory(config) def send(self, path, params): """ Отпрака сообщения :param path: принимаемый формат: 'server/controller/action' :type path: str :param params: аргументы передаваемые в экшен. :type params: dict """ server, controller, action = path.split('/') request = self.request_factory.get_request(server) controller_action_path = controller + '/' + action request.request(controller_action_path, **params)
from django.test import TestCase from django.http import Http404 from django_openid.consumer import Consumer from django_openid import signed from request_factory import RequestFactory from openid_mocks import * from openid.consumer import consumer as janrain_consumer rf = RequestFactory() class ConsumerTest(TestCase): def testBadMethod(self): "Non existent methods should result in a 404" openid_consumer = MyConsumer() get = rf.get('/openid/foo/') self.assertRaises(Http404, openid_consumer, get, 'foo/') def testLoginBegin(self): "Can log in with an OpenID" openid_consumer = MyConsumer() post = rf.post('/openid/', { 'openid_url': 'http://simonwillison.net/' }) post.session = MockSession() response = openid_consumer(post) self.assertEqual(response['Location'], 'http://url-of-openid-server/') oid_session = signed.loads(response.cookies['o_user_session'].value) self.assert_('openid_bits' in oid_session)
def __init__(self, config): self.request_factory = RequestFactory(config)