예제 #1
0
    def test_when_dates_are_valid_should_return_events_in_date_range(self):
        url = reverse('EventCalendarFeed')
        user = ViewUserFactory.create()
        event = EventFactory.create(is_repeat=False)
        start_date = datetime.date.today()
        end_date = start_date + datetime.timedelta(days=2)
        EventFactory.create(start_date=end_date+datetime.timedelta(days=1), end_date=end_date+datetime.timedelta(days=2))
        self.login(user)

        response = self.client.get(url, {'start': start_date, 'end': end_date})

        self.assertEqual(len(response.data), 1)
        self.assertEqual(response.data[0]['title'], event.title)
        self.assertEqual(response.data[0]['location'], event.location)
예제 #2
0
def test_successfully_shows_user_events(django_app, user, other_user):
    first_event = EventFactory(created_by=user)
    second_event = EventFactory(created_by=user)

    other_user_event = EventFactory(created_by=other_user)

    response = django_app.get(reverse('users:user_added_events_list'),
                              user=user,
                              status=200)

    assert user == response.context['user_object']
    assert len(response.context['events']) == 2
    assert first_event in response.context['events']
    assert second_event in response.context['events']
    assert other_user_event not in response.context['events']
예제 #3
0
    def test_when_user_logged_in_should_return_all_event(self):
        event = EventFactory.create()
        url = '/api/event/all/'
        user = ViewUserFactory.create()
        self.login(user)

        self.client.post(reverse('EventList'), self.newEvent)
        response = self.client.get(url)

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(len(response.data), 2)
        self.assertEqual(response.data[0]['id'], event.id)
        self.assertEqual(response.data[0]['title'], event.title)
        self.assertEqual(response.data[0]['location'], event.location)
        self.assertEqual(response.data[0]['start_date'], str(event.start_date))
        self.assertEqual(response.data[0]['start_time'], str(event.start_time))
        self.assertEqual(response.data[0]['end_date'], str(event.end_date))
        self.assertEqual(response.data[0]['end_time'], str(event.end_time))
        self.assertEqual(response.data[0]['description'], event.description)
        self.assertEqual(response.data[0]['is_repeat'], event.is_repeat)
        self.assertEqual(response.data[0]['repetition'], event.repetition)
        self.assertEqual(response.data[0]['ends'], str(event.ends))
        self.assertIsNotNone(response.data[1]['id'])
        self.assertEqual(response.data[1]['title'], self.newEvent['title'],)
        self.assertEqual(response.data[1]['location'], self.newEvent['location'])
        self.assertEqual(response.data[1]['start_date'], str(self.newEvent['start_date']))
        self.assertEqual(response.data[1]['start_time'], str(self.newEvent['start_time']))
        self.assertEqual(response.data[1]['end_date'], str(self.newEvent['end_date']))
        self.assertEqual(response.data[1]['end_time'], str(self.newEvent['end_time']))
        self.assertEqual(response.data[1]['description'], self.newEvent['description'])
        self.assertEqual(response.data[1]['is_repeat'], self.newEvent['is_repeat'])
        self.assertEqual(response.data[1]['repetition'], self.newEvent['repetition'])
        self.assertEqual(response.data[1]['ends'], self.newEvent['ends'])
예제 #4
0
    def test_when_not_logged_in_should_return_403_error(self):
        event = EventFactory.create()
        url = reverse('Event', args=[event.id])

        response = self.client.delete(url)

        self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
예제 #5
0
    def test_when_event_is_repeated_should_return_multiple_events_that_occur_in_week(self):
        url = reverse('EventDashboardFeed')
        user = ViewUserFactory.create()
        today = datetime.date.today()
        repeated_event_properties = {
            'start_date': today,
            'end_date': today,
            'is_repeat': True,
            'repetition': 'D',
            'ends': today + datetime.timedelta(days=2)
        }
        repeated_event = EventFactory.create(**repeated_event_properties)
        self.login(user)

        response = self.client.get(url)

        for idx, day in enumerate(response.data):
            if idx == 0:
                self.assertEqual(day[1]['title'], repeated_event.title)
                self.assertEqual(day[1]['location'], repeated_event.location)
            elif idx == 1:
                self.assertEqual(day[1]['title'], repeated_event.title)
                self.assertEqual(day[1]['location'], repeated_event.location)
            else:
                self.assertEqual(len(day), 1)
