示例#1
0
    def test_json(self):
        """Test target JSON."""
        l = GpsPosition(latitude=38, longitude=-76)
        l.save()

        t = Target(user=self.user,
                   target_type=TargetType.standard,
                   location=l,
                   orientation=Orientation.s,
                   shape=Shape.square,
                   background_color=Color.white,
                   alphanumeric='ABC',
                   alphanumeric_color=Color.black,
                   description='Test target')
        t.save()

        d = t.json()

        self.assertIn('id', d)
        self.assertEqual(self.user.pk, d['user'])
        self.assertEqual('standard', d['type'])
        self.assertEqual(38, d['latitude'])
        self.assertEqual(-76, d['longitude'])
        self.assertEqual('s', d['orientation'])
        self.assertEqual('square', d['shape'])
        self.assertEqual('white', d['background_color'])
        self.assertEqual('ABC', d['alphanumeric'])
        self.assertEqual('black', d['alphanumeric_color'])
        self.assertEqual('Test target', d['description'])
示例#2
0
    def test_put_one(self):
        """PUT update one field without affecting others."""
        l = GpsPosition(latitude=38, longitude=-76)
        l.save()

        t = Target(user=self.user,
                   target_type=TargetType.standard,
                   location=l,
                   orientation=Orientation.s,
                   shape=Shape.square,
                   background_color=Color.white,
                   alphanumeric='ABC',
                   alphanumeric_color=Color.black,
                   description='Test target')
        t.save()

        data = {'shape': 'circle'}

        response = self.client.put(
            targets_id_url(args=[t.pk]),
            data=json.dumps(data))
        self.assertEqual(200, response.status_code)

        t.refresh_from_db()
        t.location.refresh_from_db()
        self.assertEqual(self.user, t.user)
        self.assertEqual(TargetType.standard, t.target_type)
        self.assertEqual(38, t.location.latitude)
        self.assertEqual(-76, t.location.longitude)
        self.assertEqual(Orientation.s, t.orientation)
        self.assertEqual(Shape.circle, t.shape)
        self.assertEqual(Color.white, t.background_color)
        self.assertEqual('ABC', t.alphanumeric)
        self.assertEqual(Color.black, t.alphanumeric_color)
        self.assertEqual('Test target', t.description)
示例#3
0
    def test_put_one(self):
        """PUT update one field without affecting others."""
        l = GpsPosition(latitude=38, longitude=-76)
        l.save()

        t = Target(
            user=self.user,
            target_type=TargetType.standard,
            location=l,
            orientation=Orientation.s,
            shape=Shape.square,
            background_color=Color.white,
            alphanumeric='ABC',
            alphanumeric_color=Color.black,
            description='Test target')
        t.save()

        data = {'shape': 'circle'}

        response = self.client.put(targets_id_url(args=[t.pk]),
                                   data=json.dumps(data))
        self.assertEqual(200, response.status_code)

        t.refresh_from_db()
        t.location.refresh_from_db()
        self.assertEqual(self.user, t.user)
        self.assertEqual(TargetType.standard, t.target_type)
        self.assertEqual(38, t.location.latitude)
        self.assertEqual(-76, t.location.longitude)
        self.assertEqual(Orientation.s, t.orientation)
        self.assertEqual(Shape.circle, t.shape)
        self.assertEqual(Color.white, t.background_color)
        self.assertEqual('ABC', t.alphanumeric)
        self.assertEqual(Color.black, t.alphanumeric_color)
        self.assertEqual('Test target', t.description)
示例#4
0
    def test_json(self):
        """Test target JSON."""
        l = GpsPosition(latitude=38, longitude=-76)
        l.save()

        t = Target(user=self.user,
                   target_type=TargetType.standard,
                   location=l,
                   orientation=Orientation.s,
                   shape=Shape.square,
                   background_color=Color.white,
                   alphanumeric='ABC',
                   alphanumeric_color=Color.black,
                   description='Test target',
                   autonomous=True)
        t.save()

        d = t.json()

        self.assertIn('id', d)
        self.assertEqual(self.user.pk, d['user'])
        self.assertEqual('standard', d['type'])
        self.assertEqual(38, d['latitude'])
        self.assertEqual(-76, d['longitude'])
        self.assertEqual('s', d['orientation'])
        self.assertEqual('square', d['shape'])
        self.assertEqual('white', d['background_color'])
        self.assertEqual('ABC', d['alphanumeric'])
        self.assertEqual('black', d['alphanumeric_color'])
        self.assertEqual('Test target', d['description'])
        self.assertEqual(True, d['autonomous'])
