示例#1
0
 def test_simple_user_CANT_remove_his_approved_restaurant(self):
     r = Restaurant(created_by=self.user,
                    approved=True,
                    name='alskdasdzxlasdllasjdlk')
     r.save()
     self.redirect_to_login_on_get(
         "venues.views.venuess.suspend_restaurant", pargs=[r.pk])
示例#2
0
 def test_user_cant_add_notes_to_notapproved_restaurant(self):
     r = Restaurant(name='ajskdajsdas')
     r.save()
     params = {'text': 'a;lsdlasdlaksnd,mxnckajsldakjashdkjasdsdsometext'}
     self.redirect_to_login_on_post("venues.views.notes.add_note",
                                    pargs=[r.pk],
                                    params=params)
示例#3
0
    def test_user_CANT_update_not_his_restaurant(self):
        r = Restaurant()
        r.save()

        cuisine = Cuisine.objects.create(name="nasjdasdashaksds62a")

        params = {
            'name': 'alksjdlas',
            'address': 'laksdlkasd',
            'cuisines': cuisine.pk,
            'catering': True,
            'delivery': True,
            'alcoholFree': True,
            'porkFree': True,
            'muslimOwner': True,
            'location': str(Point(0, 0)),
            'menu': 1,
            'city': 'kalsjd',
            'country': 'RU',
            'website': 'http://site.ru/',
        }

        self.redirect_to_login_on_get("venues.views.venuess.update_restaurant",
                                      pargs=[r.pk],
                                      params=params)
示例#4
0
 def test_superuser_CAN_see_any_restaurant(self):
     r = Restaurant(approved=True, created_by=self.user)
     r.save()
     self.can_get("venues.views.venuess.restaurant", pargs=[r.pk])
     self.can_get("venues.views.venuess.restaurant",
                  pargs=[self.approvedRestaurant.pk])
     self.can_get("venues.views.venuess.restaurant",
                  pargs=[self.restaurant.pk])
示例#5
0
 def test_superuser_can_add_notes(self):
     r = Restaurant(name='ajskdajsdas')
     r.save()
     params = {'text': 'a;lsdlasdlaksnd,mxnckajsldasdsometext'}
     self.redirect_on_post("venues.views.notes.add_note",
                           pargs=[r.pk],
                           params=params)
     note = Note.objects.filter(venue_id=r.id).order_by('-pk').first()
     self.assertEqual(note.text, params['text'])
示例#6
0
    def setUp(self):
        super(TestReports, self).setUp()
        self.restaurant = Restaurant(name="lashdkjasd")
        self.restaurant.save()

        self.report = Report.objects.create(
            note="kjashda",
            content_type_id=ContentType.objects.get_for_model(Restaurant).id,
            venue_id=self.restaurant.id)
示例#7
0
    def test_superuser_CAN_remove_any_restaurant(self):
        r = Restaurant(created_by=self.user,
                       approved=True,
                       name='alskdlasdllasjdlk')
        r.save()
        self.redirect_on_get("venues.views.venuess.suspend_restaurant",
                             pargs=[r.pk])

        self.assertEqual(Restaurant.objects.filter(pk=r.pk).count(), 0)
示例#8
0
 def test_anyone_can_get_show_all_notes(self):
     r = Restaurant(name="jkasdhaksd")
     r.save()
     n = Note.objects.create(
         venue_id=r.id,
         content_type_id=ContentType.objects.get_for_model(Restaurant).id,
         text='LKJaklsjdasd')
     response = self.can_get("venues.views.notes.show_all_notes",
                             pargs=[r.id])
     self.assertContains(response, n.text)
