-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Unset primary schedule, fix PCx docs
- Loading branch information
1 parent
40563b6
commit 6be84c2
Showing
8 changed files
with
145 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
from rest_framework.test import APIClient | ||
|
||
from courses.models import Friendship | ||
from plan.models import Schedule | ||
from plan.models import PrimarySchedule, Schedule | ||
from tests.alert.test_alert import TEST_SEMESTER, set_semester | ||
from tests.courses.util import create_mock_data_with_reviews | ||
|
||
|
@@ -39,31 +39,60 @@ def setUp(self): | |
self.s2.save() | ||
self.s2.sections.set([self.cis121]) | ||
|
||
to_delete = Schedule( | ||
person=self.u1, | ||
semester=TEST_SEMESTER, | ||
name="My Test Schedule To Delete", | ||
) | ||
to_delete.save() | ||
self.deleted_schedule_id = to_delete.id | ||
to_delete.delete() | ||
|
||
self.client = APIClient() | ||
self.client.login(username="jacobily", password="top_secret") | ||
|
||
def test_put_primary_schedule(self): | ||
response = self.client.put(primary_schedule_url, {"schedule_id": self.s.id}) | ||
def assert_primary_schedule_id(self, client, user, schedule_id, num_primary=None): | ||
if schedule_id is None: | ||
self.assertEqual(PrimarySchedule.objects.filter(user=user).count(), 0) | ||
else: | ||
self.assertEqual(PrimarySchedule.objects.get(user=user).schedule_id, schedule_id) | ||
response = client.get(primary_schedule_url) | ||
self.assertEqual(response.status_code, 200) | ||
# self.assertEqual(response.json()["id"], self.s.id) | ||
# self.assertEqual(response.json()["name"], self.s.name) | ||
# self.assertEqual(response.json()["sections"][0]["id"], self.cis120.id) | ||
# self.assertEqual(response.json()["sections"][0]["course"]["id"], self.cis120.course.id) | ||
if num_primary is not None: | ||
self.assertEqual(len(response.json()), num_primary) | ||
if schedule_id is not None: | ||
self.assertIn(schedule_id, [p["schedule"]["id"] for p in response.json()]) | ||
|
||
def test_post_primary_schedule(self): | ||
response = self.client.post(primary_schedule_url, {"schedule_id": self.s.id}) | ||
self.assertEqual(response.status_code, 200) | ||
self.assert_primary_schedule_id(self.client, self.u1, self.s.id, num_primary=1) | ||
|
||
def test_invalid_schedule_id(self): | ||
response = self.client.post(primary_schedule_url, {"schedule_id": self.deleted_schedule_id}) | ||
self.assertEqual(response.status_code, 400) | ||
self.assert_primary_schedule_id(self.client, self.u1, None, num_primary=0) | ||
|
||
def test_replace_primary_schedule(self): | ||
response = self.client.put(primary_schedule_url, {"schedule_id": 123}) # invalid ID | ||
# self.assertEqual(response.status_code, 200) # todo: should be 400 | ||
response = self.client.post(primary_schedule_url, {"schedule_id": self.s.id}) | ||
self.assertEqual(response.status_code, 200) | ||
self.assert_primary_schedule_id(self.client, self.u1, self.s.id, num_primary=1) | ||
|
||
response = self.client.put(primary_schedule_url, {"schedule_id": self.s.id}) | ||
response = self.client.post(primary_schedule_url, {"schedule_id": self.s2.id}) | ||
self.assertEqual(response.status_code, 200) | ||
# self.assertEqual(response.data["id"], self.s.id) | ||
self.assert_primary_schedule_id(self.client, self.u1, self.s2.id, num_primary=1) | ||
|
||
response = self.client.put(primary_schedule_url, {"schedule_id": self.s2.id}) | ||
def test_unset_primary_schedule(self): | ||
response = self.client.post(primary_schedule_url, {"schedule_id": self.s.id}) | ||
self.assertEqual(response.status_code, 200) | ||
# self.assertEqual(response.data["id"], self.s2.id) | ||
self.assert_primary_schedule_id(self.client, self.u1, self.s.id, num_primary=1) | ||
|
||
response = self.client.post(primary_schedule_url, {"schedule_id": ""}) | ||
self.assertEqual(response.status_code, 200) | ||
self.assert_primary_schedule_id(self.client, self.u1, None, num_primary=0) | ||
|
||
def test_primary_schedule_friends(self): | ||
response = self.client.put(primary_schedule_url, {"schedule_id": self.s.id}) | ||
response = self.client.post(primary_schedule_url, {"schedule_id": self.s.id}) | ||
|
||
u2 = User.objects.create_user( | ||
username="jacob2", email="[email protected]", password="top_secret" | ||
|
@@ -84,16 +113,15 @@ def test_primary_schedule_friends(self): | |
) | ||
u2_s.save() | ||
u2_s.sections.set([self.cis120]) | ||
response = self.client2.put(primary_schedule_url, {"schedule_id": u2_s.id}) | ||
# self.assertEqual(response.status_code, 200) | ||
# self.assertEqual(response.data["id"], u2_s.id) | ||
response = self.client2.post(primary_schedule_url, {"schedule_id": u2_s.id}) | ||
self.assertEqual(response.status_code, 200) | ||
self.assert_primary_schedule_id(self.client2, u2, u2_s.id, num_primary=2) | ||
|
||
response = self.client.get(primary_schedule_url) | ||
self.assertEqual(response.status_code, 200) | ||
self.assertEqual(len(response.json()), 2) | ||
# print("1", response.json()) | ||
# self.assertEqual(response.data[0]["id"], self.s.id) | ||
# self.assertEqual(response.data[1]["id"], u2_s.id) | ||
self.assertIn(self.s.id, [p["schedule"]["id"] for p in response.json()]) | ||
self.assertIn(u2_s.id, [p["schedule"]["id"] for p in response.json()]) | ||
|
||
Friendship.objects.create(sender=self.u1, recipient=u3, status=Friendship.Status.ACCEPTED) | ||
u3_s = Schedule( | ||
|
@@ -110,22 +138,18 @@ def test_primary_schedule_friends(self): | |
self.assertEqual(len(response.json()), 2) | ||
|
||
# add a primary schedule for u3 | ||
response = self.client3.put(primary_schedule_url, {"schedule_id": u3_s.id}) | ||
response = self.client3.post(primary_schedule_url, {"schedule_id": u3_s.id}) | ||
self.assertEqual(response.status_code, 200) | ||
# self.assertEqual(response.data["id"], u3_s.id) | ||
self.assert_primary_schedule_id(self.client3, u3, u3_s.id, num_primary=2) | ||
|
||
# should have all 3 now | ||
response = self.client.get(primary_schedule_url) | ||
self.assertEqual(response.status_code, 200) | ||
self.assertEqual(len(response.json()), 3) | ||
# u1 should have all 3 now | ||
self.assert_primary_schedule_id(self.client, self.u1, self.s.id, num_primary=3) | ||
|
||
# remove u2 as a friend | ||
friendshipu2 = Friendship.objects.get(sender=self.u1, recipient=u2) | ||
friendshipu2.delete() | ||
|
||
# only have u1 and u3 now | ||
response = self.client.get(primary_schedule_url) | ||
self.assertEqual(response.status_code, 200) | ||
self.assertEqual(len(response.json()), 2) | ||
# self.assertEqual(response.data[0]["id"], self.s.id) | ||
# self.assertEqual(response.data[1]["id"], u3_s.id) | ||
self.assert_primary_schedule_id(self.client, self.u1, self.s.id, num_primary=2) | ||
self.assert_primary_schedule_id(self.client2, u2, u2_s.id, num_primary=1) | ||
self.assert_primary_schedule_id(self.client3, u3, u3_s.id, num_primary=2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.