Exemplo n.º 1
0
class EventCreateFromTemplateViewTestCase(ViewTestMixin, TestCase):
    """Tests for the ``EventCreateFromTemplateView`` view."""
    longMessage = True

    def get_url(self, *args, **kwargs):
        return self.event.get_template_url()

    def setUp(self):
        self.event = EventFactory()
        self.staff = StaffFactory()

    def test_view(self):
        # Only callable if event is a template
        self.is_not_callable(user=self.staff)

        self.event.template_name = 'Foo'
        self.event.save()
        self.is_callable(user=self.staff)
        data = {
            'title': self.event.title,
            'venue': self.event.venue,
            'start': self.event.start,
            'end': self.event.end,
        }
        self.is_callable('POST', data=data, user=self.staff)

        # The template remains and a new event has been created
        self.assertEqual(Event.objects.all().count(), 2)
Exemplo n.º 2
0
    def test_view(self):
        self.event = EventFactory()
        self.is_not_callable()

        self.event.is_published = True
        self.event.save()
        self.should_be_callable_when_anonymous()

        # Test with wrong url kwargs
        resp = self.client.get(self.event.get_absolute_url().replace('2', '1'))
        self.assertEqual(resp.status_code, 302)
Exemplo n.º 3
0
class EventDetailViewTestCase(ViewTestMixin, TestCase):
    """Tests for the ``EventDetailView`` view."""
    longMessage = True

    def get_url(self, **kwargs):
        return self.event.get_absolute_url()

    def test_view(self):
        self.event = EventFactory()
        self.is_not_callable()

        self.event.is_published = True
        self.event.save()
        self.should_be_callable_when_anonymous()

        # Test with wrong url kwargs
        resp = self.client.get(self.event.get_absolute_url().replace('2', '1'))
        self.assertEqual(resp.status_code, 302)
Exemplo n.º 4
0
 def test_get_free_seats(self):
     event_1 = EventFactory(available_seats=20)
     self.assertEqual(event_1.get_free_seats(), 20)
     event_2 = EventFactory()
     self.assertEqual(event_2.get_free_seats(),
                      _('Unlimited seats available.'))
     GuestFactory(event=event_1)
     self.assertEqual(event_1.get_free_seats(), 19)
Exemplo n.º 5
0
class EventDetailViewTestCase(ViewTestMixin, TestCase):
    """Tests for the ``EventDetailView`` view."""

    longMessage = True

    def get_url(self, **kwargs):
        return self.event.get_absolute_url()

    def test_view(self):
        self.event = EventFactory()
        self.is_not_callable()

        self.event.is_published = True
        self.event.save()
        self.should_be_callable_when_anonymous()

        # Test with wrong url kwargs
        resp = self.client.get(self.event.get_absolute_url().replace("2", "1"))
        self.assertEqual(resp.status_code, 302)
Exemplo n.º 6
0
    def test_view(self):
        self.event = EventFactory()
        self.is_not_callable()

        self.event.is_published = True
        self.event.save()
        self.should_be_callable_when_anonymous()

        # Test with wrong url kwargs
        resp = self.client.get(self.event.get_absolute_url().replace("2", "1"))
        self.assertEqual(resp.status_code, 302)
Exemplo n.º 7
0
 def test_is_bookable(self):
     event_1 = EventFactory()
     self.assertFalse(event_1.is_bookable())
     event_2 = EventFactory(
         start=timezone.now() + timezone.timedelta(days=5),
         end=timezone.now() + timezone.timedelta(days=15),
     )
     self.assertTrue(event_2.is_bookable())
Exemplo n.º 8
0
class EventCreateFromTemplateViewTestCase(ViewTestMixin, TestCase):
    """Tests for the ``EventCreateFromTemplateView`` view."""

    longMessage = True

    def get_url(self, *args, **kwargs):
        return self.event.get_template_url()

    def setUp(self):
        self.event = EventFactory()
        self.staff = StaffFactory()

    def test_view(self):
        # Only callable if event is a template
        self.is_not_callable(user=self.staff)

        self.event.template_name = "Foo"
        self.event.save()
        self.is_callable(user=self.staff)
        data = {"title": self.event.title, "venue": self.event.venue, "start": self.event.start, "end": self.event.end}
        self.is_callable("POST", data=data, user=self.staff)

        # The template remains and a new event has been created
        self.assertEqual(Event.objects.all().count(), 2)
Exemplo n.º 9
0
    def test_validates_and_saves_input(self):
        # Test exceeding available seats
        self.event = EventFactory(available_seats=1)
        form = GuestForm(data={'number_of_seats': 100}, event=self.event,
                         user=None)
        self.assertFalse(form.is_valid())

        # Test exceeding available seats (plural error msg)
        self.event = EventFactory(available_seats=20, max_seats_per_guest=1)
        form = GuestForm(data={'number_of_seats': 100}, event=self.event,
                         user=None)
        self.assertFalse(form.is_valid())

        # Test exceeding max amount of seats per booking
        form = GuestForm(data={'number_of_seats': 2}, event=self.event,
                         user=None)
        self.assertFalse(form.is_valid())

        # Test exceeding max amount of seats per booking (plural error msg)
        self.event = EventFactory(max_seats_per_guest=2)
        form = GuestForm(data={'number_of_seats': 3}, event=self.event,
                         user=None)
        self.assertFalse(form.is_valid())

        # Test missing required fields
        self.event = EventFactory(required_fields=['name', 'phone'])
        form = GuestForm(data={'name': 'Foo', 'email': '*****@*****.**'},
                         event=self.event, user=None)
        self.assertFalse(form.is_valid())

        # Test valid form
        form = GuestForm(data={'name': 'Foo', 'phone': '+4911111111'},
                         event=self.event, user=None)
        self.assertTrue(form.is_valid())
        form.save()
        self.assertEqual(Guest.objects.all().count(), 1)
Exemplo n.º 10
0
 def setUp(self):
     self.event = EventFactory()
     self.staff = StaffFactory()
Exemplo n.º 11
0
 def setUp(self):
     self.event = EventFactory()
     self.user = UserFactory()
Exemplo n.º 12
0
 def setUp(self):
     self.event = EventFactory()
     self.staff = StaffFactory()
Exemplo n.º 13
0
 def test_model(self):
     obj = EventFactory()
     self.assertTrue(obj.pk)