'Test unpublished layer behaviour'

def test_unpublished_layer(self):

    user = get_user_model().objects.get(username='bobby')
    self.client.login(username='bobby', password='bob')
    response = self.client.get(reverse('layer_detail', args=('geonode:CA',)))
    self.failUnlessEqual(response.status_code, 200)
    layer = Layer.objects.filter(title='CA')[0]
    layer.is_published = False
    layer.save()
    response = self.client.get(reverse('layer_detail', args=('geonode:CA',)))
    self.failUnlessEqual(response.status_code, 200)
    with self.settings(RESOURCE_PUBLISHING=True):
        response = self.client.get(reverse('layer_detail', args=('geonode:CA',)))
        self.failUnlessEqual(response.status_code, 404)
        assign_perm('publish_resourcebase', user, layer.get_self_resource())
        response = self.client.get(reverse('layer_detail', args=('geonode:CA',)))
        self.failUnlessEqual(response.status_code, 200)
        layer.is_published = True
        layer.save()
        remove_perm('publish_resourcebase', user, layer.get_self_resource())
        response = self.client.get(reverse('layer_detail', args=('geonode:CA',)))
        self.failUnlessEqual(response.status_code, 200)
    layer.is_published = True
    layer.save()