예제 #6
0
 def test_included_events_have_correct_fields(self):
     # Correct fields include 'category', 'created', 'title' and 'description'
     EventFactory()
     event = self.get_context_data()['recent'][0]
     self.assertEqual(event.category, 'Eventos')
     self.assertEqual(event.title, event.name)
     self.assertEqual(event.created, event.start_at)
예제 #7
0
 def test_items_are_sorted_by_the_created_field(self):
     job = JobFactory(set_created='1985-10-26 09:00Z')  # Middle-age ;-)
     event = EventFactory(start_at='1955-11-12 06:38Z')  # Oldest
     article = NewsArticleFactory(
         set_created='2015-10-21 09:00Z')  # Most recent
     # Assert the models are in chronological order
     self.assertListEqual([article, job, event],
                          self.get_context_data()['recent'])
예제 #8
0
    def test_when_user_logged_in_and_valid_event_data_should_return_204(self):
        event = EventFactory.create()
        url = reverse('Event', args=[event.id])
        user = ViewUserFactory.create()
        self.login(user)

        response = self.client.delete(url)

        self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
예제 #9
0
    def test_events_view_delete(self):
        event = EventFactory(owner=self.user)

        response = self.client.get(reverse('events:delete', args=(event.pk, )))
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.context["object"], event)
        response = self.client.post(reverse('events:delete', args=(event.pk, )))
        self.assertEqual(response.status_code, 302)
        self.assertFalse(Event.objects.filter(name=event.name).exists())
예제 #10
0
 def test_recent_is_a_list_with_at_most_10_items(self):
     # Create more than RECENT_ITEMS_LEN models and assert that only 10 are kept as recent
     for i in range(RECENT_ITEMS_LEN):
         JobFactory()
         EventFactory()
         NewsArticleFactory()
     # The loop above creates RECENT_ITEMS_LEN * 3 items
     self.assertEqual(len(self.get_context_data()['recent']),
                      RECENT_ITEMS_LEN)
예제 #11
0
    def test_should_return_events_that_occur_within_one_week(self):
        url = reverse('EventDashboardFeed')
        user = ViewUserFactory.create()
        today = datetime.date.today()
        event = EventFactory.create(is_repeat=False)
        event2 = EventFactory.create(start_date=today+datetime.timedelta(days=1), is_repeat=False)
        EventFactory.create(start_date=today+datetime.timedelta(days=8))
        self.login(user)

        response = self.client.get(url)

        for idx, day in enumerate(response.data):
            if idx == 0:
                self.assertEqual(day[1]['title'], event.title)
                self.assertEqual(day[1]['location'], event.location)
            elif idx == 1:
                self.assertEqual(day[1]['title'], event2.title)
                self.assertEqual(day[1]['location'], event2.location)
            else:
                self.assertEqual(len(day), 1)
예제 #12
0
    def test_should_return_event_instances_in_date_range(self):
        today = date.today()
        title = 'Foo'
        repeated_event_properties = {
            'title': title,
            'start_date': today,
            'end_date': today,
            'is_repeat': True,
            'repetition': 'D',
            'ends': today + timedelta(days=20)
        }
        event = EventFactory.create(**repeated_event_properties)

        events = get_repeated_events([event], today, today + timedelta(days=2))

        self.assertEqual(len(events), 2)
        for day in events:
            self.assertEqual(day.title, repeated_event_properties['title'])
예제 #13
0
    def test_when_not_logged_in_should_return_403_error(self):
        event = EventFactory.create()
        url = reverse('Event', args=[event.id])

        updated_event = {
            'title': "My updated title",
            'location': event.location,
            'start_date': event.start_date,
            'start_time': event.start_time,
            'end_date': event.end_date,
            'end_time': event.end_time,
            'description': event.description,
            'is_repeat': event.is_repeat,
            'repetition': event.repetition,
            'ends': event.ends
        }

        response = self.client.put(url, updated_event)

        self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
