Beispiel #1
0
class UploadLayersTest(TestCase):
    def setUp(self):
        self.user = "******"
        self.passwd = "admin"
        # self.anonymous_user = get_anonymous_user()
        self.publisher = SceneAnalyticPublisher(scenepath="test_coveragestore",
                                                date=datetime.date(1970, 1, 1))
        self.publisher.stats_dict = {
            "filename": "test_coveragestore.tiff",
            "clouds": 1,
            "desert": 2,
            "vegetation": 3,
            "water": 4,
            "keywords": ["test1", "test2"],
        }
        self.admin_user = Profile(username="******", password="******")
        self.admin_user.save()

    def test_luigi_upload_layer(self):
        self.publisher.upload_layer()
        layer = Layer.objects.get(name="test_coveragestore")
        res = self.client.get("/layers/geonode:test_coveragestore")
        self.assertEqual(res.status_code, 200)
        self.assertEqual(layer.date.date(), self.publisher.date)
        self.assertEqual([kw.name for kw in layer.keywords.all()],
                         self.publisher.stats_dict["keywords"])

    def test_upload_metadata(self):
        self.publisher.stats_model = SVMClassifierStats
        self.publisher.upload_layer()
        self.publisher.upload_metadata()
        stats = SVMClassifierStats.objects.all()
        self.assertEqual(len(stats), 1)
        self.assertEqual(stats[0].layer, self.publisher.layer)
        self.assertEqual(stats[0].clouds, 1)
        self.assertEqual(stats[0].desert, 2)
        self.assertEqual(stats[0].vegetation, 3)
        self.assertEqual(stats[0].water, 4)

    def test_upload_sld(self):
        with mock.patch("geonode.geoserver.signals") as m:
            cat = m.gs_catalog
            self.publisher.sld = os.path.join(
                os.path.dirname(geonode.wheel.publishers.__file__),
                "svmclassifier.sld")
            cat.get_style.return_value = None
            self.publisher.upload_sld_to_gs()
            self.assertTrue(
                cat.create_style.called_with(self.publisher.sld,
                                             "svmclassifier"))
            cat.get_style.return_value = 1
            self.publisher.upload_sld_to_gs()
            self.assertFalse(cat.create_style.called)

    def tearDown(self):
        layers = Layer.objects.all()
        for layer in layers:
            layer.delete()  # we don't want to leave layer in geoserver
Beispiel #2
0
def app_create(request, is_service=False):
    if request.method == "POST":
        form = AppForm(request.POST, request.FILES, is_service=is_service)
        if form.is_valid():
            app = form.save(commit=False)
            app.save()
            form.save_m2m()
            app.join(request.user, role="manager")
            
            app_user = Profile(username=app.slug[:25], profile='application', organization=app.title)
            app_user.save()
            app.join(app_user, role="alter_ego")

            return HttpResponseRedirect(
                reverse("app_detail", args=[app.slug])
            )
    else:
        form = AppForm(is_service=is_service)

    return render_to_response("apps/app_create.html", {
        "form": form,
    }, context_instance=RequestContext(request,{'is_service':is_service}))
Beispiel #3
0
def create_users(n_users):
    """ Create n users in the database """
    for i in range(0, n_users):
        user = Profile()
        user.username = '******' % i
        user.save()
def create_users(n_users):
    """ Create n users in the database """
    for i in range(0, n_users):
        user = Profile()
        user.username = '******' % i
        user.save()