示例#9
0
    def setUp(self):
        super(TestProfile, self).setUp()

        self.userRestaurant = Restaurant(name="lkajhsdklahsdkjasd",
                                         created_by=self.user)
        self.userRestaurant.save()
        self.alienRestaurant = Restaurant(name="lkahsdjashdkansdmnm")
        self.alienRestaurant.save()

        self.userNote1 = Note.objects.create(
            text="kashdkjashdas",
            created_by=self.user,
            content_type_id=ContentType.objects.get_for_model(Restaurant).id,
            venue_id=self.userRestaurant.id)
        self.userNote2 = Note.objects.create(
            text="kashdkjasdasdashdas",
            created_by=self.user,
            content_type_id=ContentType.objects.get_for_model(Restaurant).id,
            venue_id=self.alienRestaurant.id)
        self.alienNote = Note.objects.create(
            text="kashdkjasdasfasddashdas",
            content_type_id=ContentType.objects.get_for_model(Restaurant).id,
            venue_id=self.alienRestaurant.id)

        self.userReview1 = Review.objects.create(
            text="kashdkjashdas",
            created_by=self.user,
            content_type_id=ContentType.objects.get_for_model(Restaurant).id,
            venue_id=self.userRestaurant.id)
        self.userReview2 = Review.objects.create(
            text="kashdkjasdasdashdas",
            created_by=self.user,
            content_type_id=ContentType.objects.get_for_model(Restaurant).id,
            venue_id=self.alienRestaurant.id)
        self.alienReview = Review.objects.create(
            text="kashdkjasdasasdasdashdas",
            content_type_id=ContentType.objects.get_for_model(Restaurant).id,
            venue_id=self.alienRestaurant.id)

        self.userReport1 = Report.objects.create(
            note="kashdkjashdas",
            created_by=self.user,
            content_type_id=ContentType.objects.get_for_model(Restaurant).id,
            venue_id=self.userRestaurant.id)
        self.userReport2 = Report.objects.create(
            note="kashdkjasdasdashdas",
            created_by=self.user,
            content_type_id=ContentType.objects.get_for_model(Restaurant).id,
            venue_id=self.alienRestaurant.id)
        self.alienReport = Report.objects.create(
            note="kashdkjasdaasdasdsdashdas",
            content_type_id=ContentType.objects.get_for_model(Restaurant).id,
            venue_id=self.alienRestaurant.id)
示例#10
0
    def setUp(self):
        super(TestVenuess, self).setUp()

        self.cuisine = Cuisine.objects.create(name="cuisine")

        self.approvedRestaurant = Restaurant(name="Approved",
                                             approved=True,
                                             location=Point(0, 0))
        self.approvedRestaurant.save()
        self.approvedRestaurant.cuisines.add(self.cuisine)
        self.approvedRestaurant.save()

        self.approvedFarAwayRestaurant = Restaurant(
            name="approvedFarAwayRestaurant",
            approved=True,
            location=Point(45, 45))
        self.approvedFarAwayRestaurant.save()
        self.approvedFarAwayRestaurant.cuisines.add(self.cuisine)
        self.approvedFarAwayRestaurant.save()

        self.approvedRestaurantWithoutCategory = Restaurant(
            name="WithoutCategory", approved=True, location=Point(0, 0))
        self.approvedRestaurantWithoutCategory.save()

        self.restaurant = Restaurant(name="UnApproved",
                                     approved=False,
                                     location=Point(0, 0))
        self.restaurant.save()
        self.restaurant.cuisines.add(self.cuisine)
        self.restaurant.save()
示例#11
0
    def test_user_CANT_update_not_his_note(self):
        r = Restaurant(name="jaksjdaklsd")
        r.save()
        note = Note.objects.create(
            content_type_id=ContentType.objects.get_for_model(Restaurant).id,
            venue_id=r.id,
            created_by=self.user)

        params = {'text': 'new_text'}

        self.redirect_to_login_on_get("venues.views.notes.update_note",
                                      pargs=[note.pk])
        self.redirect_to_login_on_post("venues.views.notes.update_note",
                                       pargs=[note.pk],
                                       params=params)
示例#12
0
    def test_superuser_can_update_note(self):
        r = Restaurant(name="jaksjdaklsd")
        r.save()
        note = Note.objects.create(
            content_type_id=ContentType.objects.get_for_model(Restaurant).id,
            venue_id=r.id,
            created_by=self.user)

        params = {'text': 'new_text'}

        self.can_get("venues.views.notes.update_note", pargs=[note.pk])
        self.redirect_on_post("venues.views.notes.update_note",
                              pargs=[note.pk],
                              params=params)
        note = Note.objects.get(pk=note.pk)
        self.assertEqual(note.text, params['text'])
