def test_returns_bikes(self): BikeFactory.create_batch(10) client = APIClient() client.force_authenticate(user=self.user, token='blah') result = client.get('/api/v1/bikes/') self.assertEqual(result.status_code, status.HTTP_200_OK) self.assertEqual(len(result.data), 10)
def test_validate_assessed_error(self): data = { "colour": "black", "make": "Miyata", "serial_number": "12345676", "source": Bike.COS_BIKE_DIVERSION_PILOT, "size": Bike.SMALL, } BikeFactory.create(**data) client = APIClient() client.force_authenticate(user=self.user, token='blah') result = client.get(f'/api/v1/bikes/1/validate/?transition=assessed') self.assertEqual(result.status_code, status.HTTP_400_BAD_REQUEST) self.assertTrue('price' in result.data['field_errors'].keys())
def test_update_partial_state(self): bike = BikeFactory.create() client = APIClient() client.force_authenticate(user=self.user, token='blah') data = {'state': BikeState.CLAIMED} result = client.put(f'/api/v1/bikes/{bike.id}/', data=data) self.assertEqual(result.status_code, status.HTTP_400_BAD_REQUEST)
def test_validate_available_stolen(self): data = { "colour": "black", "make": "Miyata", "source": Bike.COS_BIKE_DIVERSION_PILOT, "size": Bike.SMALL, "cpic_searched_at": timezone.now(), "serial_number": '123', "stolen": True, "state": BikeState.RECEIVED } BikeFactory.create(**data) client = APIClient() client.force_authenticate(user=self.user, token='blah') result = client.get(f'/api/v1/bikes/1/validate/?transition=available') self.assertEqual(result.status_code, status.HTTP_400_BAD_REQUEST) self.assertTrue(result.data['form_errors'])
def test_update_partial_created_at(self): bike = BikeFactory.create() client = APIClient() client.force_authenticate(user=self.user, token='blah') data = { 'state': BikeState.ASSESSED, 'created_at': timezone.now().isoformat() } result = client.put(f'/api/v1/bikes/{bike.id}/', data=data) self.assertEqual(result.status_code, status.HTTP_400_BAD_REQUEST)
def test_validate_available_claimed_worked_on_four_weeks_ago(self): member = mommy.make(Member) data = { "colour": "black", "make": "Miyata", "source": Bike.COS_BIKE_DIVERSION_PILOT, "size": Bike.SMALL, "cpic_searched_at": timezone.now(), "serial_number": '123', "stolen": False, "claimed_by": member, "last_worked_on": timezone.now() - timedelta(weeks=4, seconds=1.0), "state": BikeState.CLAIMED } BikeFactory.create(**data) client = APIClient() client.force_authenticate(user=self.user, token='blah') result = client.get(f'/api/v1/bikes/1/validate/?transition=available') self.assertEqual(result.status_code, status.HTTP_204_NO_CONTENT)
def test_transfer_to_police_transition(self): data = { "colour": "black", "make": "Miyata", "serial_number": "12345676", "source": Bike.COS_BIKE_DIVERSION_PILOT, "donated_by": "Greg", "donated_at": timezone.make_aware(timezone.datetime(2017, 1, 1)), "size": Bike.SMALL, "price": '68.00', "state": BikeState.ASSESSED, "cpic_searched_at": timezone.now(), "stolen": True } bike = BikeFactory.create(**data) client = APIClient() client.force_authenticate(user=self.user, token='blah') result = client.put(f'/api/v1/bikes/{bike.id}/stolen/') self.assertEqual(result.status_code, status.HTTP_200_OK)