Example #1
0
 def test_post_with_errors(self):
     ApiAccessRequestFactory(user=self.user, status=ApiAccessRequest.APPROVED)
     response = self.client.post(self.url, {
         'name': 'test.com',
         'redirect_uris': 'not a url'
     })
     self.assertContains(response, 'Enter a valid URL.')
Example #2
0
 def test_post(self, status, application_exists, new_application_created):
     """
     Verify that posting the form creates an application if the user is
     approved, and does not otherwise. Also ensure that if the user
     already has an application, it is deleted before a new
     application is created.
     """
     if application_exists:
         old_application = ApplicationFactory(user=self.user)
     ApiAccessRequestFactory(user=self.user, status=status)
     self.client.post(self.url, {
         'name': 'test.com',
         'redirect_uris': 'http://example.com'
     })
     applications = Application.objects.filter(user=self.user)
     if application_exists and new_application_created:
         self.assertEqual(applications.count(), 1)
         self.assertNotEqual(old_application, applications[0])
     elif application_exists:
         self.assertEqual(applications.count(), 1)
         self.assertEqual(old_application, applications[0])
     elif new_application_created:
         self.assertEqual(applications.count(), 1)
     else:
         self.assertEqual(applications.count(), 0)
Example #3
0
 def test_get_with_existing_request(self):
     """
     Verify that users who have already requested access are redirected
     to the client creation page to see their status.
     """
     ApiAccessRequestFactory(user=self.user)
     response = self.client.get(self.url)
     self.assertRedirects(response, reverse('api_admin:api-status'))
Example #4
0
 def test_get_with_request(self, status, expected):
     """
     Verify that users who have requested access can see a message
     regarding their request status.
     """
     ApiAccessRequestFactory(user=self.user, status=status)
     response = self.client.get(self.url)
     self.assertContains(response, expected)
Example #5
0
 def test_get_with_request(self):
     """
     Verify that users who have requested access can see a message
     regarding their request status.
     """
     ApiAccessRequestFactory(user=self.user)
     response = self.client.get(self.url)
     self.assertEqual(response.status_code, 200)
Example #6
0
 def test_get_with_existing_application(self):
     """
     Verify that if the user has created their client credentials, they
     are shown on the status page.
     """
     ApiAccessRequestFactory(user=self.user, status=ApiAccessRequest.APPROVED)
     application = ApplicationFactory(user=self.user)
     response = self.client.get(self.url)
     self.assertContains(response, application.client_secret)
     self.assertContains(response, application.client_id)
     self.assertContains(response, application.redirect_uris)
Example #7
0
 def test_get_with_existing_application(self):
     """
     Verify that if the user has created their client credentials, they
     are shown on the status page.
     """
     ApiAccessRequestFactory(user=self.user, status=ApiAccessRequest.APPROVED)
     application = ApplicationFactory(user=self.user)
     response = self.client.get(self.url)
     self.assertEqual(response.status_code, 200)
     unicode_content = response.content.decode('utf-8')
     self.assertIn(application.client_secret, unicode_content)  # pylint: disable=no-member
     self.assertIn(application.client_id, unicode_content)  # pylint: disable=no-member
     self.assertIn(application.redirect_uris, unicode_content)  # pylint: disable=no-member
Example #8
0
 def test_unique_per_user(self):
     with self.assertRaises(IntegrityError):
         ApiAccessRequestFactory(user=self.user)
Example #9
0
 def setUp(self):
     super(ApiAccessRequestTests, self).setUp()
     self.user = UserFactory()
     self.request = ApiAccessRequestFactory(user=self.user)
Example #10
0
 def setUp(self):
     super(ApiAccessRequestTests, self).setUp()  # lint-amnesty, pylint: disable=super-with-arguments
     self.user = UserFactory()
     self.request = ApiAccessRequestFactory(user=self.user)