"""
Tests for token endpoints.
"""
from txoauth import token, clientcred as cred
from txoauth.test.test_clientcred import IDENTIFIER, BOGUS_IDENTIFIER, URI

from twisted.trial.unittest import TestCase

TYPE, ASSERTION = "", ""
BOGUS_TYPE, BOGUS_ASSERTION = "", ""


class AssertionTests(TestCase):
    def setUp(self):
        self.credentials = cred.ClientIdentifier(IDENTIFIER, URI)
        self.bogusCredentials = cred.ClientIdentifier(BOGUS_IDENTIFIER, URI)
        self.assertion = token.Assertion(self.credentials, TYPE, ASSERTION)


    def test_interface(self):
        self.assertTrue(token.IAssertion.implementedBy(token.Assertion))


    def test_simple(self):
        self.assertEqual(self.assertion.client, self.credentials)
        self.assertEqual(self.assertion.assertionType, TYPE)
        self.assertEqual(self.assertion.assertion, ASSERTION)


    def test_clientImmutability_same(self):
        def mutateClient():
            self.assertion.client = self.credentials
        self.assertRaises(AttributeError, mutateClient)


    def test_clientImmutability_different(self):
        def mutateClient():
            self.assertion.client = self.bogusCredentials
        self.assertRaises(AttributeError, mutateClient)


    def test_assertionTypeImmutability_same(self):
        def mutateAssertionType():
            self.assertion.assertionType = TYPE
        self.assertRaises(AttributeError, mutateAssertionType)


    def test_assertionTypeImmutability_different(self):
        def mutateAssertionType():
            self.assertion.assertionType = BOGUS_TYPE
        self.assertRaises(AttributeError, mutateAssertionType)


    def test_assertionImmutability_same(self):
        def mutateAssertion():
            self.assertion.assertion = ASSERTION
        self.assertRaises(AttributeError, mutateAssertion)


    def test_assertionImmutability_different(self):
        def mutateAssertion():
            self.assertion.assertion = BOGUS_ASSERTION
        self.assertRaises(AttributeError, mutateAssertion)

"""
Tests for token endpoints.
"""
from txoauth import token, clientcred as cred
from txoauth.test.test_clientcred import IDENTIFIER, BOGUS_IDENTIFIER, URI

from twisted.trial.unittest import TestCase


class _TokenRequestTests(TestCase):
    interface, implementer = None, None

    def setUp(self):
        self.credentials = cred.ClientIdentifier(IDENTIFIER, URI)
        self.bogusCredentials = cred.ClientIdentifier(BOGUS_IDENTIFIER, URI)


    def test_interface(self):
        self.assertTrue(token.ITokenRequest.implementedBy(self.implementer))
        self.assertTrue(self.interface.implementedBy(self.implementer))


    def test_clientCredentialsImmutability_same(self):
        def mutateClient():
            self.assertion.clientCredentials = self.credentials
        self.assertRaises(AttributeError, mutateClient)


    def test_clientCredentialsImmutability_different(self):
        def mutateClient():
            self.assertion.clientCredentials = self.bogusCredentials
        self.assertRaises(AttributeError, mutateClient)



class BaseTokenRequestTestCase(_TokenRequestTests):
    interface, implementer = token.ITokenRequest, token._BaseTokenRequest


TYPE, ASSERTION = "", ""
BOGUS_TYPE, BOGUS_ASSERTION = "", ""


class AssertionTests(_TokenRequestTests):
    interface, implementer = token.IAssertion, token.Assertion

    def setUp(self):
        _TokenRequestTests.setUp(self)
        self.assertion = token.Assertion(self.credentials, TYPE, ASSERTION)


    def test_interface(self):
        self.assertTrue(token.IAssertion.implementedBy(token.Assertion))


    def test_simple(self):
        self.assertEqual(self.assertion.clientCredentials, self.credentials)
        self.assertEqual(self.assertion.assertionType, TYPE)
        self.assertEqual(self.assertion.assertion, ASSERTION)


    def test_assertionTypeImmutability_same(self):
        def mutateAssertionType():
            self.assertion.assertionType = TYPE
        self.assertRaises(AttributeError, mutateAssertionType)


    def test_assertionTypeImmutability_different(self):
        def mutateAssertionType():
            self.assertion.assertionType = BOGUS_TYPE
        self.assertRaises(AttributeError, mutateAssertionType)


    def test_assertionImmutability_same(self):
        def mutateAssertion():
            self.assertion.assertion = ASSERTION
        self.assertRaises(AttributeError, mutateAssertion)


    def test_assertionImmutability_different(self):
        def mutateAssertion():
            self.assertion.assertion = BOGUS_ASSERTION
        self.assertRaises(AttributeError, mutateAssertion)

Test refactoring and fixes