'Test permissions on an unpublished layer'

def test_unpublished(self):

    thefile = os.path.join(gisdata.VECTOR_DATA, 'san_andres_y_providencia_poi.shp')
    layer = file_upload(thefile, overwrite=True)
    layer.set_default_permissions()
    check_layer(layer)
    time.sleep(20)
    url = 'http://localhost:8080/geoserver/ows?service=wms&version=1.3.0&request=GetCapabilities'
    str_to_check = '<Name>geonode:san_andres_y_providencia_poi</Name>'
    request = urllib2.Request(url)
    response = urllib2.urlopen(request)
    self.assertTrue(any(((str_to_check in s) for s in response.readlines())))
    self.assertTrue(layer.is_published, True)
    layer.delete()
    with self.settings(RESOURCE_PUBLISHING=True):
        thefile = os.path.join(gisdata.VECTOR_DATA, 'san_andres_y_providencia_administrative.shp')
        layer = file_upload(thefile, overwrite=True)
        layer.set_default_permissions()
        check_layer(layer)
        time.sleep(20)
        str_to_check = '<Name>san_andres_y_providencia_administrative</Name>'
        self.assertEqual(layer.is_published, False)
        request = urllib2.Request(url)
        response = urllib2.urlopen(request)
        self.assertFalse(any(((str_to_check in s) for s in response.readlines())))
        resource = layer.get_self_resource()
        resource.is_published = True
        resource.save()
        request = urllib2.Request(url)
        response = urllib2.urlopen(request)
        self.assertTrue(any(((str_to_check in s) for s in response.readlines())))
        layer.delete()