示例#5
0
    def test_put_review_no_approved(self):
        """Test PUT review with no approved field."""
        target = Target(user=self.team, target_type=TargetType.qrc)
        target.save()

        response = self.client.put(targets_review_id_url(args=[target.pk]))
        self.assertEqual(400, response.status_code)
示例#6
0
    def test_delete_other(self):
        """Test DELETEing a target owned by another user."""
        user2 = User.objects.create_user('testuser2', '*****@*****.**',
                                         'testpass')
        t = Target(user=user2, target_type=TargetType.standard)
        t.save()

        response = self.client.delete(targets_id_url(args=[t.pk]))
        self.assertEqual(403, response.status_code)
示例#7
0
    def test_get_other_user(self):
        """Test GETting a thumbnail owned by a different user."""
        user2 = User.objects.create_user('testuser2', '*****@*****.**',
                                         'testpass')
        t = Target(user=user2, target_type=TargetType.standard)
        t.save()

        response = self.client.get(targets_id_image_url(args=[t.pk]))
        self.assertEqual(403, response.status_code)
示例#8
0
    def test_get_own(self):
        """Test GETting a target owned by the correct user."""
        t = Target(user=self.user, target_type=TargetType.standard)
        t.save()

        response = self.client.get(targets_id_url(args=[t.pk]))
        self.assertEqual(200, response.status_code)

        self.assertEqual(t.json(), json.loads(response.content))
示例#9
0
    def test_delete_other(self):
        """Test DELETEing a target owned by another user."""
        user2 = User.objects.create_user('testuser2', '*****@*****.**',
                                         'testpass')
        t = Target(user=user2, target_type=TargetType.standard)
        t.save()

        response = self.client.delete(targets_id_url(args=[t.pk]))
        self.assertEqual(403, response.status_code)
示例#10
0
    def test_get_other_user(self):
        """Test GETting a thumbnail owned by a different user."""
        user2 = User.objects.create_user('testuser2', '*****@*****.**',
                                         'testpass')
        t = Target(user=user2, target_type=TargetType.standard)
        t.save()

        response = self.client.get(targets_id_image_url(args=[t.pk]))
        self.assertEqual(403, response.status_code)
示例#11
0
    def test_get_own(self):
        """Test GETting a target owned by the correct user."""
        t = Target(user=self.user, target_type=TargetType.standard)
        t.save()

        response = self.client.get(targets_id_url(args=[t.pk]))
        self.assertEqual(200, response.status_code)

        self.assertEqual(t.json(), json.loads(response.content))
示例#12
0
    def test_put_location_missing_one(self):
        """PUTting new location requires both latitude and longitude."""
        t = Target(user=self.user, target_type=TargetType.standard)
        t.save()

        data = {'latitude': 38}

        response = self.client.put(targets_id_url(args=[t.pk]),
                                   data=json.dumps(data))
        self.assertEqual(400, response.status_code)
示例#13
0
    def test_put_location_missing_one(self):
        """PUTting new location requires both latitude and longitude."""
        t = Target(user=self.user, target_type=TargetType.standard)
        t.save()

        data = {'latitude': 38}

        response = self.client.put(targets_id_url(args=[t.pk]),
                                   data=json.dumps(data))
        self.assertEqual(400, response.status_code)
示例#14
0
    def test_put_invalid_json(self):
        """PUT request body must be valid JSON."""
        l = GpsPosition(latitude=38, longitude=-76)
        l.save()

        t = Target(user=self.user, target_type=TargetType.standard, location=l)
        t.save()

        response = self.client.put(targets_id_url(args=[t.pk]),
                                   data="latitude=76",
                                   content_type='multipart/form-data')
        self.assertEqual(400, response.status_code)
