def test_put_clear_shape(self): """PUT clear a field with None.""" l = GpsPosition(latitude=38, longitude=-76) l.save() t = Odlc(user=self.user, odlc_type=OdlcType.standard, location=l, orientation=Orientation.s, shape=Shape.square, background_color=Color.white, alphanumeric='ABC', alphanumeric_color=Color.black, description='Test odlc') t.save() updated = { 'type': 'STANDARD', } response = self.client.put(odlcs_id_url(args=[t.pk]), data=json.dumps(updated)) self.assertEqual(200, response.status_code) t.refresh_from_db() self.assertEqual(self.user, t.user) self.assertEqual(OdlcType.standard, t.odlc_type) self.assertIsNone(t.location) self.assertIsNone(t.orientation) self.assertIsNone(t.shape) self.assertIsNone(t.background_color) self.assertEqual('', t.alphanumeric) self.assertIsNone(t.alphanumeric_color) self.assertEqual('', t.description)
def test_put_review(self): """Test PUT review is saved.""" odlc = Odlc( mission=self.mission, user=self.team, odlc_type=interop_api_pb2.Odlc.STANDARD) odlc.save() response = self.client.put( odlcs_review_id_url(args=[odlc.pk]), data=json.dumps({ 'thumbnailApproved': True, 'descriptionApproved': True, })) self.assertEqual(200, response.status_code) data = json.loads(response.content) self.assertIn('odlc', data) self.assertIn('id', data['odlc']) self.assertEqual(odlc.pk, data['odlc']['id']) self.assertIn('thumbnailApproved', data) self.assertTrue(data['thumbnailApproved']) self.assertTrue(data['descriptionApproved']) odlc.refresh_from_db() self.assertTrue(odlc.thumbnail_approved) self.assertTrue(odlc.description_approved)
def test_put_one(self): """PUT update one field without affecting others.""" l = GpsPosition(latitude=38, longitude=-76) l.save() t = Odlc( user=self.user, odlc_type=OdlcType.standard, location=l, orientation=Orientation.s, shape=Shape.square, background_color=Color.white, alphanumeric='ABC', alphanumeric_color=Color.black, description='Test odlc') t.save() data = {'shape': 'circle'} response = self.client.put( odlcs_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(OdlcType.standard, t.odlc_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 odlc', t.description)
def test_delete_thumb(self): """Test DELETEing a odlc with thumbnail.""" t = Odlc( mission=self.mission, user=self.user, odlc_type=interop_api_pb2.Odlc.STANDARD) t.save() pk = t.pk with open(test_image("A.jpg"), 'rb') as f: response = self.client.post( odlcs_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.path self.assertTrue(os.path.exists(thumb)) response = self.client.delete(odlcs_id_url(args=[pk])) self.assertEqual(200, response.status_code) self.assertFalse(os.path.exists(thumb))
def test_put_append(self): """PUT sets a new field that wasn't set before.""" t = Odlc(user=self.user, odlc_type=OdlcType.standard) t.save() data = {'type': 'STANDARD', 'description': 'Hello'} response = self.client.put(odlcs_id_url(args=[t.pk]), data=json.dumps(data)) self.assertEqual(200, response.status_code) t.refresh_from_db() self.assertEqual('Hello', t.description)
def test_put_change_autonomous(self): """Change autonomous with PUT""" t = Odlc(user=self.user, odlc_type=OdlcType.standard) t.save() data = {'autonomous': True} response = self.client.put( odlcs_id_url(args=[t.pk]), data=json.dumps(data)) self.assertEqual(200, response.status_code) t.refresh_from_db() self.assertEqual(True, t.autonomous)
def test_put_location(self): """PUT new location""" t = Odlc(user=self.user, odlc_type=OdlcType.standard) t.save() data = {'latitude': 38, 'longitude': -76} response = self.client.put( odlcs_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)
def test_put_clear_shape(self): """PUT clear a field with None.""" t = Odlc( user=self.user, odlc_type=OdlcType.standard, shape=Shape.square) t.save() data = {'shape': None} response = self.client.put( odlcs_id_url(args=[t.pk]), data=json.dumps(data)) self.assertEqual(200, response.status_code) t.refresh_from_db() self.assertEqual(None, t.shape)
def test_put_updates_fields(self): """PUT updates fields.""" l = GpsPosition(latitude=38, longitude=-76) l.save() t = Odlc( mission=self.mission, user=self.user, odlc_type=interop_api_pb2.Odlc.STANDARD, location=l, orientation=interop_api_pb2.Odlc.S, shape=interop_api_pb2.Odlc.SQUARE, background_color=interop_api_pb2.Odlc.WHITE, alphanumeric='ABC', alphanumeric_color=interop_api_pb2.Odlc.BLACK, description='Test odlc') t.save() updated = { 'mission': self.mission.pk, 'type': 'OFF_AXIS', 'latitude': 39, 'longitude': -77, 'orientation': 'N', 'shape': 'CIRCLE', 'shapeColor': 'BLACK', 'alphanumeric': 'A', 'alphanumericColor': 'GREEN', 'description': 'Best odlc', 'autonomous': False, } response = self.client.put( odlcs_id_url(args=[t.pk]), data=json.dumps(updated)) self.assertEqual(200, response.status_code) t.refresh_from_db() t.location.refresh_from_db() self.assertEqual(self.user, t.user) self.assertEqual(interop_api_pb2.Odlc.OFF_AXIS, t.odlc_type) self.assertEqual(39, t.location.latitude) self.assertEqual(-77, t.location.longitude) self.assertEqual(interop_api_pb2.Odlc.N, t.orientation) self.assertEqual(interop_api_pb2.Odlc.CIRCLE, t.shape) self.assertEqual(interop_api_pb2.Odlc.BLACK, t.background_color) self.assertEqual('A', t.alphanumeric) self.assertEqual(interop_api_pb2.Odlc.GREEN, t.alphanumeric_color) self.assertEqual('Best odlc', t.description)
def test_put_clear_location(self): """PUT clear location by clearing lat and lon.""" l = GpsPosition(latitude=38, longitude=-76) l.save() t = Odlc(user=self.user, odlc_type=OdlcType.standard, location=l) t.save() data = {'latitude': None, 'longitude': None} response = self.client.put( odlcs_id_url(args=[t.pk]), data=json.dumps(data)) self.assertEqual(200, response.status_code) t.refresh_from_db() self.assertEqual(None, t.location)
def test_put_invalidates_description_review(self): """Test that update invalidates description field.""" t = Odlc( user=self.user, odlc_type=OdlcType.emergent, description='Hello') t.description_approved = True t.save() data = {'description': 'World'} response = self.client.put( odlcs_id_url(args=[t.pk]), data=json.dumps(data)) self.assertEqual(200, response.status_code) t.refresh_from_db() self.assertEqual('World', t.description) self.assertIsNone(t.description_approved)
def test_put_changes_last_modified(self): """PUT sets a new field that wasn't set before.""" t = Odlc(user=self.user, odlc_type=OdlcType.standard) t.save() orig_last_modified = t.last_modified_time data = {'description': 'Hello'} response = self.client.put( odlcs_id_url(args=[t.pk]), data=json.dumps(data)) self.assertEqual(200, response.status_code) t.refresh_from_db() self.assertNotEqual(orig_last_modified, t.last_modified_time) # Response also matches self.assertEqual(t.json(), json.loads(response.content))
def test_put_updates_fields(self): """PUT updates fields.""" l = GpsPosition(latitude=38, longitude=-76) l.save() t = Odlc(user=self.user, odlc_type=OdlcType.standard, location=l, orientation=Orientation.s, shape=Shape.square, background_color=Color.white, alphanumeric='ABC', alphanumeric_color=Color.black, description='Test odlc') t.save() updated = { 'type': 'OFF_AXIS', 'latitude': 39, 'longitude': -77, 'orientation': 'N', 'shape': 'CIRCLE', 'shapeColor': 'BLACK', 'alphanumeric': 'A', 'alphanumericColor': 'GREEN', 'description': 'Best odlc', 'autonomous': False, } response = self.client.put(odlcs_id_url(args=[t.pk]), data=json.dumps(updated)) self.assertEqual(200, response.status_code) t.refresh_from_db() t.location.refresh_from_db() self.assertEqual(self.user, t.user) self.assertEqual(OdlcType.off_axis, t.odlc_type) self.assertEqual(39, t.location.latitude) self.assertEqual(-77, t.location.longitude) self.assertEqual(Orientation.n, t.orientation) self.assertEqual(Shape.circle, t.shape) self.assertEqual(Color.black, t.background_color) self.assertEqual('A', t.alphanumeric) self.assertEqual(Color.green, t.alphanumeric_color) self.assertEqual('Best odlc', t.description)
def test_put_superuser_change_actionable_override(self): """Admin user can update actionable_override flag.""" # Login as superuser. superuser = User.objects.create_superuser( 'testsuperuser', '*****@*****.**', 'testsuperpass') self.client.force_login(superuser) t = Odlc(user=self.user, odlc_type=OdlcType.standard) t.save() data = {'actionable_override': True} response = self.client.put( odlcs_id_url(args=[t.pk]), data=json.dumps(data)) self.assertEqual(200, response.status_code) t.refresh_from_db() self.assertEqual(True, t.actionable_override)
def test_put_update_location(self): """PUT updating location only requires one of lat/lon.""" l = GpsPosition(latitude=38, longitude=-76) l.save() t = Odlc(user=self.user, odlc_type=OdlcType.standard, location=l) t.save() data = {'latitude': 39} response = self.client.put( odlcs_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)
def test_put_superuser_doesnt_change_modified(self): """Admin user can update without modifying last updated time.""" # Login as superuser. superuser = User.objects.create_superuser( 'testsuperuser', '*****@*****.**', 'testsuperpass') self.client.force_login(superuser) t = Odlc(user=self.user, odlc_type=OdlcType.standard) t.save() orig_last_modified = t.last_modified_time data = {'thumbnail_approved': True} response = self.client.put( odlcs_id_url(args=[t.pk]), data=json.dumps(data)) self.assertEqual(200, response.status_code) t.refresh_from_db() self.assertEqual(orig_last_modified, t.last_modified_time)
def test_put_changes_last_modified(self): """PUT sets a new field that wasn't set before.""" t = Odlc(mission=self.mission, user=self.user, odlc_type=interop_api_pb2.Odlc.STANDARD) t.save() orig_last_modified = t.last_modified_time data = { 'mission': self.mission.pk, 'type': 'STANDARD', 'description': 'Hello' } response = self.client.put(odlcs_id_url(args=[t.pk]), data=json.dumps(data)) self.assertEqual(200, response.status_code) t.refresh_from_db() self.assertNotEqual(orig_last_modified, t.last_modified_time)
def test_put_clear_shape(self): """PUT clear a field with None.""" l = GpsPosition(latitude=38, longitude=-76) l.save() t = Odlc( mission=self.mission, user=self.user, odlc_type=interop_api_pb2.Odlc.STANDARD, location=l, orientation=interop_api_pb2.Odlc.S, shape=interop_api_pb2.Odlc.SQUARE, background_color=interop_api_pb2.Odlc.WHITE, alphanumeric='ABC', alphanumeric_color=interop_api_pb2.Odlc.BLACK, description='Test odlc') t.save() updated = { 'mission': self.mission.pk, 'type': 'STANDARD', } response = self.client.put( odlcs_id_url(args=[t.pk]), data=json.dumps(updated)) self.assertEqual(200, response.status_code) t.refresh_from_db() self.assertEqual(self.user, t.user) self.assertEqual(interop_api_pb2.Odlc.STANDARD, t.odlc_type) self.assertIsNone(t.location) self.assertIsNone(t.orientation) self.assertIsNone(t.shape) self.assertIsNone(t.background_color) self.assertEqual('', t.alphanumeric) self.assertIsNone(t.alphanumeric_color) self.assertEqual('', t.description)