Skip to content

Commit

Permalink
fix twostep after visiting onestep
Browse files Browse the repository at this point in the history
  • Loading branch information
uraniumanchor committed Dec 15, 2023
1 parent 902b470 commit 43788fb
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 78 deletions.
1 change: 1 addition & 0 deletions bundles/processing/modules/processing/ActionLog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ function ActionEntry({ action }: { action: HistoryAction }) {
// eslint-disable-next-line react/jsx-no-bind
onPress={() => unprocess.mutate(action.donationId)}
isDisabled={unprocess.isLoading}
aria-name="undo"
aria-label="Undo this action and bring the donation back to the main view">
<Undo />
</Button>
Expand Down
4 changes: 3 additions & 1 deletion bundles/processing/pages/ProcessDonations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,10 @@ function Sidebar(props: SidebarProps) {
React.useEffect(() => {
if (event?.use_one_step_screening) {
setProcessingMode('onestep');
} else if (event && !event.use_one_step_screening && processingMode === 'onestep') {
setProcessingMode('flag');
}
}, [event, setProcessingMode, canSendToReader]);
}, [event, setProcessingMode, processingMode]);

const handleApprovalModeChanged = React.useCallback(
(mode: ProcessingMode) => {
Expand Down
23 changes: 17 additions & 6 deletions tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,20 @@ def setUp(self):
self.donation.save()

def test_one_step_screening(self):
self.event.use_one_step_screening = True
self.event.save()
self.tracker_login(self.processor.username)
self.webdriver.get(
f'{self.live_server_url}{reverse("admin:process_donations")}'
)
row = self.webdriver.find_element(
By.CSS_SELECTOR, f'div[data-test-pk="{self.donation.pk}"]'
)
row.find_element(By.CSS_SELECTOR, 'button[data-test-id="send"]').click()
self.wait_for_element_gone(f'div[data-test-pk="{self.donation.pk}"]')
row.find_element(
By.CSS_SELECTOR,
f'button[data-test-id="send"]',
).click()
self.webdriver.find_element(By.CSS_SELECTOR, f'button[aria-name="undo"]')
self.donation.refresh_from_db()
self.assertEqual(self.donation.readstate, 'READY')

Expand All @@ -96,8 +101,11 @@ def test_two_step_screening(self):
row = self.webdriver.find_element(
By.CSS_SELECTOR, f'div[data-test-pk="{self.donation.pk}"]'
)
row.find_element(By.CSS_SELECTOR, 'button[data-test-id="send"]').click()
self.wait_for_element_gone(f'div[data-test-pk="{self.donation.pk}"]')
row.find_element(
By.CSS_SELECTOR,
f'button[data-test-id="send"]',
).click()
self.webdriver.find_element(By.CSS_SELECTOR, f'button[aria-name="undo"]')
self.donation.refresh_from_db()
self.assertEqual(self.donation.readstate, 'FLAGGED')
self.tracker_logout()
Expand All @@ -109,8 +117,11 @@ def test_two_step_screening(self):
row = self.webdriver.find_element(
By.CSS_SELECTOR, f'div[data-test-pk="{self.donation.pk}"]'
)
row.find_element(By.CSS_SELECTOR, 'button[data-test-id="send"]').click()
self.wait_for_element_gone(f'div[data-test-pk="{self.donation.pk}"]')
row.find_element(
By.CSS_SELECTOR,
f'button[data-test-id="send"]',
).click()
self.webdriver.find_element(By.CSS_SELECTOR, f'button[aria-name="undo"]')
self.donation.refresh_from_db()
self.assertEqual(self.donation.readstate, 'READY')

Expand Down
6 changes: 1 addition & 5 deletions tests/test_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,12 @@
from django.urls import reverse

from tracker import models, settings
from tracker.compat import zoneinfo
from tracker.util import utcnow

from . import randgen
from .util import long_ago_noon, today_noon, tomorrow_noon

try:
import zoneinfo
except ImportError:
from backports import zoneinfo


class TestEvent(TestCase):
def setUp(self):
Expand Down
7 changes: 1 addition & 6 deletions tests/test_speedrun.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,11 @@

import tracker.models as models
from tracker import settings
from tracker.util import pairwise
from tracker.compat import pairwise, zoneinfo

from . import randgen
from .util import today_noon

try:
import zoneinfo
except ImportError:
from backports import zoneinfo


class TestSpeedRunBase(TransactionTestCase):
def setUp(self):
Expand Down
29 changes: 10 additions & 19 deletions tests/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import itertools
import json
import logging
import os
import random
import sys
import time
Expand All @@ -25,11 +26,7 @@

from tracker import models, settings
from tracker.api.pagination import TrackerPagination

try:
import zoneinfo
except ImportError:
from backports import zoneinfo
from tracker.compat import zoneinfo


def parse_test_mail(mail):
Expand Down Expand Up @@ -616,7 +613,8 @@ class TrackerSeleniumTestCase(StaticLiveServerTestCase, metaclass=_TestFailedMet
def setUpClass(cls):
super().setUpClass()
options = Options()
options.add_argument('--headless')
if not bool(int(os.environ.get('TRACKER_DISABLE_HEADLESS', '0'))):
options.add_argument('--headless')
cls.webdriver = webdriver.Firefox(options=options)
cls.webdriver.implicitly_wait(5)

Expand All @@ -627,13 +625,15 @@ def tearDownClass(cls):

def tearDown(self):
super().tearDown()
self.tracker_logout()
if self.test_failed:
self.webdriver.get_screenshot_as_file(
f'./test-results/TEST-{self.id()}.{int(time.time())}.png'
)
raise Exception(
f'{self.webdriver.current_url}\ndata:image/png;base64,{self.webdriver.get_screenshot_as_base64()}'
)
if not bool(int(os.environ.get('TRACKER_DISABLE_DUMP', '0'))):
raise Exception(
f'{self.webdriver.current_url}\ndata:image/png;base64,{self.webdriver.get_screenshot_as_base64()}'
)

def tracker_login(self, username, password='password'):
self.webdriver.get(self.live_server_url + reverse('admin:login'))
Expand All @@ -645,11 +645,7 @@ def tracker_login(self, username, password='password'):
) # admin page has loaded

def tracker_logout(self):
self.webdriver.get(self.live_server_url + reverse('admin:logout'))
self.assertEqual(
self.webdriver.find_element(By.CSS_SELECTOR, '#content h1').text,
'Logged out',
)
self.webdriver.delete_cookie(settings.SESSION_COOKIE_NAME)

def select_option(self, selector, value):
Select(self.webdriver.find_element(By.CSS_SELECTOR, selector)).select_by_value(
Expand All @@ -662,8 +658,3 @@ def wait_for_spinner(self):
(By.CSS_SELECTOR, '[data-test-id="spinner"]')
)
)

def wait_for_element_gone(self, selector):
WebDriverWait(self.webdriver, 5).until_not(
EC.presence_of_element_located((By.CSS_SELECTOR, selector))
)
6 changes: 1 addition & 5 deletions tracker/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
import logging
from collections import defaultdict
from contextlib import contextmanager

try:
from functools import cached_property
except ImportError:
from backports.cached_property import cached_property
from functools import cached_property

from django.core.exceptions import NON_FIELD_ERRORS, ValidationError
from django.utils.translation import gettext_lazy as _
Expand Down
28 changes: 14 additions & 14 deletions tracker/api/views/donations.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def get_serializer(self, *args, **kwargs):
*args, with_permissions=self.request.user.get_all_permissions(), **kwargs
)