示例#13
0
class TestProfile(TestCaseVenue):
    def setUp(self):
        super(TestProfile, self).setUp()

        self.userRestaurant = Restaurant(name="lkajhsdklahsdkjasd",
                                         created_by=self.user)
        self.userRestaurant.save()
        self.alienRestaurant = Restaurant(name="lkahsdjashdkansdmnm")
        self.alienRestaurant.save()

        self.userNote1 = Note.objects.create(
            text="kashdkjashdas",
            created_by=self.user,
            content_type_id=ContentType.objects.get_for_model(Restaurant).id,
            venue_id=self.userRestaurant.id)
        self.userNote2 = Note.objects.create(
            text="kashdkjasdasdashdas",
            created_by=self.user,
            content_type_id=ContentType.objects.get_for_model(Restaurant).id,
            venue_id=self.alienRestaurant.id)
        self.alienNote = Note.objects.create(
            text="kashdkjasdasfasddashdas",
            content_type_id=ContentType.objects.get_for_model(Restaurant).id,
            venue_id=self.alienRestaurant.id)

        self.userReview1 = Review.objects.create(
            text="kashdkjashdas",
            created_by=self.user,
            content_type_id=ContentType.objects.get_for_model(Restaurant).id,
            venue_id=self.userRestaurant.id)
        self.userReview2 = Review.objects.create(
            text="kashdkjasdasdashdas",
            created_by=self.user,
            content_type_id=ContentType.objects.get_for_model(Restaurant).id,
            venue_id=self.alienRestaurant.id)
        self.alienReview = Review.objects.create(
            text="kashdkjasdasasdasdashdas",
            content_type_id=ContentType.objects.get_for_model(Restaurant).id,
            venue_id=self.alienRestaurant.id)

        self.userReport1 = Report.objects.create(
            note="kashdkjashdas",
            created_by=self.user,
            content_type_id=ContentType.objects.get_for_model(Restaurant).id,
            venue_id=self.userRestaurant.id)
        self.userReport2 = Report.objects.create(
            note="kashdkjasdasdashdas",
            created_by=self.user,
            content_type_id=ContentType.objects.get_for_model(Restaurant).id,
            venue_id=self.alienRestaurant.id)
        self.alienReport = Report.objects.create(
            note="kashdkjasdaasdasdsdashdas",
            content_type_id=ContentType.objects.get_for_model(Restaurant).id,
            venue_id=self.alienRestaurant.id)

    def test_guest_cant_view_profile_pages(self):
        self.redirect_to_login_on_get("venues.views.profile.myrestaurants")
        self.redirect_to_login_on_get("venues.views.profile.myreviews")
        self.redirect_to_login_on_get("venues.views.profile.mynotes")
        self.redirect_to_login_on_get("venues.views.profile.myreports")

    @TestCaseVenue.login
    def test_user_can_view_his_restaurants(self):
        response = self.can_get("venues.views.profile.myrestaurants")
        self.assertContains(response, self.userRestaurant.name)
        self.assertNotContains(response, self.alienRestaurant.name)

    @TestCaseVenue.login
    def test_user_can_view_his_notes(self):
        response = self.can_get("venues.views.profile.mynotes")
        self.assertContains(response, self.userNote1.text)
        self.assertContains(response, self.userNote2.text)
        self.assertNotContains(response, self.alienNote.text)

    @TestCaseVenue.login
    def test_user_can_view_his_reviews(self):
        response = self.can_get("venues.views.profile.myreviews")
        self.assertContains(response, self.userReview1.text)
        self.assertContains(response, self.userReview2.text)
        self.assertNotContains(response, self.alienReview.text)

    @TestCaseVenue.login
    def test_user_can_view_his_reports(self):
        response = self.can_get("venues.views.profile.myreports")
        self.assertContains(response, self.userReport1.note)
        self.assertContains(response, self.userReport2.note)
        self.assertNotContains(response, self.alienReport.note)
