def test_no_integer_pk(self): """Ensure we fail with 404 when person PK is string, not integer.""" tests = [ (self.factory.get('/'), 'alpha'), (self.factory.post('/', {'person': 'alpha'}), None), ] for request, person_id in tests: with self.subTest(method=request.method): with self.assertRaises(Http404): assign(request, self.event, person_id=person_id) # just reset the link, for safety sake self.event.assigned_to = None self.event.save()
def test_no_integer_pk(self): """Ensure we fail with 404 when person PK is string, not integer.""" tests = [ (self.factory.get('/'), 'alpha'), (self.factory.post('/', {'person': 'alpha'}), None), ] for request, person_id in tests: with self.subTest(method=request.method): with self.assertRaises(Http404): assign(request, self.event, person_id=person_id) # just reset the link, for safety sake self.event.assigned_to = None self.event.save()
def test_assigning(self): """Ensure that with assignment is set correctly.""" first_person = Person.objects.first() tests = [ (self.factory.get('/'), first_person.pk), (self.factory.post('/', {'person': first_person.pk}), None), ] for request, person_id in tests: with self.subTest(method=request.method): # just reset the link, for safety sake self.event.assigned_to = None self.event.save() assign(request, self.event, person_id=person_id) self.event.refresh_from_db() self.assertEqual(self.event.assigned_to, first_person)
def test_assigning(self): """Ensure that with assignment is set correctly.""" first_person = Person.objects.first() tests = [ (self.factory.get('/'), first_person.pk), (self.factory.post('/', {'person': first_person.pk}), None), ] for request, person_id in tests: with self.subTest(method=request.method): # just reset the link, for safety sake self.event.assigned_to = None self.event.save() assign(request, self.event, person_id=person_id) self.event.refresh_from_db() self.assertEqual(self.event.assigned_to, first_person)
def test_removing_assignment(self): """Ensure that with person_id=None, the assignment is removed.""" first_person = Person.objects.first() tests = [ (self.factory.get('/'), None), (self.factory.post('/'), None), ] for request, person_id in tests: with self.subTest(method=request.method): # just re-set the link to first person, for safety sake self.event.assigned_to = first_person self.event.save() assign(request, self.event, person_id=person_id) self.event.refresh_from_db() self.assertEqual(self.event.assigned_to, None)
def test_removing_assignment(self): """Ensure that with person_id=None, the assignment is removed.""" first_person = Person.objects.first() tests = [ (self.factory.get('/'), None), (self.factory.post('/'), None), ] for request, person_id in tests: with self.subTest(method=request.method): # just re-set the link to first person, for safety sake self.event.assigned_to = first_person self.event.save() assign(request, self.event, person_id=person_id) self.event.refresh_from_db() self.assertEqual(self.event.assigned_to, None)
def get(self, request, *args, **kwargs): self.object = self.get_object() requested_person_id = self.kwargs.get(self.person_url_kwarg) assign(request, self.object, requested_person_id) return super().get(request, *args, **kwargs)
def get(self, request, *args, **kwargs): self.object = self.get_object() requested_person_id = self.kwargs.get(self.person_url_kwarg) assign(request, self.object, requested_person_id) return super().get(request, *args, **kwargs)