def list(self, *_, **__):
def list(self, request):
"""
Return a list of donations matching the given IDs, provided as a series
of `ids[]` query parameters, up to a maximum of TRACKER_PAGINATION_LIMIT.
Expand All @@ -161,7 +161,7 @@ def list(self, *_, **__):
return Response(serializer.data)

@action(detail=False, methods=['get'], permission_classes=[CanViewComments])
def unprocessed(self, *_, **__):
def unprocessed(self, request):
"""
Return a list of the oldest completed donations for the event which have
not yet been processed in any way (e.g., are still PENDING for comment
Expand All @@ -177,7 +177,7 @@ def unprocessed(self, *_, **__):
return Response(serializer.data)

@action(detail=False, methods=['get'], permission_classes=[CanViewComments])
def flagged(self, *_, **__):
def flagged(self, request):
"""
Return a list of the oldest completed donations for the event which have
been flagged for head review (e.g., are FLAGGED for read moderation),
Expand All @@ -193,7 +193,7 @@ def flagged(self, *_, **__):
return Response(serializer.data)

@action(detail=False, methods=['get'], permission_classes=[CanViewComments])
def unread(self, *_, **__):
def unread(self, request):
"""
Return a list of the oldest completed donations for the event which have
been approved and sent to the reader (e.g., have a READY readstate),
Expand All @@ -209,7 +209,7 @@ def unread(self, *_, **__):
return Response(serializer.data)

@action(detail=True, methods=['patch'], permission_classes=[CanChangeDonation])
def unprocess(self, *_, **__):
def unprocess(self, request, pk):
"""
Reset the comment and read states for the donation.
"""
Expand All @@ -223,7 +223,7 @@ def unprocess(self, *_, **__):
return Response(data)

@action(detail=True, methods=['patch'], permission_classes=[CanChangeDonation])
def approve_comment(self, *_, **__):
def approve_comment(self, request, pk):
"""
Mark the comment for the donation as approved, but do not send it on to
be read.
Expand All @@ -238,7 +238,7 @@ def approve_comment(self, *_, **__):
return Response(data)

@action(detail=True, methods=['patch'], permission_classes=[CanChangeDonation])
def deny_comment(self, *_, **__):
def deny_comment(self, request, pk):
"""
Mark the comment for the donation as explicitly denied and ignored.
"""
Expand All @@ -252,7 +252,7 @@ def deny_comment(self, *_, **__):
return Response(data)

@action(detail=True, methods=['patch'], permission_classes=[CanChangeDonation])
def flag(self, *_, **__):
def flag(self, request, pk):
"""
Mark the donation as approved, but flagged for head donations to review
before sending to the reader. This should only be called when the event
Expand All @@ -272,7 +272,7 @@ def flag(self, *_, **__):
methods=['patch'],
permission_classes=[CanSendToReader],
)
def send_to_reader(self, *_, **__):
def send_to_reader(self, request, pk):
"""
Mark the donation as approved and send it directly to the reader.
"""
Expand All @@ -286,7 +286,7 @@ def send_to_reader(self, *_, **__):
return Response(data)