示例#14
0
class TestReports(TestCaseVenue):
    def setUp(self):
        super(TestReports, self).setUp()
        self.restaurant = Restaurant(name="lashdkjasd")
        self.restaurant.save()

        self.report = Report.objects.create(
            note="kjashda",
            content_type_id=ContentType.objects.get_for_model(Restaurant).id,
            venue_id=self.restaurant.id)

    def test_guest_cant_report_restaurant(self):
        self.redirect_to_login_on_get("venues.views.reports.report_restaurant",
                                      pargs=[self.restaurant.id])

    @TestCaseVenue.login
    def test_login_user_CAN_report_restaurant(self):
        Report.objects.all().delete()

        params = {'type': 1, 'note': 'alksjdlkasjd'}

        self.can_get("venues.views.reports.report_restaurant",
                     pargs=[self.restaurant.id])
        self.redirect_on_post("venues.views.reports.report_restaurant",
                              pargs=[self.restaurant.id],
                              params=params)

        self.assertEqual(Report.objects.filter(**params).count(), 1)

    def test_guest_cant_moderate(self):
        self.redirect_to_login_on_get("venues.views.reports.moderate_reports")

    @TestCaseVenue.login
    def test_simple_user_cant_moderate(self):
        self.redirect_to_login_on_get("venues.views.reports.moderate_reports")

    @TestCaseVenue.moderator
    def test_moderator_can_moderate(self):
        self.can_get("venues.views.reports.moderate_reports")

    @TestCaseVenue.superuser
    def test_superuser_can_moderate(self):
        self.can_get("venues.views.reports.moderate_reports")

    def test_guest_cant_moderate_report(self):
        self.redirect_to_login_on_get("venues.views.reports.moderate_report",
                                      pargs=[
                                          self.report.id,
                                      ])

    @TestCaseVenue.login
    def test_simple_user_cant_moderate_report(self):
        self.redirect_to_login_on_get("venues.views.reports.moderate_report",
                                      pargs=[
                                          self.report.id,
                                      ])

    @TestCaseVenue.moderator
    def test_moderator_CAN_moderate_report(self):
        params = {"resolved": True, "moderator_note": 'alskkdlaksjdlkasd'}
        self.redirect_on_post("venues.views.reports.moderate_report",
                              pargs=[
                                  self.report.id,
                              ],
                              params=params)

        self.report = Report.objects.get(pk=self.report.pk)
        self.assertEqual(self.report.moderator_note, params['moderator_note'])
        self.assertEqual(self.report.resolved, params['resolved'])
示例#15
0
 def test_simple_user_CAN_see_unapproved_his_restaurant(self):
     r = Restaurant(approved=True, created_by=self.user)
     r.save()
     self.can_get("venues.views.venuess.restaurant", pargs=[r.pk])
示例#16
0
 def test_guest_CANT_remove_restaurant(self):
     r = Restaurant(created_by=self.user, name='alskdlasdllasjdlk')
     r.save()
     self.redirect_to_login_on_get(
         "venues.views.venuess.suspend_restaurant", pargs=[r.pk])
示例#17
0
 def test_simple_user_CANT_remove_not_his_restaurant(self):
     r = Restaurant(name='alskdlasdllzxcaasjdlk')
     r.save()
     self.redirect_to_login_on_get(
         "venues.views.venuess.suspend_restaurant", pargs=[r.pk])
示例#18
0
 def test_guest_cant_add_notes(self):
     r = Restaurant(name='ajskdajsdas')
     r.save()
     self.redirect_to_login_on_post("venues.views.notes.add_note",
                                    pargs=[r.pk])
