'Verify that the ajax_layer_permissions view is behaving as expected'

def test_ajax_map_permissions(self):

    mapid = Map.objects.all()[0].pk
    invalid_mapid = '42'
    def url(id):
        return reverse('resource_permissions', args=[id])
    response = self.client.post(url(invalid_mapid), data=json.dumps(self.perm_spec), content_type='application/json')
    self.assertEquals(response.status_code, 404)
    response = self.client.get(url(mapid))
    assert ('permissions' in response.content)
    response = self.client.post(url(mapid), 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(url(mapid), 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(url(mapid), data=json.dumps(self.perm_spec), content_type='application/json')
    self.assertEquals(response.status_code, 200)
