'Verify that the ajax_document_permissions view is behaving as expected'

def test_ajax_document_permissions(self):

    f = SimpleUploadedFile('test_img_file.gif', self.imgfile.read(), 'image/gif')
    superuser = get_user_model().objects.get(pk=2)
    document = Document.objects.create(doc_file=f, owner=superuser, title='theimg')
    document.set_default_permissions()
    document_id = document.id
    invalid_document_id = 20
    response = self.client.post(reverse('resource_permissions', args=(invalid_document_id,)), data=json.dumps(self.perm_spec), content_type='application/json')
    self.assertEquals(response.status_code, 404)
    response = self.client.get(reverse('resource_permissions', args=(document_id,)))
    assert ('permissions' in response.content)
    response = self.client.post(reverse('resource_permissions', args=(document_id,)), data=json.dumps(self.perm_spec), content_type='application/json')
    self.assertEquals(response.status_code, 401)
    logged_in = self.client.login(username='bobby', password='bob')
    self.assertEquals(logged_in, True)
    response = self.client.post(reverse('resource_permissions', args=(document_id,)), data=json.dumps(self.perm_spec), content_type='application/json')
    self.assertEquals(response.status_code, 401)
    logged_in = self.client.login(username='admin', password='admin')
    self.assertEquals(logged_in, True)
    response = self.client.post(reverse('resource_permissions', args=(document_id,)), data=json.dumps(self.perm_spec), content_type='application/json')
    self.assertEquals(response.status_code, 200)