示例#15
0
    def test_put_clear_type(self):
        """PUT type may not be cleared."""
        t = Target(user=self.user,
                   target_type=TargetType.standard,
                   shape=Shape.square)
        t.save()

        data = {'type': None}

        response = self.client.put(targets_id_url(args=[t.pk]),
                                   data=json.dumps(data))
        self.assertEqual(400, response.status_code)
示例#16
0
    def test_last_modified_time(self):
        """Last modified time is set on creation and changes every update."""
        t = Target(user=self.user, target_type=TargetType.standard)
        t.save()

        orig = t.last_modified_time
        self.assertIsNotNone(orig)

        t.alphanumeric = 'A'
        t.save()

        self.assertGreater(t.last_modified_time, orig)
示例#17
0
    def test_creation_time(self):
        """Creation time is set on creation and doesn't change on update."""
        t = Target(user=self.user, target_type=TargetType.standard)
        t.save()

        orig = t.creation_time
        self.assertIsNotNone(orig)

        t.alphanumeric = 'A'
        t.save()

        self.assertEqual(orig, t.creation_time)
示例#18
0
    def test_creation_time(self):
        """Creation time is set on creation and doesn't change on update."""
        t = Target(user=self.user, target_type=TargetType.standard)
        t.save()

        orig = t.creation_time
        self.assertIsNotNone(orig)

        t.alphanumeric = 'A'
        t.save()

        self.assertEqual(orig, t.creation_time)
示例#19
0
    def test_get_after_delete_own(self):
        """Test GETting a target after DELETE."""
        t = Target(user=self.user, target_type=TargetType.standard)
        t.save()

        pk = t.pk

        response = self.client.delete(targets_id_url(args=[pk]))
        self.assertEqual(200, response.status_code)

        response = self.client.get(targets_id_url(args=[pk]))
        self.assertEqual(404, response.status_code)
示例#20
0
    def test_get_after_delete_own(self):
        """Test GETting a target after DELETE."""
        t = Target(user=self.user, target_type=TargetType.standard)
        t.save()

        pk = t.pk

        response = self.client.delete(targets_id_url(args=[pk]))
        self.assertEqual(200, response.status_code)

        response = self.client.get(targets_id_url(args=[pk]))
        self.assertEqual(404, response.status_code)
示例#21
0
    def test_put_clear_type(self):
        """PUT type may not be cleared."""
        t = Target(user=self.user,
                   target_type=TargetType.standard,
                   shape=Shape.square)
        t.save()

        data = {'type': None}

        response = self.client.put(targets_id_url(args=[t.pk]),
                                   data=json.dumps(data))
        self.assertEqual(400, response.status_code)
示例#22
0
    def test_last_modified_time(self):
        """Last modified time is set on creation and changes every update."""
        t = Target(user=self.user, target_type=TargetType.standard)
        t.save()

        orig = t.last_modified_time
        self.assertIsNotNone(orig)

        t.alphanumeric = 'A'
        t.save()

        self.assertGreater(t.last_modified_time, orig)
示例#23
0
    def test_put_partial_clear_location(self):
        """PUT can't clear location with only one of lat/lon."""
        l = GpsPosition(latitude=38, longitude=-76)
        l.save()

        t = Target(user=self.user, target_type=TargetType.standard, location=l)
        t.save()

        data = {'latitude': None}

        response = self.client.put(targets_id_url(args=[t.pk]),
                                   data=json.dumps(data))
        self.assertEqual(400, response.status_code)
示例#24
0
    def test_put_partial_clear_location(self):
        """PUT can't clear location with only one of lat/lon."""
        l = GpsPosition(latitude=38, longitude=-76)
        l.save()

        t = Target(user=self.user, target_type=TargetType.standard, location=l)
        t.save()

        data = {'latitude': None}

        response = self.client.put(targets_id_url(args=[t.pk]),
                                   data=json.dumps(data))
        self.assertEqual(400, response.status_code)