示例#19
0
    def test_moderator_CAN_update_any_restaurant(self):
        r = Restaurant(name="lasjdklasd,.mxz,calsd")
        Cuisine.objects.create(name="nasjdasdashaksdsa")
        Cuisine.objects.create(name="nasjdasdashaksdsa")
        Cuisine.objects.create(name="nasjdasdashaksdsa")
        Cuisine.objects.create(name="nasjdasdashaksdsa")
        Cuisine.objects.create(name="nasjdasdashaksdsa")
        Cuisine.objects.create(name="nasjdasdashakssdsa")
        Cuisine.objects.create(name="nasjdasdashaksddsa")
        Cuisine.objects.create(name="nasjdasdashaksdasa")
        Cuisine.objects.create(name="nasjdasdashaksdsa")
        Cuisine.objects.create(name="nasjdasdashaksdasa")
        Cuisine.objects.create(name="nasjdasdashaksdsdsa")
        Cuisine.objects.create(name="nasjdasdashaksdsa")
        Cuisine.objects.create(name="nasjdasdashakshgdsa")
        Cuisine.objects.create(name="nasjdasdashaksdsa")
        Cuisine.objects.create(name="nasjdasdashaksdfsa")
        Cuisine.objects.create(name="nasjdasdashaksddsa")
        Cuisine.objects.create(name="nasjdasdashakdssdsa")
        Cuisine.objects.create(name="nasjdasdashaksvdsa")
        Cuisine.objects.create(name="nasjdasdashaks2dsa")
        Cuisine.objects.create(name="nasjdasdashaks3dsa")
        Cuisine.objects.create(name="nasjdasdashaks32dsa")
        Cuisine.objects.create(name="nasjdasdashaksd2sa")
        Cuisine.objects.create(name="nasjdasdashaksd23sa")
        Cuisine.objects.create(name="nasjdasdashaksd2sa")
        Cuisine.objects.create(name="nasjdasdashaksdsa")
        Cuisine.objects.create(name="nasjdasdashaksd521sa")
        Cuisine.objects.create(name="nasjdasdashaksdsa")
        cuisine = Cuisine.objects.create(name="nasjdhaksdsa")
        r.save()

        params = {
            'name': 'alksjdlas',
            'address': 'laksdlkasd',
            'cuisines': cuisine.pk,
            'catering': True,
            'delivery': True,
            'alcoholFree': True,
            'porkFree': True,
            'muslimOwner': True,
            'location': str(Point(0, 0)),
            'menu': 1,
            'city': 'kalsjd',
            'country': 'RU',
            'website': 'http://site.ru/',
        }

        self.can_get("venues.views.venuess.update_restaurant", pargs=[r.pk])
        response = self.redirect_on_post(
            "venues.views.venuess.update_restaurant",
            pargs=[r.pk],
            params=params)

        r = Restaurant.objects.get(pk=r.pk)

        for key in params.keys():
            if key == 'cuisines':
                self.assertEqual(r.cuisines.all()[0].pk, cuisine.pk)
            else:
                self.assertEqual(getattr(r, key), params[key])
示例#20
0
 def test_anyone_can_get_show_all_reviews(self):
     rest = Restaurant(name="kajshdkjasdas")
     rest.save()
     self.can_get("venues.views.reviews.show_all_reviews", pargs=[rest.pk])
