Exemplo n.º 1
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')
Exemplo n.º 2
0
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)
Exemplo n.º 3
0
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)
Exemplo n.º 4
0
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)
Exemplo n.º 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})
Exemplo n.º 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})
Exemplo n.º 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')
Exemplo n.º 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")
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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")
Exemplo n.º 13
0
 def setUp(self):
     self.obj = Map(name="the map", edit_id="edit id", view_id="view id", is_public=False)
     self.obj.save()
Exemplo n.º 14
0
 def setUp(self):
     self.obj = Map(name="the map", edit_id="edit id", view_id="view id")
     self.obj.save()
Exemplo n.º 15
0
 def setUp(self):
     self.obj = Map(name='the map', edit_id='edit id', view_id='view id')
     self.obj.save()
Exemplo n.º 16
0
 def setUp(self):
     self.obj = Map(name='the map',
                    edit_id='edit id',
                    view_id='view id',
                    is_public=False)
     self.obj.save()
Exemplo n.º 17
0
 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()
Exemplo n.º 18
0
 def setUp(self):
     self.obj = Map(name='the map', edit_id='edit id', view_id='view id')
     self.obj.save()