示例#25
0
    def test_put_invalid_json(self):
        """PUT request body must be valid JSON."""
        l = GpsPosition(latitude=38, longitude=-76)
        l.save()

        t = Target(user=self.user, target_type=TargetType.standard, location=l)
        t.save()

        response = self.client.put(
            targets_id_url(args=[t.pk]),
            data="latitude=76",
            content_type='multipart/form-data')
        self.assertEqual(400, response.status_code)
示例#26
0
    def test_put_change_autonomous(self):
        """Change autonomous with PUT"""
        t = Target(user=self.user, target_type=TargetType.standard)
        t.save()

        data = {'autonomous': True}

        response = self.client.put(targets_id_url(args=[t.pk]),
                                   data=json.dumps(data))
        self.assertEqual(200, response.status_code)

        t.refresh_from_db()
        self.assertEqual(True, t.autonomous)
示例#27
0
    def test_delete_own(self):
        """Test DELETEing a target owned by the correct user."""
        t = Target(user=self.user, target_type=TargetType.standard)
        t.save()

        pk = t.pk

        self.assertTrue(Target.objects.get(pk=pk))

        response = self.client.delete(targets_id_url(args=[pk]))
        self.assertEqual(200, response.status_code)

        with self.assertRaises(Target.DoesNotExist):
            Target.objects.get(pk=pk)
示例#28
0
    def test_put_location(self):
        """PUT new location"""
        t = Target(user=self.user, target_type=TargetType.standard)
        t.save()

        data = {'latitude': 38, 'longitude': -76}

        response = self.client.put(targets_id_url(args=[t.pk]),
                                   data=json.dumps(data))
        self.assertEqual(200, response.status_code)

        t.refresh_from_db()
        self.assertEqual(38, t.location.latitude)
        self.assertEqual(-76, t.location.longitude)
示例#29
0
    def test_put_location(self):
        """PUT new location"""
        t = Target(user=self.user, target_type=TargetType.standard)
        t.save()

        data = {'latitude': 38, 'longitude': -76}

        response = self.client.put(targets_id_url(args=[t.pk]),
                                   data=json.dumps(data))
        self.assertEqual(200, response.status_code)

        t.refresh_from_db()
        self.assertEqual(38, t.location.latitude)
        self.assertEqual(-76, t.location.longitude)
示例#30
0
    def test_delete_own(self):
        """Test DELETEing a target owned by the correct user."""
        t = Target(user=self.user, target_type=TargetType.standard)
        t.save()

        pk = t.pk

        self.assertTrue(Target.objects.get(pk=pk))

        response = self.client.delete(targets_id_url(args=[pk]))
        self.assertEqual(200, response.status_code)

        with self.assertRaises(Target.DoesNotExist):
            Target.objects.get(pk=pk)
示例#31
0
    def test_get_targets(self):
        """We get back the targets we own."""
        t1 = Target(user=self.user, target_type=TargetType.standard)
        t1.save()

        t2 = Target(user=self.user, target_type=TargetType.qrc)
        t2.save()

        response = self.client.get(targets_url)
        self.assertEqual(200, response.status_code)

        d = json.loads(response.content)

        self.assertItemsEqual([t1.json(), t2.json()], d)
示例#32
0
    def test_put_change_autonomous(self):
        """Change autonomous with PUT"""
        t = Target(user=self.user, target_type=TargetType.standard)
        t.save()

        data = {'autonomous': True}

        response = self.client.put(
            targets_id_url(args=[t.pk]),
            data=json.dumps(data))
        self.assertEqual(200, response.status_code)

        t.refresh_from_db()
        self.assertEqual(True, t.autonomous)
示例#33
0
    def test_get_targets(self):
        """We get back the targets we own."""
        t1 = Target(user=self.user, target_type=TargetType.standard)
        t1.save()

        t2 = Target(user=self.user, target_type=TargetType.qrc)
        t2.save()

        response = self.client.get(targets_url)
        self.assertEqual(200, response.status_code)

        d = json.loads(response.content)

        self.assertItemsEqual([t1.json(), t2.json()], d)