示例#21
0
class TestVenuess(TestCaseVenue):
    def setUp(self):
        super(TestVenuess, self).setUp()

        self.cuisine = Cuisine.objects.create(name="cuisine")

        self.approvedRestaurant = Restaurant(name="Approved",
                                             approved=True,
                                             location=Point(0, 0))
        self.approvedRestaurant.save()
        self.approvedRestaurant.cuisines.add(self.cuisine)
        self.approvedRestaurant.save()

        self.approvedFarAwayRestaurant = Restaurant(
            name="approvedFarAwayRestaurant",
            approved=True,
            location=Point(45, 45))
        self.approvedFarAwayRestaurant.save()
        self.approvedFarAwayRestaurant.cuisines.add(self.cuisine)
        self.approvedFarAwayRestaurant.save()

        self.approvedRestaurantWithoutCategory = Restaurant(
            name="WithoutCategory", approved=True, location=Point(0, 0))
        self.approvedRestaurantWithoutCategory.save()

        self.restaurant = Restaurant(name="UnApproved",
                                     approved=False,
                                     location=Point(0, 0))
        self.restaurant.save()
        self.restaurant.cuisines.add(self.cuisine)
        self.restaurant.save()

    def test_anyone_can_access_index_page(self):
        self.can_get("venues.views.venuess.index")

    def test_guest_can_see_only_approved_restaurants(self):
        response = self.can_get("venues.views.venuess.index")
        self.assertContains(response, self.approvedRestaurant.name)
        self.assertNotContains(response, self.restaurant.name)

        response = self.can_post("venues.views.venuess.index")
        self.assertContains(response, self.approvedRestaurant.name)
        self.assertNotContains(response, self.restaurant.name)

    @TestCaseEx.login
    def test_simple_user_can_see_only_approved_restaurants(self):
        response = self.can_get("venues.views.venuess.index")
        self.assertContains(response, self.approvedRestaurant.name)
        self.assertNotContains(response, self.restaurant.name)

        response = self.can_post("venues.views.venuess.index")
        self.assertContains(response, self.approvedRestaurant.name)
        self.assertNotContains(response, self.restaurant.name)

    @TestCaseVenue.moderator
    def test_moderator_can_see_all_restaurants(self):
        response = self.can_get("venues.views.venuess.index")
        self.assertContains(response, self.approvedRestaurant.name)
        self.assertContains(response, self.restaurant.name)

        response = self.can_post("venues.views.venuess.index")
        self.assertContains(response, self.approvedRestaurant.name)
        self.assertContains(response, self.restaurant.name)

    @TestCaseEx.superuser
    def test_superuser_can_see_all_restaurants(self):
        response = self.can_get("venues.views.venuess.index")
        self.assertContains(response, self.approvedRestaurant.name)
        self.assertContains(response, self.restaurant.name)

        response = self.can_post("venues.views.venuess.index")
        self.assertContains(response, self.approvedRestaurant.name)
        self.assertContains(response, self.restaurant.name)

    # def test_closets_should_respond(self):
    #     self.can_get("venues.views.venuess.closest")

    def test_closest_should_respond_with_lat_and_lng_parameters(self):
        response = self.can_get("venues.views.venuess.index",
                                params={
                                    'lat': 0,
                                    'lon': 0
                                })
        self.assertContains(response, self.approvedRestaurant.name)
        self.assertContains(response,
                            self.approvedRestaurantWithoutCategory.name)
        self.assertNotContains(response, self.approvedFarAwayRestaurant.name)
        self.assertNotContains(response, self.restaurant.name)

    def test_closest_should_respond_with_lat_and_lng_and_categories_parameters(
            self):
        response = self.can_get("venues.views.venuess.index",
                                params={
                                    'lat': 0,
                                    'lon': 0,
                                    'category': self.cuisine.name
                                })
        self.assertContains(response, self.approvedRestaurant.name)
        self.assertNotContains(response,
                               self.approvedRestaurantWithoutCategory.name)
        self.assertNotContains(response, self.approvedFarAwayRestaurant.name)
        self.assertNotContains(response, self.restaurant.name)

    def test_anyone_can_see_approved_restaurant(self):
        self.can_get("venues.views.venuess.restaurant",
                     pargs=[self.approvedRestaurant.pk])

    def test_guest_cant_see_unapproved_restaurant(self):
        response = self.get("venues.views.venuess.restaurant",
                            pargs=[self.restaurant.pk])
        self.assertEqual(response.status_code, 404)

    @TestCaseVenue.login
    def test_simple_user_CANT_see_unapproved_NOT_his_restaurant(self):
        response = self.get("venues.views.venuess.restaurant",
                            pargs=[self.restaurant.pk])
        self.assertEqual(response.status_code, 404)

    @TestCaseVenue.login
    def test_simple_user_CAN_see_unapproved_his_restaurant(self):
        r = Restaurant(approved=True, created_by=self.user)
        r.save()
        self.can_get("venues.views.venuess.restaurant", pargs=[r.pk])

    @TestCaseVenue.moderator
    def test_moderator_CAN_see_any_restaurant(self):
        r = Restaurant(approved=True, created_by=self.user)
        r.save()
        self.can_get("venues.views.venuess.restaurant", pargs=[r.pk])
        self.can_get("venues.views.venuess.restaurant",
                     pargs=[self.approvedRestaurant.pk])
        self.can_get("venues.views.venuess.restaurant",
                     pargs=[self.restaurant.pk])

    @TestCaseVenue.superuser
    def test_superuser_CAN_see_any_restaurant(self):
        r = Restaurant(approved=True, created_by=self.user)
        r.save()
        self.can_get("venues.views.venuess.restaurant", pargs=[r.pk])
        self.can_get("venues.views.venuess.restaurant",
                     pargs=[self.approvedRestaurant.pk])
        self.can_get("venues.views.venuess.restaurant",
                     pargs=[self.restaurant.pk])

    def test_guest_CANT_remove_restaurant(self):
        r = Restaurant(created_by=self.user, name='alskdlasdllasjdlk')
        r.save()
        self.redirect_to_login_on_get(
            "venues.views.venuess.suspend_restaurant", pargs=[r.pk])

    @TestCaseVenue.login
    def test_simple_user_CANT_remove_not_his_restaurant(self):
        r = Restaurant(name='alskdlasdllzxcaasjdlk')
        r.save()
        self.redirect_to_login_on_get(
            "venues.views.venuess.suspend_restaurant", pargs=[r.pk])

    @TestCaseVenue.login
    def test_simple_user_CANT_remove_his_approved_restaurant(self):
        r = Restaurant(created_by=self.user,
                       approved=True,
                       name='alskdasdzxlasdllasjdlk')
        r.save()
        self.redirect_to_login_on_get(
            "venues.views.venuess.suspend_restaurant", pargs=[r.pk])

    @TestCaseVenue.login
    def test_simple_user_CAN_remove_his_not_approved_restaurant(self):
        r = Restaurant(created_by=self.user,
                       approved=False,
                       name='alsasdkdlasdllasjdlk')
        r.save()
        self.redirect_on_get("venues.views.venuess.suspend_restaurant",
                             pargs=[r.pk])

        self.assertEqual(Restaurant.objects.filter(pk=r.pk).count(), 0)

    @TestCaseVenue.moderator
    def test_moderator_CAN_remove_any_restaurant(self):
        r = Restaurant(created_by=self.user,
                       approved=True,
                       name='alskdlasdllasjdlk')
        r.save()
        self.redirect_on_get("venues.views.venuess.suspend_restaurant",
                             pargs=[r.pk])

        self.assertEqual(Restaurant.objects.filter(pk=r.pk).count(), 0)

    @TestCaseVenue.superuser
    def test_superuser_CAN_remove_any_restaurant(self):
        r = Restaurant(created_by=self.user,
                       approved=True,
                       name='alskdlasdllasjdlk')
        r.save()
        self.redirect_on_get("venues.views.venuess.suspend_restaurant",
                             pargs=[r.pk])

        self.assertEqual(Restaurant.objects.filter(pk=r.pk).count(), 0)

    def test_guest_cant_add_restaurant(self):
        self.redirect_to_login_on_get("venues.views.venuess.add_restaurant")

    @TestCaseVenue.login
    def test_user_can_add_restaurant(self):
        self.can_get("venues.views.venuess.add_restaurant")

        params = {
            'name': 'alksjdlas',
            'address': 'laksdlkasd',
            'cuisines': self.cuisine.pk,
            'catering': True,
            'delivery': True,
            'alcoholFree': True,
            'porkFree': True,
            'muslimOwner': True,
            'location': str(Point(0, 0)),
            'menu': 1,
            'city': 'kalsjd',
            'country': 'RU',
            'website': 'http://site.ru/',
        }

        count_before = Restaurant.objects.count()

        response = self.redirect_on_post("venues.views.venuess.add_restaurant",
                                         params=params)

        self.assertEqual(count_before + 1, Restaurant.objects.count())
        rest = Restaurant.objects.order_by('-pk').first()

        for key in params.keys():
            if key == 'cuisines':
                self.assertEqual(rest.cuisines.all()[0].pk, self.cuisine.pk)
            else:
                self.assertEqual(getattr(rest, key), params[key])

    def test_guest_cant_update_restaurant(self):
        self.redirect_to_login_on_get("venues.views.venuess.update_restaurant",
                                      pargs=[self.approvedRestaurant.pk])

    @TestCaseVenue.login
    def test_user_CANT_update_not_his_restaurant(self):
        r = Restaurant()
        r.save()

        cuisine = Cuisine.objects.create(name="nasjdasdashaksds62a")

        params = {
            'name': 'alksjdlas',
            'address': 'laksdlkasd',
            'cuisines': cuisine.pk,
            'catering': True,
            'delivery': True,
            'alcoholFree': True,
            'porkFree': True,
            'muslimOwner': True,
            'location': str(Point(0, 0)),
            'menu': 1,
            'city': 'kalsjd',
            'country': 'RU',
            'website': 'http://site.ru/',
        }

        self.redirect_to_login_on_get("venues.views.venuess.update_restaurant",
                                      pargs=[r.pk],
                                      params=params)

    @TestCaseVenue.moderator
    def test_moderator_CAN_update_any_restaurant(self):
        r = Restaurant(name="lasjdklasd,.mxz,calsd")
        Cuisine.objects.create(name="nasjdasdashaksdsa")
        Cuisine.objects.create(name="nasjdasdashaksdsa")
        Cuisine.objects.create(name="nasjdasdashaksdsa")
        Cuisine.objects.create(name="nasjdasdashaksdsa")
        Cuisine.objects.create(name="nasjdasdashaksdsa")
        Cuisine.objects.create(name="nasjdasdashakssdsa")
        Cuisine.objects.create(name="nasjdasdashaksddsa")
        Cuisine.objects.create(name="nasjdasdashaksdasa")
        Cuisine.objects.create(name="nasjdasdashaksdsa")
        Cuisine.objects.create(name="nasjdasdashaksdasa")
        Cuisine.objects.create(name="nasjdasdashaksdsdsa")
        Cuisine.objects.create(name="nasjdasdashaksdsa")
        Cuisine.objects.create(name="nasjdasdashakshgdsa")
        Cuisine.objects.create(name="nasjdasdashaksdsa")
        Cuisine.objects.create(name="nasjdasdashaksdfsa")
        Cuisine.objects.create(name="nasjdasdashaksddsa")
        Cuisine.objects.create(name="nasjdasdashakdssdsa")
        Cuisine.objects.create(name="nasjdasdashaksvdsa")
        Cuisine.objects.create(name="nasjdasdashaks2dsa")
        Cuisine.objects.create(name="nasjdasdashaks3dsa")
        Cuisine.objects.create(name="nasjdasdashaks32dsa")
        Cuisine.objects.create(name="nasjdasdashaksd2sa")
        Cuisine.objects.create(name="nasjdasdashaksd23sa")
        Cuisine.objects.create(name="nasjdasdashaksd2sa")
        Cuisine.objects.create(name="nasjdasdashaksdsa")
        Cuisine.objects.create(name="nasjdasdashaksd521sa")
        Cuisine.objects.create(name="nasjdasdashaksdsa")
        cuisine = Cuisine.objects.create(name="nasjdhaksdsa")
        r.save()

        params = {
            'name': 'alksjdlas',
            'address': 'laksdlkasd',
            'cuisines': cuisine.pk,
            'catering': True,
            'delivery': True,
            'alcoholFree': True,
            'porkFree': True,
            'muslimOwner': True,
            'location': str(Point(0, 0)),
            'menu': 1,
            'city': 'kalsjd',
            'country': 'RU',
            'website': 'http://site.ru/',
        }

        self.can_get("venues.views.venuess.update_restaurant", pargs=[r.pk])
        response = self.redirect_on_post(
            "venues.views.venuess.update_restaurant",
            pargs=[r.pk],
            params=params)

        r = Restaurant.objects.get(pk=r.pk)

        for key in params.keys():
            if key == 'cuisines':
                self.assertEqual(r.cuisines.all()[0].pk, cuisine.pk)
            else:
                self.assertEqual(getattr(r, key), params[key])

    def test_anyone_can_get_restaurant_by_slug(self):
        self.can_get("venues.views.venuess.restaurant_by_slug",
                     pargs=[self.approvedRestaurant.slug])