from __future__ import unicode_literals

from django.test import TestCase

from caffeine_oauth2.models import CoffeestatsApplication


class CoffeestatsApplicationTest(TestCase):
    def test___str__(self):
        application = CoffeestatsApplication(name='test', client_id='client')
        self.assertEquals(str(application), 'test client')

@@ -34,16 +34,108 @@
 terals%0A%0A
+from django.contrib.auth import get_user_model%0Afrom django.core.urlresolvers import reverse%0A
 from dja
@@ -159,16 +159,16 @@
 estCase%0A
-
 %0Afrom ca
@@ -219,16 +219,41 @@
 cation%0A%0A
+User = get_user_model()%0A%0A
 %0Aclass C
@@ -395,16 +395,16 @@
 lient')%0A
-
         
@@ -446,16 +446,1704 @@
  'test client')%0A
+%0A    def test_get_absolute_url_unapproved(self):%0A        application = CoffeestatsApplication(name='test', client_id='client',%0A                                             pk=1)%0A        self.assertEqual(%0A            application.get_absolute_url(),%0A            reverse('oauth2_provider:pending_approval', kwargs=%7B'pk': 1%7D))%0A%0A    def test_get_absolute_url_approved(self):%0A        application = CoffeestatsApplication(name='test', client_id='client',%0A                                             pk=1, approved=True)%0A        self.assertEqual(%0A            application.get_absolute_url(),%0A            reverse('oauth2_provider:detail', kwargs=%7B'pk': 1%7D))%0A%0A    def test_approve(self):%0A        application = CoffeestatsApplication(name='test', client_id='client')%0A        self.assertFalse(application.approved)%0A        self.assertIsNone(application.approved_by_id)%0A        self.assertIsNone(application.approved_on)%0A        user = User(username='tester')%0A        application.approve(user)%0A        self.assertTrue(application.approved)%0A        self.assertEqual(application.approved_by, user)%0A        self.assertIsNotNone(application.approved_on)%0A%0A    def test_reject(self):%0A        user = User.objects.create(username='tester')%0A        application = CoffeestatsApplication.objects.create(%0A            name='test', agree=False, user=user)%0A        client_id = application.client_id%0A        self.assertIsNotNone(client_id)%0A        found = CoffeestatsApplication.objects.get(client_id=client_id)%0A        self.assertEqual(found, application)%0A        found.reject()%0A        with self.assertRaises(CoffeestatsApplication.DoesNotExist):%0A            CoffeestatsApplication.objects.get(client_id=client_id)%0A

Add tests for new caffeine_oauth2.models code