示例#34
0
    def test_put_clear_shape(self):
        """PUT clear a field with None."""
        t = Target(user=self.user,
                   target_type=TargetType.standard,
                   shape=Shape.square)
        t.save()

        data = {'shape': None}

        response = self.client.put(targets_id_url(args=[t.pk]),
                                   data=json.dumps(data))
        self.assertEqual(200, response.status_code)

        t.refresh_from_db()
        self.assertEqual(None, t.shape)
示例#35
0
    def test_get_noneditable_without_thumbnail_targets(self):
        """Test GET when there are non-editable targets without thumbnail."""
        MissionClockEvent(user=self.team,
                          team_on_clock=True,
                          team_on_timeout=False).save()
        MissionClockEvent(user=self.team,
                          team_on_clock=False,
                          team_on_timeout=False).save()
        target = Target(user=self.team, target_type=TargetType.qrc)
        target.save()

        response = self.client.get(targets_review_url)
        self.assertEqual(200, response.status_code)
        data = json.loads(response.content)
        self.assertEqual(0, len(data))
示例#36
0
    def test_put_clear_shape(self):
        """PUT clear a field with None."""
        t = Target(user=self.user,
                   target_type=TargetType.standard,
                   shape=Shape.square)
        t.save()

        data = {'shape': None}

        response = self.client.put(targets_id_url(args=[t.pk]),
                                   data=json.dumps(data))
        self.assertEqual(200, response.status_code)

        t.refresh_from_db()
        self.assertEqual(None, t.shape)
示例#37
0
    def test_put_clear_location(self):
        """PUT clear location by clearing lat and lon."""
        l = GpsPosition(latitude=38, longitude=-76)
        l.save()

        t = Target(user=self.user, target_type=TargetType.standard, location=l)
        t.save()

        data = {'latitude': None, 'longitude': None}

        response = self.client.put(targets_id_url(args=[t.pk]),
                                   data=json.dumps(data))
        self.assertEqual(200, response.status_code)

        t.refresh_from_db()
        self.assertEqual(None, t.location)
示例#38
0
    def test_put_append(self):
        """PUT sets a new field that wasn't set before."""
        t = Target(user=self.user, target_type=TargetType.standard)
        t.save()

        data = {'description': 'Hello'}

        response = self.client.put(targets_id_url(args=[t.pk]),
                                   data=json.dumps(data))
        self.assertEqual(200, response.status_code)

        t.refresh_from_db()
        self.assertEqual('Hello', t.description)

        # Response also matches
        self.assertEqual(t.json(), json.loads(response.content))
示例#39
0
    def test_put_clear_location(self):
        """PUT clear location by clearing lat and lon."""
        l = GpsPosition(latitude=38, longitude=-76)
        l.save()

        t = Target(user=self.user, target_type=TargetType.standard, location=l)
        t.save()

        data = {'latitude': None, 'longitude': None}

        response = self.client.put(targets_id_url(args=[t.pk]),
                                   data=json.dumps(data))
        self.assertEqual(200, response.status_code)

        t.refresh_from_db()
        self.assertEqual(None, t.location)
示例#40
0
    def test_put_append(self):
        """PUT sets a new field that wasn't set before."""
        t = Target(user=self.user, target_type=TargetType.standard)
        t.save()

        data = {'description': 'Hello'}

        response = self.client.put(targets_id_url(args=[t.pk]),
                                   data=json.dumps(data))
        self.assertEqual(200, response.status_code)

        t.refresh_from_db()
        self.assertEqual('Hello', t.description)

        # Response also matches
        self.assertEqual(t.json(), json.loads(response.content))
示例#41
0
    def test_not_others(self):
        """We don't get targets owned by other users."""
        user2 = User.objects.create_user('testuser2', '*****@*****.**',
                                         'testpass')

        mine = Target(user=self.user, target_type=TargetType.standard)
        mine.save()

        theirs = Target(user=user2, target_type=TargetType.qrc)
        theirs.save()

        response = self.client.get(targets_url)
        self.assertEqual(200, response.status_code)

        d = json.loads(response.content)

        self.assertItemsEqual([mine.json()], d)