@action(detail=True, methods=['patch'], permission_classes=[CanChangeDonation])
def pin(self, *_, **__):
def pin(self, request, pk):
"""
Mark the donation as pinned to the top of the reader's view.
"""
Expand All @@ -299,7 +299,7 @@ def pin(self, *_, **__):
return Response(data)

@action(detail=True, methods=['patch'], permission_classes=[CanChangeDonation])
def unpin(self, *_, **__):
def unpin(self, request, pk):
"""
Umark the donation as pinned, returning it to a normal position in the donation list.
"""
Expand All @@ -312,7 +312,7 @@ def unpin(self, *_, **__):
return Response(data)

@action(detail=True, methods=['patch'], permission_classes=[CanChangeDonation])
def read(self, *_, **__):
def read(self, request, pk):
"""
Mark the donation as read, completing the donation's lifecycle.
"""
Expand All @@ -325,7 +325,7 @@ def read(self, *_, **__):
return Response(data)

@action(detail=True, methods=['patch'], permission_classes=[CanChangeDonation])
def ignore(self, *_, **__):
def ignore(self, request, pk):
"""
Mark the donation as ignored, completing the donation's lifecycle.
"""
Expand All @@ -338,7 +338,7 @@ def ignore(self, *_, **__):
return Response(data)

@action(detail=True, methods=['patch'], permission_classes=[CanChangeDonation])
def comment(self, request, *_, **__):
def comment(self, request, pk):
"""
Add or edit the `modcomment` for the donation. Currently donations only
store a single comment; providing a new comment will override whatever
Expand Down
20 changes: 20 additions & 0 deletions tracker/compat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
try:
import zoneinfo
except ImportError:
# TODO: remove when 3.9 is oldest supported version

# noinspection PyUnresolvedReferences
from backports import zoneinfo # noqa: F401

try:
from itertools import pairwise
except ImportError:
# TODO: remove when 3.10 is oldest supported version

def pairwise(iterable):
import itertools

# pairwise('ABCDEFG') --> AB BC CD DE EF FG
a, b = itertools.tee(iterable)
next(b, None)
return zip(a, b)
5 changes: 3 additions & 2 deletions tracker/models/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
from django.urls import reverse
from timezone_field import TimeZoneField

from tracker import compat, util
from tracker.validators import nonzero, positive

from .. import util
from .fields import TimestampField
from .util import LatestEvent

Expand Down Expand Up @@ -558,7 +558,7 @@ def clean(self):
'order': 'Next anchor in the order would occur before this one'
}
)
for c, n in util.pairwise(
for c, n in compat.pairwise(
itertools.chain(
[self],
SpeedRun.objects.filter(
Expand Down Expand Up @@ -853,6 +853,7 @@ def validate_unique(self, exclude=None):
super(Headset, self).validate_unique(exclude)
except ValidationError as e:
if case_insensitive:
# FIXME: does this actually work?
e.error_dict.setdefault('name', []).append(
self.unique_error_message(Headset, ['name'])
)
Expand Down
Loading

0 comments on commit 43788fb

Please sign in to comment.