This repository has been archived by the owner on Jul 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
65 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
"""Test the consumer.""" | ||
from __future__ import unicode_literals | ||
|
||
import django | ||
from django.test import TestCase | ||
from openid.fetchers import setDefaultFetcher, HTTPResponse | ||
from openid.yadis.constants import YADIS_CONTENT_TYPE | ||
|
||
# Allow django tests to run through discover | ||
django.setup() | ||
|
||
|
||
EXAMPLE_XRDS = b'''<?xml version="1.0" encoding="UTF-8"?> | ||
<xrds:XRDS xmlns:xrds="xri://$xrds" xmlns="xri://$xrd*($v*2.0)"> | ||
<XRD> | ||
<Service priority="0"> | ||
<Type>http://specs.openid.net/auth/2.0/server</Type> | ||
<URI>http://example.com/</URI> | ||
</Service> | ||
</XRD> | ||
</xrds:XRDS>''' | ||
|
||
|
||
class FakeFetcher(object): | ||
"""Fake fetcher for tests.""" | ||
|
||
def __init__(self): | ||
self.response = None | ||
|
||
def fetch(self, *args, **kwargs): | ||
return self.response | ||
|
||
|
||
class TestStartOpenID(TestCase): | ||
"""Test 'startOpenID' view.""" | ||
|
||
def setUp(self): | ||
self.fetcher = FakeFetcher() | ||
setDefaultFetcher(self.fetcher) | ||
|
||
def tearDown(self): | ||
setDefaultFetcher(None) | ||
|
||
def test_get(self): | ||
response = self.client.get('/consumer/') | ||
self.assertContains(response, ' example consumer ') | ||
|
||
def test_post(self): | ||
self.fetcher.response = HTTPResponse('http://example.com/', 200, {'content-type': YADIS_CONTENT_TYPE}, | ||
EXAMPLE_XRDS) | ||
|
||
response = self.client.post('/consumer/', {'openid_identifier': 'http://example.com/'}) | ||
|
||
# Renders a POST form | ||
self.assertContains(response, 'http://example.com/') | ||
self.assertContains(response, 'openid.identity') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters