'Test the PrintProxyMiddleware if activated.
It should respect the permissions on private layers.'

def testPrintProxy(self):

    if ('geonode.middleware.PrintProxyMiddleware' in settings.MIDDLEWARE_CLASSES):
        from geonode.maps.models import Map
        self.client.login(username='norman', password='norman')
        norman = get_user_model().objects.get(username='norman')
        saved_layer = file_upload(os.path.join(gisdata.VECTOR_DATA, 'san_andres_y_providencia_poi.shp'), name='san_andres_y_providencia_poi_by_norman', user=norman, overwrite=True)
        saved_layer.set_permissions({'users': {'AnonymousUser': ['view_resourcebase']}})
        url = reverse('layer_metadata', args=[saved_layer.service_typename])
        resp = self.client.get(url)
        self.assertEquals(resp.status_code, 200)
        self.client.logout()
        resp = self.client.get(url)
        self.assertEquals(resp.status_code, 302)
        map_obj = Map(owner=norman, zoom=0, center_x=0, center_y=0)
        map_obj.create_from_layer_list(norman, [saved_layer], 'title', '')
        print_url = (settings.OGC_SERVER['default']['LOCATION'] + 'pdf/create.json')
        post_payload = {'dpi': 75, 'layers': [{'baseURL': (settings.OGC_SERVER['default']['LOCATION'] + 'wms?SERVICE=WMS&'), 'format': 'image/png', 'customParams': {'TILED': True, 'TRANSPARENT': True}, 'layers': [saved_layer.service_typename], 'opacity': 1, 'singleTile': False, 'type': 'WMS'}], 'layout': 'A4    portrait', 'mapTitle': 'test', 'outputFilename': 'print', 'srs': getattr(settings, 'DEFAULT_MAP_CRS', 'EPSG:900913'), 'units': 'm'}
        self.client.post(print_url, post_payload)
        resp = self.client.get(url)
        self.assertEquals(resp.status_code, 302)
    else:
        pass
