Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrated linter fix - (Built on django-migrate and NOT main) #312

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions .github/workflows/shared-build-deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@ name: Build and Deploy OHQ
on: push

jobs:
# backend-check:
# name: "Backend Check"
# uses: pennlabs/shared-actions/.github/workflows/[email protected]
# with:
# projectName: officehoursqueue
# path: backend
# flake: true
# black: true
backend-check:
benjmnxu marked this conversation as resolved.
Show resolved Hide resolved
name: "Backend Check"
benjmnxu marked this conversation as resolved.
Show resolved Hide resolved
uses: pennlabs/shared-actions/.github/workflows/django.yaml@507f4cf1cc88259fc8625fb3a35bd3f18fc91cd5
secrets: inherit
with:
projectName: officehoursqueue
path: backend
pythonVersion: 3.11
flake: true
black: true
ruff: false

publish-backend:
uses: pennlabs/shared-actions/.github/workflows/[email protected]
Expand Down Expand Up @@ -86,4 +89,4 @@ jobs:

needs:
- publish-backend
- publish-frontend
- publish-frontend
1 change: 1 addition & 0 deletions backend/Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ gunicorn = "*"
django-scheduler = "*"
typing-extensions = "*"
drf-excel = "*"
coverage = "*"

[requires]
python_version = "3.11"
61 changes: 60 additions & 1 deletion backend/Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion backend/ohq/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ class QuestionSearchFilter(filters.FilterSet):

class Meta:
model = Question
fields = {"time_asked": ["gt", "lt"], "queue": ["exact"], "status": ["exact"], "time_responded_to": ["gt", "lt"]}
fields = {
"time_asked": ["gt", "lt"],
"queue": ["exact"],
"status": ["exact"],
"time_responded_to": ["gt", "lt"],
}

def search_filter(self, queryset, name, value):
return queryset.filter(
Expand Down
9 changes: 6 additions & 3 deletions backend/ohq/statistics.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.contrib.auth import get_user_model
from django.db.models import Avg, Case, Count, F, Sum, When, FloatField, ExpressionWrapper
from django.db.models import Avg, Case, Count, ExpressionWrapper, F, FloatField, Sum, When
from django.db.models.functions import TruncDate
from django.utils import timezone

Expand Down Expand Up @@ -217,8 +217,11 @@ def queue_calculate_questions_per_ta_heatmap(queue, weekday, hour):
questions=Count("date", distinct=False),
tas=Count("responded_to_by", distinct=True),
)
.annotate(
q_per_ta=Case(When(tas=0, then=ExpressionWrapper(F("questions"), output_field=FloatField())), default=1.0 * F("questions") / F("tas")),
.annotate(
q_per_ta=Case(
When(tas=0, then=ExpressionWrapper(F("questions"), output_field=FloatField())),
default=1.0 * F("questions") / F("tas"),
),
)
.aggregate(avg=Avg(F("q_per_ta"), output_field=FloatField()))
)
Expand Down
6 changes: 3 additions & 3 deletions backend/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ multi_line_output = 3
include_trailing_comma = True
use_parentheses = True

# [coverage:run]
# omit = */tests/*, */migrations/*, */settings/*, */asgi.py, */wsgi.py, */apps.py, */schemas.py, */.venv/*, manage.py, */management/commands/populate.py
# source = .
[coverage:run]
omit = */tests/*, */migrations/*, */settings/*, */asgi.py, */wsgi.py, */apps.py, */schemas.py, */.venv/*, manage.py, */management/commands/populate.py
source = .

[uwsgi]
http-socket = :80
Expand Down
2 changes: 1 addition & 1 deletion backend/tests/ohq/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ def test_questions_per_ta_computation(self):
day=(yesterday_weekday + 1) % 7 + 1,
hour=8,
).value

self.assertEqual(expected_8, actual_8)

