class TestMapFeatureRetrieving(TestCase):
    def setUp(self):
        self.obj = Map(name='the map', edit_id='edit id', view_id='view id')
        self.obj.save()
        self.feature = MapFeature(feature_type=MapFeature.TYPE_REVEAL, map=self.obj,
            data='123')
        self.feature.save()


    def test_get_without_map_id(self):
        response = self.client.get(reverse('features-list'))
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.data), 0)

    def test_get_by_edit_id(self):
        response = self.client.get(reverse('features-list'), {'map': self.obj.edit_id})
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.data), 1)
        self.assertEqual(response.data[0]['id'], self.feature.id)

    def test_get_by_view_id(self):
        response = self.client.get(reverse('features-list'), {'map': self.obj.view_id})
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.data), 1)
        self.assertEqual(response.data[0]['id'], self.feature.id)
Beispiel #2
0
class TestMapRetrieving(TestCase):
    def setUp(self):
        self.obj = Map(name='the map',
                       edit_id='edit id',
                       view_id='view id',
                       is_public=False)
        self.obj.save()

    def test_get_by_edit_id(self):
        response = self.client.get(
            reverse('maps-detail', kwargs={'id': self.obj.edit_id}))
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.data['name'], 'the map')

    def test_get_by_view_id(self):
        response = self.client.get(
            reverse('maps-detail', kwargs={'id': self.obj.view_id}))
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.data['name'], 'the map')

    def test_list_public(self):
        public_map = Map(name='public map', is_public=True)
        public_map.save()

        response = self.client.get(reverse('maps-list'))
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.data), 1)
        self.assertEqual(response.data[0]['name'], 'public map')
class TestEdit(TestCase):
    def setUp(self):
        self.obj = Map(name='the map', edit_id='edit_id', view_id='view_id')
        self.obj.save()
        self.feature = MapFeature(feature_type=MapFeature.TYPE_REVEAL, map=self.obj,
            data='123')
        self.feature.save()

    def test_edit_data_by_edit_id(self):
        url = (reverse('features-detail', kwargs={'id': self.feature.id})
            + '?map=%s' % self.feature.map.edit_id)

        response = self.client.patch(url, json.dumps({'data': 443}),
            content_type='application/json')

        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.data['data'], 443)
        self.assertEqual(response.data['id'], self.feature.id)

    def test_edit_data_by_view_id(self):
        url = (reverse('features-detail', kwargs={'id': self.feature.id})
            + '?map=%s' % self.feature.map.view_id)

        response = self.client.patch(url, None,
            content_type='application/json')

        self.assertEqual(response.status_code, 403)
class TestAddingMapFeatures(TestCase):
    def setUp(self):
        self.obj = Map(name='the map', edit_id='edit id', view_id='view id')
        self.obj.save()

    def test_add_using_edit_id(self):
        data = {
            'map': self.obj.edit_id,
            'feature_type': MapFeature.TYPE_REVEAL
        }

        response = self.client.post(reverse('features-list'),
            json.dumps(data), content_type='application/json')
        self.assertEqual(response.status_code, 201)
        self.assertEqual(self.obj.features.count(), 1)


    def test_add_using_view_id(self):
        data = {
            'map': self.obj.view_id,
            'feature_type': MapFeature.TYPE_REVEAL
        }

        response = self.client.post(reverse('features-list'),
            json.dumps(data), content_type='application/json')
        self.assertEqual(response.status_code, 400)
        self.assertEqual(self.obj.features.count(), 0)
Beispiel #5
0
def create_step_3(request):
    maps = request.user.editable_maps.all()
    errors = []
    if request.method == "POST":
        if 'map' not in request.POST:
            errors.append('Выберите карту или создайте новую')
        else:
            map = request.POST.get('map')
            if map == 'new':
                description = request.POST.get('map-description')
                name = request.POST.get('map-name')
                m = Map(name=name, description=description,
                        user=request.user)
                m.save()
                m.editors.add(request.user)
                map = m
            else:
                map = Map.objects.get(id=int(map))

            if not request.POST.get('dataset-name'):
                dataset_name = generate_random_string(10)
            else:
                dataset_name = request.POST['dataset-name']

            dataset = Dataset.objects.create(name=dataset_name, map=map)
            dataset.save()

            request.session[STEP_3_MAP] = map.id
            request.session[STEP_3_DATASET] = dataset.id
            return redirect('step4')
    return render(request, 'create-3.html', {'maps': maps, 'errors': errors})
