Example #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)
Example #2
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)
Example #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'])
Example #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)
Example #5
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)
Example #6
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)
Example #7
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'])
Example #8
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))
Example #9
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)
Example #10
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)
Example #11
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)