expected_17 = (self.ta_1_questions_17 + self.ta_2_questions_17) / self.num_tas_17
Expand Down
14 changes: 9 additions & 5 deletions backend/tests/ohq/test_live.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from asgiref.sync import sync_to_async
from channels.auth import AuthMiddlewareStack
from channels.db import database_sync_to_async as db
from channels.testing import WebsocketCommunicator
from django.contrib.auth import get_user_model
from django.test import TransactionTestCase
from django.urls import reverse
Expand All @@ -13,7 +14,6 @@
from ohq.models import Announcement, Course, Membership, Question, Queue, Semester
from ohq.serializers import AnnouncementSerializer
from ohq.urls import realtime_router
from channels.testing import WebsocketCommunicator


User = get_user_model()
Expand Down Expand Up @@ -45,7 +45,9 @@ async def asyncSetUp(self):
)

headers = await get_headers_for_user(self.student2)
self.client = WebsocketCommunicator(AuthMiddlewareStack(realtime_router.as_consumer().as_asgi()), "/ws/subscribe/", headers)
self.client = WebsocketCommunicator(
AuthMiddlewareStack(realtime_router.as_consumer().as_asgi()), "/ws/subscribe/", headers
)
connected, _ = await self.client.connect()
self.assertTrue(connected)

Expand Down Expand Up @@ -76,7 +78,7 @@ async def testPositionUpdate(self):
question_position = 2
response = await self.client.receive_json_from()

self.assertEquals(question_position, response["instance"]["position"])
self.assertEqual(question_position, response["instance"]["position"])

retrieve_payload = {
"type": "subscribe",
Expand All @@ -100,7 +102,7 @@ async def testPositionUpdate(self):
question_position -= 1

response = await self.client.receive_json_from()
self.assertEquals(question_position, response["instance"]["position"])
self.assertEqual(question_position, response["instance"]["position"])


class AnnouncementTestCase(TransactionTestCase):
Expand All @@ -119,7 +121,9 @@ async def asyncSetUp(self):
)

headers = await get_headers_for_user(self.student)
self.client = WebsocketCommunicator(AuthMiddlewareStack(realtime_router.as_consumer().as_asgi()), "/ws/subscribe/", headers)
self.client = WebsocketCommunicator(
AuthMiddlewareStack(realtime_router.as_consumer().as_asgi()), "/ws/subscribe/", headers
)
connected, _ = await self.client.connect()
self.assertTrue(connected)

Expand Down
30 changes: 15 additions & 15 deletions backend/tests/ohq/test_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def test_generate_pin(self):
reverse("ohq:queue-detail", args=[self.course.id, self.queue.id]), {"active": True}
)
self.queue.refresh_from_db()
self.assertEquals(old_pin, self.queue.pin)
self.assertEqual(old_pin, self.queue.pin)

# queue with pin enabled generates new pin
self.queue.pin_enabled = True
Expand All @@ -215,7 +215,7 @@ def test_generate_pin(self):
reverse("ohq:queue-detail", args=[self.course.id, self.queue.id]), {"active": True}
)
self.queue.refresh_from_db()
self.assertNotEquals(old_pin, self.queue.pin)
self.assertNotEqual(old_pin, self.queue.pin)

self.queue.active = False
self.queue.save()
Expand All @@ -225,7 +225,7 @@ def test_generate_pin(self):
reverse("ohq:queue-detail", args=[self.course.id, self.queue.id]), {"active": True}
)
self.queue.refresh_from_db()
self.assertNotEquals(old_pin, self.queue.pin)
self.assertNotEqual(old_pin, self.queue.pin)

# TAs+ (but not student) can change pin
self.queue.pin_enabled = True
Expand All @@ -237,7 +237,7 @@ def test_generate_pin(self):
{"pin": manual_update_pin},
)
self.queue.refresh_from_db()
self.assertEquals(manual_update_pin, self.queue.pin)
self.assertEqual(manual_update_pin, self.queue.pin)

self.queue.pin = self.pin
self.queue.save()
Expand All @@ -247,8 +247,8 @@ def test_generate_pin(self):
{"pin": manual_update_pin},
)
self.queue.refresh_from_db()
self.assertNotEquals(manual_update_pin, self.queue.pin)
self.assertEquals(self.pin, self.queue.pin)
self.assertNotEqual(manual_update_pin, self.queue.pin)
self.assertEqual(self.pin, self.queue.pin)

