feat: add community contribution ranks
This commit is contained in:
@@ -201,12 +201,14 @@ class TestEventsAPIIntegrationTests:
|
||||
response = self.client.post(f'/api/events/{event.id}/register', HTTP_AUTHORIZATION=f'Bearer {self.token}', content_type='application/json')
|
||||
assert response.status_code == 400
|
||||
|
||||
def test_registration_status_update_and_cancel(self):
|
||||
def test_registration_status_update_rejects_self_attendance_and_allows_cancel(self):
|
||||
event = self._create_event(price=0)
|
||||
registration = self._create_registration(event, self.user)
|
||||
original_status = registration.status
|
||||
update = self.client.put(f'/api/events/registrations/{registration.id}', data=json.dumps({'status': Registration.StatusChoices.ATTENDED}), content_type='application/json', HTTP_AUTHORIZATION=f'Bearer {self.token}')
|
||||
assert update.status_code == 200
|
||||
assert update.json()['status'] == Registration.StatusChoices.ATTENDED
|
||||
assert update.status_code == 403
|
||||
registration.refresh_from_db()
|
||||
assert registration.status == original_status
|
||||
cancel = self.client.delete(f'/api/events/registrations/{registration.id}', HTTP_AUTHORIZATION=f'Bearer {self.token}')
|
||||
assert cancel.status_code == 200
|
||||
assert cancel.json()['message'] == 'ثبت\u200cنام شما لغو شد :('
|
||||
@@ -224,6 +226,100 @@ class TestEventsAPIIntegrationTests:
|
||||
assert status_resp.status_code == 200
|
||||
assert status_resp.json()['is_registered']
|
||||
|
||||
def test_my_registrations_pagination_is_scoped_by_status(self):
|
||||
for index in range(12):
|
||||
event = self._create_event(title=f'Confirmed {index}')
|
||||
self._create_registration(event, self.user, status=Registration.StatusChoices.CONFIRMED)
|
||||
cancelled_event = self._create_event(title='Cancelled entry')
|
||||
self._create_registration(cancelled_event, self.user, status=Registration.StatusChoices.CANCELLED)
|
||||
|
||||
first_page = self.client.get(
|
||||
'/api/events/my-registrations/paginated',
|
||||
{'status': Registration.StatusChoices.CONFIRMED, 'page': 1},
|
||||
**self._auth_headers(self.token),
|
||||
)
|
||||
second_page = self.client.get(
|
||||
'/api/events/my-registrations/paginated',
|
||||
{'status': Registration.StatusChoices.CONFIRMED, 'page': 2},
|
||||
**self._auth_headers(self.token),
|
||||
)
|
||||
cancelled_page = self.client.get(
|
||||
'/api/events/my-registrations/paginated',
|
||||
{'status': Registration.StatusChoices.CANCELLED, 'page': 1},
|
||||
**self._auth_headers(self.token),
|
||||
)
|
||||
|
||||
assert first_page.status_code == 200, first_page.content
|
||||
assert first_page.json()['count'] == 12
|
||||
assert first_page.json()['page_size'] == 10
|
||||
assert first_page.json()['total_pages'] == 2
|
||||
assert len(first_page.json()['results']) == 10
|
||||
assert len(second_page.json()['results']) == 2
|
||||
assert all(item['status'] == Registration.StatusChoices.CONFIRMED for item in first_page.json()['results'])
|
||||
assert cancelled_page.json()['count'] == 1
|
||||
assert cancelled_page.json()['results'][0]['status'] == Registration.StatusChoices.CANCELLED
|
||||
|
||||
all_first_page = self.client.get(
|
||||
'/api/events/my-registrations/paginated',
|
||||
{'status': 'all', 'page': 1},
|
||||
**self._auth_headers(self.token),
|
||||
)
|
||||
all_second_page = self.client.get(
|
||||
'/api/events/my-registrations/paginated',
|
||||
{'status': 'all', 'page': 2},
|
||||
**self._auth_headers(self.token),
|
||||
)
|
||||
assert all_first_page.status_code == 200, all_first_page.content
|
||||
assert all_first_page.json()['count'] == 13
|
||||
assert all_first_page.json()['total_pages'] == 2
|
||||
assert len(all_first_page.json()['results']) == 10
|
||||
assert len(all_second_page.json()['results']) == 3
|
||||
assert {item['status'] for item in all_first_page.json()['results'] + all_second_page.json()['results']} == {
|
||||
Registration.StatusChoices.CONFIRMED,
|
||||
Registration.StatusChoices.CANCELLED,
|
||||
}
|
||||
|
||||
def test_my_registrations_supports_status_filter_and_event_ordering(self):
|
||||
now = timezone.now()
|
||||
older = self._create_event(title='Bravo Event', slug='bravo-event', start_time=now - timedelta(days=10))
|
||||
middle = self._create_event(title='Alpha Event', slug='alpha-event', start_time=now - timedelta(days=5))
|
||||
newest = self._create_event(title='Charlie Event', slug='charlie-event', start_time=now - timedelta(days=1))
|
||||
self._create_registration(older, self.user, status=Registration.StatusChoices.CANCELLED)
|
||||
self._create_registration(middle, self.user, status=Registration.StatusChoices.CONFIRMED)
|
||||
self._create_registration(newest, self.user, status=Registration.StatusChoices.PENDING)
|
||||
endpoint = '/api/events/my-registrations/paginated'
|
||||
headers = self._auth_headers(self.token)
|
||||
|
||||
all_status_default_order = self.client.get(endpoint, {'status': 'all'}, **headers)
|
||||
legacy_default = self.client.get(endpoint, **headers)
|
||||
confirmed_only = self.client.get(endpoint, {'status': 'confirmed'}, **headers)
|
||||
start_time_ascending = self.client.get(endpoint, {'status': 'all', 'sort_by': 'start_time', 'sort_order': 'asc'}, **headers)
|
||||
title_ascending = self.client.get(endpoint, {'status': 'all', 'sort_by': 'title', 'sort_order': 'asc'}, **headers)
|
||||
title_descending = self.client.get(endpoint, {'status': 'all', 'sort_by': 'title', 'sort_order': 'desc'}, **headers)
|
||||
invalid_sort = self.client.get(endpoint, {'sort_by': 'created_at'}, **headers)
|
||||
invalid_direction = self.client.get(endpoint, {'sort_order': 'sideways'}, **headers)
|
||||
|
||||
assert all_status_default_order.status_code == 200, all_status_default_order.content
|
||||
assert all_status_default_order.json()['count'] == 3
|
||||
assert [row['event']['slug'] for row in all_status_default_order.json()['results']] == [
|
||||
'charlie-event', 'alpha-event', 'bravo-event',
|
||||
]
|
||||
assert legacy_default.json()['count'] == 1
|
||||
assert legacy_default.json()['results'][0]['status'] == Registration.StatusChoices.CONFIRMED
|
||||
assert confirmed_only.json()['count'] == 1
|
||||
assert confirmed_only.json()['results'][0]['status'] == Registration.StatusChoices.CONFIRMED
|
||||
assert [row['event']['slug'] for row in start_time_ascending.json()['results']] == [
|
||||
'bravo-event', 'alpha-event', 'charlie-event',
|
||||
]
|
||||
assert [row['event']['title'] for row in title_ascending.json()['results']] == [
|
||||
'Alpha Event', 'Bravo Event', 'Charlie Event',
|
||||
]
|
||||
assert [row['event']['title'] for row in title_descending.json()['results']] == [
|
||||
'Charlie Event', 'Bravo Event', 'Alpha Event',
|
||||
]
|
||||
assert invalid_sort.status_code == 422
|
||||
assert invalid_direction.status_code == 422
|
||||
|
||||
def test_list_event_registrations(self):
|
||||
event = self.event
|
||||
self._create_registration(event, self.user)
|
||||
|
||||
Reference in New Issue
Block a user