示例#1
0
    def test_when_authenticated_and_does_not_have_permission_should_deny_access(self):
        user = ViewUserFactory.create()
        user_to_delete = ViewUserFactory.create()
        url = reverse('Account', args=[user_to_delete.id])
        self.login(user)

        response = self.client.delete(url)

        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
        self.assertEqual(response.data['detail'], 'You do not have the right permission to access this data')
示例#2
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'])
示例#3
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)
示例#4
0
    def test_when_user_logged_in_and_event_does_not_exist_should_return_404(self):
        url = reverse('Event', args=[101])
        user = ViewUserFactory.create()
        self.login(user)

        response = self.client.get(url)

        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
示例#5
0
    def test_when_not_authenticated_should_deny_access(self):
        user_to_delete = ViewUserFactory.create()
        url = reverse('Account', args=[user_to_delete.id])

        response = self.client.delete(url)

        self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
        self.assertEqual(response.data['detail'], 'Authentication credentials were not provided.')
示例#6
0
    def test_when_user_authenticated_has_permission_should_allow_access(self):
        user = ViewUserFactory.create()
        url = reverse('VictimInterview')
        self.login(user)

        response = self.client.get(url)

        self.assertEqual(response.status_code, status.HTTP_200_OK)
示例#7
0
    def test_when_logged_in_and_does_not_have_permission_should_deny_access(self):
        user = ViewUserFactory.create()
        self.login(user)
        url = reverse('ResendActivationEmail', args=[1000])

        response = self.client.post(url)

        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
        self.assertEqual(response.data['detail'], 'You do not have the right permission to access this data')
示例#8
0
    def test_when_authenticated_and_has_permission_should_delete_account(self):
        user = SuperUserFactory.create()
        user_to_delete = ViewUserFactory.create()
        url = reverse('Account', args=[user_to_delete.id])
        self.login(user)

        response = self.client.delete(url)

        self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
示例#9
0
    def test_when_authenticated_and_does_not_have_permission_should_deny_access(self):
        url = reverse('AccountList')
        user = ViewUserFactory.create()
        self.login(user)

        response = self.client.post(url, self.get_user_data(user))

        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
        self.assertEqual(response.data['detail'], 'You do not have the right permission to access this data')
示例#10
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)
示例#11
0
    def test_when_no_start_and_end_date_in_query_should_return_400_error(self):
        url = reverse('EventCalendarFeed')
        user = ViewUserFactory.create()
        self.login(user)

        response = self.client.get(url)

        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertEqual(response.data, 'Date does not match format YYYY-MM-DD')
示例#12
0
    def test_password_reset(self):
        url = reverse('PasswordReset')
        account = ViewUserFactory.create()
        old_activation_key = account.activation_key
        data = {"email": account.email}
        response = self.client.post(url, data)

        self.assertEqual(len(mail.outbox), 1)
        self.assertEqual(old_activation_key, account.activation_key)  # sending a password reset generates a new activation key
        self.assertEqual(response.status_code, status.HTTP_200_OK)
示例#13
0
    def test_when_authenticated_and_does_not_have_permission_should_deny_access(self):
        permission_set = SuperUserDesignation.create()
        url = reverse('DefaultPermissionsSet', args=[permission_set.id])
        user = ViewUserFactory.create()
        self.login(user)

        response = self.client.delete(url)

        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
        self.assertEqual(response.data['detail'], 'You do not have the right permission to access this data')
示例#14
0
    def test_when_logged_in_and_account_has_not_been_activated_should_return_True(self):
        user = SuperUserFactory.create()
        activated_user = ViewUserFactory.create()
        self.login(user)
        url = reverse('ResendActivationEmail', args=[activated_user.id])

        response = self.client.post(url)

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.data, True)
示例#15
0
    def test_when_start_date_is_later_than_end_date_should_return_400_error(self):
        url = reverse('EventCalendarFeed')
        user = ViewUserFactory.create()
        start_date = datetime.date.today()
        end_date = start_date - datetime.timedelta(days=7)
        self.login(user)

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

        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertEqual(response.data, 'Start date is later than end date')
示例#16
0
    def test_when_authenticated_and_does_not_have_permission_should_deny_access(self):
        user = ViewUserFactory.create()
        url = reverse('Account', args=[user.id])
        self.login(user)
        new_email = '*****@*****.**'
        update_user_data = self.get_update_user_data(user, new_email)

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

        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
        self.assertEqual(response.data['detail'], 'You do not have the right permission to access this data')
示例#17
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)
示例#18
0
    def test_when_authenticated_and_does_not_have_permission_should_deny_access(self):
        name = 'set_to_get'
        permission_set = SuperUserDesignation.create(name=name)
        url = reverse('DefaultPermissionsSet', args=[permission_set.id])

        user = ViewUserFactory.create()
        self.login(user)

        new_name = 'new_name_for_set'
        update_permission_set = self.get_update_permission_set(permission_set, new_name)

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

        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
        self.assertEqual(response.data['detail'], 'You do not have the right permission to access this data')
示例#19
0
    def test_when_user_logged_in_and_valid_event_should_return_event(self):
        url = reverse('EventList')
        user = ViewUserFactory.create()
        self.login(user)

        response = self.client.post(url, self.newEvent)

        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
        self.assertIsNotNone(response.data['id'])
        self.assertEqual(response.data['title'], self.newEvent['title'],)
        self.assertEqual(response.data['location'], self.newEvent['location'])
        self.assertEqual(response.data['start_date'], str(self.newEvent['start_date']))
        self.assertEqual(response.data['start_time'], str(self.newEvent['start_time']))
        self.assertEqual(response.data['end_date'], str(self.newEvent['end_date']))
        self.assertEqual(response.data['end_time'], str(self.newEvent['end_time']))
        self.assertEqual(response.data['description'], self.newEvent['description'])
        self.assertEqual(response.data['is_repeat'], self.newEvent['is_repeat'])
        self.assertEqual(response.data['repetition'], self.newEvent['repetition'])
        self.assertEqual(response.data['ends'], self.newEvent['ends'])
示例#20
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))
示例#21
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)
示例#22
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)
示例#23
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)