def test_get_pin(self):
"""
Expand All @@ -268,7 +268,7 @@ def test_get_pin(self):
reverse("ohq:queue-detail", args=[self.course.id, self.pin_queue.id])
)
content = json.loads(response.content)
self.assertEquals(content["pin"], self.pin)
self.assertEqual(content["pin"], self.pin)


@patch("ohq.serializers.sendUpNextNotificationTask.delay")
Expand Down Expand Up @@ -650,8 +650,8 @@ def test_update(self):
},
)
event = Event.objects.all().first()
self.assertEquals(event.title, self.new_title)
self.assertEquals(event.rule.frequency, "MONTHLY")
self.assertEqual(event.title, self.new_title)
self.assertEqual(event.rule.frequency, "MONTHLY")
# student cannot make changes
self.client.force_authenticate(user=self.student)
self.client.patch(
Expand All @@ -660,8 +660,8 @@ def test_update(self):
)
event = Event.objects.all().first()
# title has not changed
self.assertEquals(event.title, self.new_title)
self.assertEquals(event.rule.frequency, "MONTHLY")
self.assertEqual(event.title, self.new_title)
self.assertEqual(event.rule.frequency, "MONTHLY")

def test_update_no_rule(self):
"""
Expand All @@ -686,7 +686,7 @@ def test_update_no_rule(self):
{"title": self.new_title, "courseId": self.course.id},
)
event = Event.objects.all().first()
self.assertEquals(event.title, self.new_title)
self.assertEqual(event.title, self.new_title)

def test_list(self):
"""
Expand Down Expand Up @@ -721,6 +721,6 @@ def test_list(self):
+ str(self.course.id)
)
data = json.loads(response.content)
self.assertEquals(2, len(data))
self.assertEquals(self.course.id, data[0]["course_id"])
self.assertEquals(self.course.id, data[1]["course_id"])
self.assertEqual(2, len(data))
self.assertEqual(self.course.id, data[0]["course_id"])
self.assertEqual(self.course.id, data[1]["course_id"])
18 changes: 9 additions & 9 deletions backend/tests/ohq/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ def test_list(self):
+ self.filter_end
)
occurrences = json.loads(response.content)
self.assertEquals(2, len(occurrences))
self.assertEqual(2, len(occurrences))

def test_cancel(self):
self.client.force_authenticate(user=self.ta)
Expand Down Expand Up @@ -376,7 +376,7 @@ def test_no_rule(self):
+ self.filter_end
)
occurrences = json.loads(response.content)
self.assertEquals(1, len(occurrences))
self.assertEqual(1, len(occurrences))

# calling twice doesn't create more occurrences
response = self.client.get(
Expand All @@ -388,9 +388,9 @@ def test_no_rule(self):
+ self.filter_end
)
occurrences = json.loads(response.content)
self.assertEquals(1, len(occurrences))
self.assertEqual(1, len(occurrences))
cnt = Occurrence.objects.all().count()
self.assertEquals(1, cnt)
self.assertEqual(1, cnt)

def test_update_start(self):
self.client.force_authenticate(user=self.ta)
Expand All @@ -416,8 +416,8 @@ def test_update_start(self):
+ filter_end
)
occurrences = json.loads(response.content)
self.assertEquals(2, len(occurrences))
self.assertEquals(occurrences[0]["start"], self.start_time)
self.assertEqual(2, len(occurrences))
self.assertEqual(occurrences[0]["start"], self.start_time)
# update event's start day should update occurrences
event = Event.objects.all().first()
new_start_date = "2021-12-07T12:40:37Z"
Expand All @@ -432,7 +432,7 @@ def test_update_start(self):
},
)
event = Event.objects.all().first()
self.assertEquals(event.title, "New TA Session")
self.assertEqual(event.title, "New TA Session")
response = self.client.get(
"/api/occurrences/?course="
+ str(self.course.id)
Expand All @@ -442,5 +442,5 @@ def test_update_start(self):
+ filter_end
)
occurrences = json.loads(response.content)
self.assertEquals(1, len(occurrences))
self.assertEquals(occurrences[0]["start"], new_start_date)
self.assertEqual(1, len(occurrences))
self.assertEqual(occurrences[0]["start"], new_start_date)
Loading