示例#42
0
    def test_not_others(self):
        """We don't get targets owned by other users."""
        user2 = User.objects.create_user('testuser2', '*****@*****.**',
                                         'testpass')

        mine = Target(user=self.user, target_type=TargetType.standard)
        mine.save()

        theirs = Target(user=user2, target_type=TargetType.qrc)
        theirs.save()

        response = self.client.get(targets_url)
        self.assertEqual(200, response.status_code)

        d = json.loads(response.content)

        self.assertItemsEqual([mine.json()], d)
示例#43
0
文件: targets.py 项目: APTRG/interop
    def post(self, request):
        try:
            data = json.loads(request.body)
        except ValueError:
            return HttpResponseBadRequest('Request body is not valid JSON.')

        # Target type is required.
        if 'type' not in data:
            return HttpResponseBadRequest('Target type required.')

        latitude = data.get('latitude')
        longitude = data.get('longitude')

        # Require zero or both of latitude and longitude.
        if (latitude is not None and longitude is None) or \
            (latitude is None and longitude is not None):
            return HttpResponseBadRequest(
                'Either none or both of latitude and longitude required.')

        try:
            data = normalize_data(data)
        except ValueError as e:
            return HttpResponseBadRequest(str(e))

        l = None
        if latitude is not None and longitude is not None:
            l = GpsPosition(latitude=data['latitude'],
                            longitude=data['longitude'])
            l.save()

        # Use the dictionary get() method to default non-existent values to None.
        t = Target(user=request.user,
                   target_type=data['type'],
                   location=l,
                   orientation=data.get('orientation'),
                   shape=data.get('shape'),
                   background_color=data.get('background_color'),
                   alphanumeric=data.get('alphanumeric', ''),
                   alphanumeric_color=data.get('alphanumeric_color'),
                   description=data.get('description', ''),
                   autonomous=data.get('autonomous', False))
        t.save()

        return JsonResponse(
            t.json(is_superuser=request.user.is_superuser),
            status=201)
示例#44
0
    def test_put_review(self):
        """Test PUT review is saved."""
        target = Target(user=self.team, target_type=TargetType.qrc)
        target.save()

        response = self.client.put(
            targets_review_id_url(args=[target.pk]),
            data=json.dumps({'thumbnail_approved': False}))
        self.assertEqual(200, response.status_code)
        data = json.loads(response.content)
        self.assertIn('id', data)
        self.assertEqual(target.pk, data['id'])
        self.assertIn('thumbnail_approved', data)
        self.assertFalse(data['thumbnail_approved'])

        target.refresh_from_db()
        self.assertFalse(target.thumbnail_approved)
示例#45
0
    def post(self, request):
        try:
            data = json.loads(request.body)
        except ValueError:
            return HttpResponseBadRequest('Request body is not valid JSON.')

        # Target type is required.
        if 'type' not in data:
            return HttpResponseBadRequest('Target type required.')

        latitude = data.get('latitude')
        longitude = data.get('longitude')

        # Require zero or both of latitude and longitude.
        if (latitude is not None and longitude is None) or \
            (latitude is None and longitude is not None):
            return HttpResponseBadRequest(
                'Either none or both of latitude and longitude required.')

        try:
            data = normalize_data(data)
        except ValueError as e:
            return HttpResponseBadRequest(str(e))

        l = None
        if latitude is not None and longitude is not None:
            l = GpsPosition(latitude=data['latitude'],
                            longitude=data['longitude'])
            l.save()

        # Use the dictionary get() method to default non-existent values to None.
        t = Target(user=request.user,
                   target_type=data['type'],
                   location=l,
                   orientation=data.get('orientation'),
                   shape=data.get('shape'),
                   background_color=data.get('background_color'),
                   alphanumeric=data.get('alphanumeric', ''),
                   alphanumeric_color=data.get('alphanumeric_color'),
                   description=data.get('description', ''),
                   autonomous=data.get('autonomous', False))
        t.save()

        return JsonResponse(t.json(is_superuser=request.user.is_superuser),
                            status=201)
