Пример #1
0
 def test_deletes_place(self):
     user = UserFactory.create()
     place = PlaceFactory.create(user=user)
     self.client.force_login(user)
     url = reverse("places:delete", args=(place.id, ))
     self.client.post(url)
     self.assertFalse(Place.objects.filter(id=place.id).exists())
Пример #2
0
 def test_puts_place_to_context(self):
     user = UserFactory.create()
     place = PlaceFactory.create(user=user)
     self.client.force_login(user)
     url = reverse("places:delete", args=(place.id, ))
     response = self.client.get(url)
     self.assertContains(response, place.name)
Пример #3
0
 def test_renders_delete_template(self):
     user = UserFactory.create()
     place = PlaceFactory.create(user=user)
     self.client.force_login(user)
     url = reverse("places:delete", args=(place.id, ))
     response = self.client.get(url)
     self.assertEqual(response.status_code, 200)
     self.assertEqual(response.template_name[0], "places/delete.html")
Пример #4
0
 def test_puts_places_to_context(self):
     user = UserFactory.create()
     places = PlaceFactory.create_batch(5, user=user)
     self.client.force_login(user)
     response = self.client.get(reverse("places:list"))
     self.assertEqual(response.status_code, 200)
     self.assertQuerysetEqual(response.context.get("places"),
                              places,
                              transform=lambda x: x,
                              ordered=False)
Пример #5
0
 def test_edits_place(self):
     user = UserFactory.create()
     place = PlaceFactory.create(user=user)
     self.client.force_login(user)
     url = reverse("places:edit", args=(place.id, ))
     response = self.client.post(
         url,
         {
             "name":
             "New_name",
             "point":
             json.dumps({
                 "type": "Point",
                 "coordinates": place.point.coords
             }),
         },
         follow=True,
     )
     self.assertEqual(response.template_name[0], "places/list.html")
     self.assertTrue(
         Place.objects.filter(name="New_name", user=user,
                              id=place.id).exists())