class TestOauthGroup(TestCase): def setUp(self): super(TestOauthGroup, self).setUp() self.group, _ = Group.objects.get_or_create(name='Hydroshare Author') self.client = Client() self.user = users.create_account('*****@*****.**', username='******', password='******', first_name='some_first_name1', last_name='some_last_name1', groups=[], superuser=False) self.user.set_password("abc123") self.user2 = users.create_account('*****@*****.**', username='******', password='******', first_name='some_first_name2', last_name='some_last_name2', groups=[], superuser=False) self.user2.set_password("abc123") self.testGroup1 = self.user.uaccess.create_group( title="Test Group", description="Group for testing") def tearDown(self): super(TestOauthGroup, self).tearDown() self.user.delete() self.user2.delete() self.testGroup1.delete() self.group.delete() def test_application_group(self): # register the application self.client.login(username=self.user.username, password='******') form_data = { "name": "Foo app", "client_id": "nfd0fufZtcuNQT2Uzoag19TqTWE6CJtPusKD268B", "client_secret": "client_secret", "client_type": "public", "redirect_uris": "https://www.google.com", "authorization_grant_type": "authorization-code", } response = self.client.post(reverse("oauth2_provider:register"), form_data) self.assertEqual(response.status_code, 302) group_authorize = '/o/groupauthorize/{}/?redirect_uri=https://www.google.com&' \ 'client_id=nfd0fufZtcuNQT2Uzoag19TqTWE6CJtPusKD268B&' \ 'response_type=code'.format(self.testGroup1.pk) # check user in group can authenticate response = self.client.get(group_authorize, follow=True) self.assertEquals(response.status_code, 200) # check user not in group cannot authenticate self.client.logout() self.client.login(username=self.user2.username, password='******') response = self.client.get(group_authorize, follow=True) self.assertEquals(response.redirect_chain, [('/group/{}'.format(self.testGroup1.pk), 302)])
def setUp(self): super(TestOauthGroup, self).setUp() self.group, _ = Group.objects.get_or_create(name='Hydroshare Author') self.client = Client() self.user = users.create_account('*****@*****.**', username='******', password='******', first_name='some_first_name1', last_name='some_last_name1', groups=[], superuser=False) self.user.set_password("abc123") self.user2 = users.create_account('*****@*****.**', username='******', password='******', first_name='some_first_name2', last_name='some_last_name2', groups=[], superuser=False) self.user2.set_password("abc123") self.testGroup1 = self.user.uaccess.create_group( title="Test Group", description="Group for testing")
def test_image_view_template_extends_base(self): image = Image.objects.create(title='my image', image='my_image.jpg') client = Client() response = client.get(resolve_url(image)) self.assertTemplateUsed(response, 'base.html')
def test_image_delete_view(self): image = Image.objects.create(title='my image', image='my_image.jpg') client = Client() response = client.get(resolve_url('image_delete', pk=image.id)) self.assertEqual(response.context['image'], image)
def test_image_view_returns_200(self): image = Image.objects.create(title='my image', image='my_image.jpg') client = Client() response = client.get(image.get_absolute_url()) self.assertEqual(response.status_code, 200)