示例#46
0
    def test_minimal_json(self):
        """Test target JSON with minimal data."""
        t = Target(user=self.user, target_type=TargetType.standard)
        t.save()

        d = t.json()

        self.assertIn('id', d)
        self.assertEqual(self.user.pk, d['user'])
        self.assertEqual('standard', d['type'])
        self.assertEqual(None, d['latitude'])
        self.assertEqual(None, d['longitude'])
        self.assertEqual(None, d['orientation'])
        self.assertEqual(None, d['shape'])
        self.assertEqual(None, d['background_color'])
        self.assertEqual(None, d['alphanumeric'])
        self.assertEqual(None, d['alphanumeric_color'])
        self.assertEqual(None, d['description'])
示例#47
0
    def test_put_update_location(self):
        """PUT updating location only requires one of lat/lon."""
        l = GpsPosition(latitude=38, longitude=-76)
        l.save()

        t = Target(user=self.user, target_type=TargetType.standard, location=l)
        t.save()

        data = {'latitude': 39}

        response = self.client.put(targets_id_url(args=[t.pk]),
                                   data=json.dumps(data))
        self.assertEqual(200, response.status_code)

        t.refresh_from_db()
        t.location.refresh_from_db()
        self.assertEqual(39, t.location.latitude)
        self.assertEqual(-76, t.location.longitude)
示例#48
0
    def test_put_update_location(self):
        """PUT updating location only requires one of lat/lon."""
        l = GpsPosition(latitude=38, longitude=-76)
        l.save()

        t = Target(user=self.user, target_type=TargetType.standard, location=l)
        t.save()

        data = {'latitude': 39}

        response = self.client.put(targets_id_url(args=[t.pk]),
                                   data=json.dumps(data))
        self.assertEqual(200, response.status_code)

        t.refresh_from_db()
        t.location.refresh_from_db()
        self.assertEqual(39, t.location.latitude)
        self.assertEqual(-76, t.location.longitude)
示例#49
0
    def test_json(self):
        """Test target JSON."""
        l = GpsPosition(latitude=38, longitude=-76)
        l.save()

        t = Target(
            user=self.user,
            target_type=TargetType.standard,
            location=l,
            orientation=Orientation.s,
            shape=Shape.square,
            background_color=Color.white,
            alphanumeric="ABC",
            alphanumeric_color=Color.black,
            description="Test target",
            autonomous=True,
        )
        t.save()

        d = t.json()

        self.assertIn("id", d)
        self.assertEqual(self.user.pk, d["user"])
        self.assertEqual("standard", d["type"])
        self.assertEqual(38, d["latitude"])
        self.assertEqual(-76, d["longitude"])
        self.assertEqual("s", d["orientation"])
        self.assertEqual("square", d["shape"])
        self.assertEqual("white", d["background_color"])
        self.assertEqual("ABC", d["alphanumeric"])
        self.assertEqual("black", d["alphanumeric_color"])
        self.assertEqual("Test target", d["description"])
        self.assertEqual(True, d["autonomous"])
        self.assertNotIn("thumbnail_approved", d)

        d = t.json(is_superuser=True)
        self.assertIn("thumbnail_approved", d)

        t.thumbnail_approved = True
        t.save()
        d = t.json(is_superuser=True)
        self.assertEqual(None, d["thumbnail"])
        self.assertEqual(True, d["thumbnail_approved"])
示例#50
0
    def test_minimal_json(self):
        """Test target JSON with minimal data."""
        t = Target(user=self.user, target_type=TargetType.standard)
        t.save()

        d = t.json()

        self.assertIn("id", d)
        self.assertEqual(self.user.pk, d["user"])
        self.assertEqual("standard", d["type"])
        self.assertEqual(None, d["latitude"])
        self.assertEqual(None, d["longitude"])
        self.assertEqual(None, d["orientation"])
        self.assertEqual(None, d["shape"])
        self.assertEqual(None, d["background_color"])
        self.assertEqual(None, d["alphanumeric"])
        self.assertEqual(None, d["alphanumeric_color"])
        self.assertEqual(None, d["description"])
        self.assertEqual(False, d["autonomous"])
