'Test that layers can be uploaded to running GeoNode/GeoServer'

def test_layer_upload(self):

    layers = {}
    expected_layers = []
    not_expected_layers = []
    for filename in os.listdir(gisdata.GOOD_DATA):
        (basename, extension) = os.path.splitext(filename)
        if (extension.lower() in ['.tif', '.shp', '.zip']):
            expected_layers.append(os.path.join(gisdata.GOOD_DATA, filename))
    for filename in os.listdir(gisdata.BAD_DATA):
        not_expected_layers.append(os.path.join(gisdata.BAD_DATA, filename))
    uploaded = upload(gisdata.DATA_DIR, console=None)
    for item in uploaded:
        errors = ('error' in item)
        if errors:
            if (item['file'] in not_expected_layers):
                continue
            else:
                msg = ('Could    not    upload    file    "%s",    and    it    is    not    in    %s' % (item['file'], not_expected_layers))
                assert errors, msg
        else:
            msg = ('Upload    should    have    returned    either    "name"    or    "errors"    for    file    %s.' % item['file'])
            assert ('name' in item), msg
            layers[item['file']] = item['name']
    msg = ('There    were    %s    compatible    layers    in    the    directory,    but    only    %s    were    sucessfully    uploaded' % (len(expected_layers), len(layers)))
    for layer in expected_layers:
        msg = ('The    following    file    should    have    been    uploadedbut    was    not:    %s.    ' % layer)
        assert (layer in layers), msg
        layer_name = layers[layer]
        Layer.objects.get(name=layer_name)
        found = False
        (gs_username, gs_password) = (settings.OGC_SERVER['default']['USER'], settings.OGC_SERVER['default']['PASSWORD'])
        page = get_web_page(os.path.join(settings.OGC_SERVER['default']['LOCATION'], 'rest/layers'), username=gs_username, password=gs_password)
        if (page.find(('rest/layers/%s.html' % layer_name)) > 0):
            found = True
        if (not found):
            msg = ('Upload    could    not    be    verified,    the    layer    %s    is    not    in    geoserver    %s,    but    GeoNode    did    not    raise    any    errors,    this    should    never    happen.' % (layer_name, settings.OGC_SERVER['default']['LOCATION']))
            raise GeoNodeException(msg)
    for layer in expected_layers:
        layer_name = layers[layer]
        Layer.objects.get(name=layer_name).delete()