예제 #14
0
    def test_when_user_logged_in_and_event_exists_should_return_event(self):
        event = EventFactory.create()
        url = reverse('Event', args=[event.id])
        user = ViewUserFactory.create()
        self.login(user)

        response = self.client.get(url)

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.data['id'], event.id)
        self.assertEqual(response.data['title'], event.title)
        self.assertEqual(response.data['location'], event.location)
        self.assertEqual(response.data['start_date'], str(event.start_date))
        self.assertEqual(response.data['start_time'], str(event.start_time))
        self.assertEqual(response.data['end_date'], str(event.end_date))
        self.assertEqual(response.data['end_time'], str(event.end_time))
        self.assertEqual(response.data['description'], event.description)
        self.assertEqual(response.data['is_repeat'], event.is_repeat)
        self.assertEqual(response.data['repetition'], event.repetition)
        self.assertEqual(response.data['ends'], str(event.ends))
예제 #15
0
    def test_when_event_is_repeated_should_return_multiple_events(self):
        url = reverse('EventCalendarFeed')
        user = ViewUserFactory.create()
        start_date = datetime.date.today()
        end_date = start_date + datetime.timedelta(days=2)
        repeated_event_properties = {
            'start_date': start_date,
            'end_date': start_date,
            'is_repeat': True,
            'repetition': 'D',
            'ends': end_date + datetime.timedelta(days=4)
        }
        repeated_event = EventFactory.create(**repeated_event_properties)
        self.login(user)

        response = self.client.get(url, {'start': start_date, 'end': end_date})

        self.assertEqual(len(response.data), 2)
        self.assertEqual(response.data[0]['title'], repeated_event.title)
        self.assertEqual(response.data[0]['location'], repeated_event.location)
        self.assertEqual(response.data[1]['title'], repeated_event.title)
        self.assertEqual(response.data[1]['location'], repeated_event.location)
예제 #16
0
    def test_events_view_edit(self):
        event = EventFactory(owner=self.user)

        response = self.client.get(reverse('events:edit', args=(event.pk, )))
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.context["object"], event)
        event_data = {
            'name': "PyDay Rio IV",
            'description': event.description,
            'place': event.place,
            'address': event.address,
            'url': "http://rioiv.python.org.ar",
            'start_at': (now() + timedelta(days=1)).strftime('%d/%m/%Y 08:00:00'),
            'end_at': (now() + timedelta(days=1)).strftime('%d/%m/%Y 18:00:00'),
            'registration_enabled': 1,
            'has_sponsors': 1
        }
        response = self.client.post(reverse('events:edit', args=(event.pk, )), event_data)
        self.assertEqual(response.status_code, 302)
        self.assertFalse(Event.objects.filter(name=event.name).exists())
        edit_event = Event.objects.get(pk=event.pk)
        self.assertEqual(edit_event.name, "PyDay Rio IV")
        self.assertEqual(edit_event.url, "http://rioiv.python.org.ar")
예제 #17
0
    def test_when_user_logged_in_and_valid_event_data_should_return_200(self):
        event = EventFactory.create()
        url = reverse('Event', args=[event.id])
        user = ViewUserFactory.create()
        self.login(user)

        updated_event = {
            'id': event.id,
            'title': "My updated title",
            'location': event.location,
            'start_date': event.start_date,
            'start_time': event.start_time,
            'end_date': event.end_date,
            'end_time': event.end_time,
            'description': event.description,
            'is_repeat': event.is_repeat,
            'repetition': event.repetition,
            'ends': event.ends
        }

        response = self.client.put(url, updated_event)

        self.assertEqual(response.status_code, status.HTTP_200_OK)
예제 #18
0
 def test_events_view_slug(self):
     event = EventFactory()
     response_por_slug = self.client.get('/eventos/{}/'.format(event.slug))
     self.assertEqual(response_por_slug.context['event'].id, event.id)
예제 #19
0
 def test_events_view_list(self):
     event = EventFactory()
     response = self.client.get(reverse('events:events_list_all'))
     self.assertEqual(response.status_code, 200)
     self.assertIn(event, response.context["eventos_pasados"])
예제 #20
0
 def test_events_are_included_in_recent(self):
     event = EventFactory()
     self.assertEqual([event], self.get_context_data()['recent'])