示例#51
0
    def test_minimal_json(self):
        """Test target JSON with minimal data."""
        t = Target(user=self.user, target_type=TargetType.standard)
        t.save()

        d = t.json()

        self.assertIn('id', d)
        self.assertEqual(self.user.pk, d['user'])
        self.assertEqual('standard', d['type'])
        self.assertEqual(None, d['latitude'])
        self.assertEqual(None, d['longitude'])
        self.assertEqual(None, d['orientation'])
        self.assertEqual(None, d['shape'])
        self.assertEqual(None, d['background_color'])
        self.assertEqual(None, d['alphanumeric'])
        self.assertEqual(None, d['alphanumeric_color'])
        self.assertEqual(None, d['description'])
        self.assertEqual(False, d['autonomous'])
示例#52
0
    def test_valid(self):
        """Test creating a valid target."""
        with open(os.path.join(settings.BASE_DIR,
                               'auvsi_suas/fixtures/testdata/S.jpg')) as f:
            thumb = SimpleUploadedFile('thumb.jpg', f.read())

        l = GpsPosition(latitude=38, longitude=-76)
        l.save()

        t = Target(user=self.user,
                   target_type=TargetType.standard,
                   location=l,
                   orientation=Orientation.s,
                   shape=Shape.square,
                   background_color=Color.white,
                   alphanumeric='ABC',
                   alphanumeric_color=Color.black,
                   description='Test target',
                   thumbnail=thumb)
        t.save()
示例#53
0
    def test_valid(self):
        """Test creating a valid target."""
        with open(os.path.join(settings.BASE_DIR,
                               'auvsi_suas/fixtures/testdata/S.jpg')) as f:
            thumb = SimpleUploadedFile('thumb.jpg', f.read())

        l = GpsPosition(latitude=38, longitude=-76)
        l.save()

        t = Target(user=self.user,
                   target_type=TargetType.standard,
                   location=l,
                   orientation=Orientation.s,
                   shape=Shape.square,
                   background_color=Color.white,
                   alphanumeric='ABC',
                   alphanumeric_color=Color.black,
                   description='Test target',
                   thumbnail=thumb)
        t.save()
示例#54
0
    def test_get_noneditable_targets(self):
        """Test GET when there are non-editable targets."""
        MissionClockEvent(user=self.team,
                          team_on_clock=True,
                          team_on_timeout=False).save()
        MissionClockEvent(user=self.team,
                          team_on_clock=False,
                          team_on_timeout=False).save()
        target = Target(user=self.team, target_type=TargetType.qrc)
        target.save()

        with open(test_image('A.jpg')) as f:
            target.thumbnail.save('%d.%s' % (target.pk, 'jpg'), ImageFile(f))
        target.save()

        response = self.client.get(targets_review_url)
        self.assertEqual(200, response.status_code)
        data = json.loads(response.content)
        self.assertEqual(1, len(data))
        self.assertIn('type', data[0])
        self.assertEqual('qrc', data[0]['type'])
示例#55
0
    def test_delete_thumb(self):
        """Test DELETEing a target with thumbnail."""
        t = Target(user=self.user, target_type=TargetType.standard)
        t.save()

        pk = t.pk

        with open(test_image("A.jpg")) as f:
            response = self.client.post(targets_id_image_url(args=[pk]),
                                        data=f.read(),
                                        content_type="image/jpeg")
            self.assertEqual(200, response.status_code)

        t.refresh_from_db()
        thumb = t.thumbnail.name
        self.assertTrue(os.path.exists(absolute_media_path(thumb)))

        response = self.client.delete(targets_id_url(args=[pk]))
        self.assertEqual(200, response.status_code)

        self.assertFalse(os.path.exists(absolute_media_path(thumb)))
示例#56
0
 def test_null_fields(self):
     """Only user and target type."""
     t = Target(user=self.user, target_type=TargetType.standard)
     t.save()