format files with black
This commit is contained in:
+26
-26
@@ -13,28 +13,30 @@ URL = "/api/events/"
|
||||
|
||||
|
||||
class EventTestCase(APITestCase):
|
||||
|
||||
def setUp(self):
|
||||
# Visible and relevant
|
||||
test1 = createEventObject(
|
||||
"Testitapahtuma1",
|
||||
start_time=timezone.datetime(2019, 11, 9, 12, 0, 0))
|
||||
"Testitapahtuma1", start_time=timezone.datetime(2019, 11, 9, 12, 0, 0)
|
||||
)
|
||||
# Invisible but relevant
|
||||
createEventObject(
|
||||
"Testitapahtuma2",
|
||||
visible=False,
|
||||
start_time=timezone.datetime(2018, 11, 9, 12, 0, 0))
|
||||
start_time=timezone.datetime(2018, 11, 9, 12, 0, 0),
|
||||
)
|
||||
# Visible but unrelevant
|
||||
test2 = createEventObject(
|
||||
"Testitapahtuma3",
|
||||
visible=True,
|
||||
start_time=timezone.datetime(2018, 12, 9, 12, 0, 0),
|
||||
end_time=timezone.datetime(2018, 12, 9, 13, 0, 0))
|
||||
end_time=timezone.datetime(2018, 12, 9, 13, 0, 0),
|
||||
)
|
||||
# Visible and relevant
|
||||
createEventObject(
|
||||
"Testitapahtuma4",
|
||||
visible=True,
|
||||
start_time=timezone.datetime(2018, 12, 9, 12, 0, 0))
|
||||
start_time=timezone.datetime(2018, 12, 9, 12, 0, 0),
|
||||
)
|
||||
# Add some tags
|
||||
tag1 = tagBuilder()
|
||||
tag2 = tagBuilder("testtag2")
|
||||
@@ -47,7 +49,9 @@ class EventTestCase(APITestCase):
|
||||
self.signupFormId = createSignupForm().id
|
||||
|
||||
username, password = "test_admin", "password123"
|
||||
self.authClient = User.objects.create_superuser(username, "myemail@test.com", password)
|
||||
self.authClient = User.objects.create_superuser(
|
||||
username, "myemail@test.com", password
|
||||
)
|
||||
|
||||
def test_get_current_events(self):
|
||||
# Get from API
|
||||
@@ -60,11 +64,11 @@ class EventTestCase(APITestCase):
|
||||
req = APIRequestFactory().get(r"http://testserver/api/events/")
|
||||
req.user = AnonymousUser()
|
||||
serializer = EventSerializer(
|
||||
Event.objects.filter(title_fi__in=("Testitapahtuma1", "Testitapahtuma4")).order_by("start_time"),
|
||||
Event.objects.filter(
|
||||
title_fi__in=("Testitapahtuma1", "Testitapahtuma4")
|
||||
).order_by("start_time"),
|
||||
many=True,
|
||||
context={
|
||||
"request": req
|
||||
}
|
||||
context={"request": req},
|
||||
)
|
||||
expected = serializer.data
|
||||
# TODO: Couldn't figure out how to fill filtered_signup_forms used by prefetch for the test...
|
||||
@@ -80,11 +84,11 @@ class EventTestCase(APITestCase):
|
||||
req = APIRequestFactory().get(r"http://testserver/api/events/")
|
||||
req.user = AnonymousUser()
|
||||
serializer = EventSerializer(
|
||||
Event.objects.filter(title_fi__in=("Testitapahtuma1", "Testitapahtuma3", "Testitapahtuma4")).order_by("start_time"),
|
||||
Event.objects.filter(
|
||||
title_fi__in=("Testitapahtuma1", "Testitapahtuma3", "Testitapahtuma4")
|
||||
).order_by("start_time"),
|
||||
many=True,
|
||||
context={
|
||||
"request": req
|
||||
}
|
||||
context={"request": req},
|
||||
)
|
||||
expected = serializer.data
|
||||
# TODO: Couldn't figure out how to fill filtered_signup_forms used by prefetch for the test...
|
||||
@@ -119,7 +123,7 @@ class EventTestCase(APITestCase):
|
||||
response = self.client.post(
|
||||
URL,
|
||||
createEventJSON(tag_id=[self.testTagId], signup_id=[self.signupFormId]),
|
||||
format="json"
|
||||
format="json",
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
|
||||
@@ -129,7 +133,7 @@ class EventTestCase(APITestCase):
|
||||
response = self.client.post(
|
||||
URL,
|
||||
createEventJSON(tag_id=[self.testTagId], signup_id=[self.signupFormId]),
|
||||
format="json"
|
||||
format="json",
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
|
||||
@@ -140,11 +144,7 @@ class EventTestCase(APITestCase):
|
||||
self.client.force_authenticate(user=self.authClient)
|
||||
event = Event.objects.get(id=self.testEventId)
|
||||
new = createEventJSON(name="Update1", signup_id=[self.signupFormId])
|
||||
response = self.client.put(
|
||||
f"{URL}{self.testEventId}/",
|
||||
new,
|
||||
format="json"
|
||||
)
|
||||
response = self.client.put(f"{URL}{self.testEventId}/", new, format="json")
|
||||
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
event = Event.objects.get(id=self.testEventId)
|
||||
@@ -153,9 +153,7 @@ class EventTestCase(APITestCase):
|
||||
|
||||
def test_update_event_unauth(self):
|
||||
response = self.client.put(
|
||||
f"{URL}{self.testEventId}/",
|
||||
createEventJSON(name="Update1"),
|
||||
format="json"
|
||||
f"{URL}{self.testEventId}/", createEventJSON(name="Update1"), format="json"
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
|
||||
@@ -164,7 +162,9 @@ class EventTestCase(APITestCase):
|
||||
self.assertEqual(Event.objects.count(), 4)
|
||||
|
||||
def test_delete_event(self):
|
||||
response = self.client.delete(f"{URL}{self.testEventId}/",)
|
||||
response = self.client.delete(
|
||||
f"{URL}{self.testEventId}/",
|
||||
)
|
||||
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
|
||||
self.assertEqual(Event.objects.count(), 4)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user