Beispiel #6
0
def create_step_3(request):
    maps = request.user.editable_maps.all()
    errors = []
    if request.method == "POST":
        if 'map' not in request.POST:
            errors.append('Выберите карту или создайте новую')
        else:
            map = request.POST.get('map')
            if map == 'new':
                description = request.POST.get('map-description')
                name = request.POST.get('map-name')
                m = Map(name=name, description=description, user=request.user)
                m.save()
                m.editors.add(request.user)
                map = m
            else:
                map = Map.objects.get(id=int(map))

            if not request.POST.get('dataset-name'):
                dataset_name = generate_random_string(10)
            else:
                dataset_name = request.POST['dataset-name']

            dataset = Dataset.objects.create(name=dataset_name, map=map)
            dataset.save()

            request.session[STEP_3_MAP] = map.id
            request.session[STEP_3_DATASET] = dataset.id
            return redirect('step4')
    return render(request, 'create-3.html', {'maps': maps, 'errors': errors})
Beispiel #7
0
    def test_list_public(self):
        public_map = Map(name="public map", is_public=True)
        public_map.save()

        response = self.client.get(reverse("maps-list"))
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.data), 1)
        self.assertEqual(response.data[0]["name"], "public map")
Beispiel #8
0
    def test_list_public(self):
        public_map = Map(name='public map', is_public=True)
        public_map.save()

        response = self.client.get(reverse('maps-list'))
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.data), 1)
        self.assertEqual(response.data[0]['name'], 'public map')
Beispiel #9
0
 def get(self,
         request,
         longtitude,
         lat,
         km,
         monumentbool,
         nr_of_mutations,
         format=None):
     location = [float(longtitude), float(lat)]
     url_item = generate_map_urls(location,
                                  int(km) * 1000, bool(monumentbool),
                                  int(nr_of_mutations))
     # print url_item
     map_item = Map(url=url_item)
     map_item.save()
     serializer = MapSerializer(map_item, many=False)
     return Response(serializer.data)
Beispiel #10
0
class TestUpdating(TestCase):
    def setUp(self):
        self.obj = Map(name='the map', edit_id='edit id', view_id='view id')
        self.obj.save()

    def test_update_by_edit_id(self):
        response = self.client.patch(reverse('maps-detail',
                                             kwargs={'id': self.obj.edit_id}),
                                     json.dumps({'name': 'foobar'}),
                                     content_type='application/json')
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.data['name'], 'foobar')

    def test_update_by_view_id(self):
        response = self.client.patch(reverse('maps-detail',
                                             kwargs={'id': self.obj.view_id}),
                                     json.dumps({'name': 'foobar'}),
                                     content_type='application/json')
        self.assertEqual(response.status_code, 403)
Beispiel #11
0
class TestUpdating(TestCase):
    def setUp(self):
        self.obj = Map(name="the map", edit_id="edit id", view_id="view id")
        self.obj.save()

    def test_update_by_edit_id(self):
        response = self.client.patch(
            reverse("maps-detail", kwargs={"id": self.obj.edit_id}),
            json.dumps({"name": "foobar"}),
            content_type="application/json",
        )
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.data["name"], "foobar")

    def test_update_by_view_id(self):
        response = self.client.patch(
            reverse("maps-detail", kwargs={"id": self.obj.view_id}),
            json.dumps({"name": "foobar"}),
            content_type="application/json",
        )
        self.assertEqual(response.status_code, 403)
Beispiel #12
0
class TestMapRetrieving(TestCase):
    def setUp(self):
        self.obj = Map(name="the map", edit_id="edit id", view_id="view id", is_public=False)
        self.obj.save()

    def test_get_by_edit_id(self):
        response = self.client.get(reverse("maps-detail", kwargs={"id": self.obj.edit_id}))
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.data["name"], "the map")

    def test_get_by_view_id(self):
        response = self.client.get(reverse("maps-detail", kwargs={"id": self.obj.view_id}))
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.data["name"], "the map")

    def test_list_public(self):
        public_map = Map(name="public map", is_public=True)
        public_map.save()

        response = self.client.get(reverse("maps-list"))
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.data), 1)
        self.assertEqual(response.data[0]["name"], "public map")