-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'rookie-subletting' of https://github.com/pennlabs/penn-…
…mobile into rookie-subletting
- Loading branch information
Showing
1 changed file
with
57 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -118,6 +118,9 @@ def test_browse_sublet(self): | |
class TestOffers(TestCase): | ||
"""Tests Create/Delete/List for offers""" | ||
|
||
# TODO: test create offer fails when offer is duplicate | ||
# TODO: delete offer fails when offer doesn't exist | ||
|
||
def setUp(self): | ||
self.user = User.objects.create_user("user", "[email protected]", "user") | ||
self.client = APIClient() | ||
|
@@ -194,7 +197,7 @@ def test_get_offers_property(self): | |
response = self.client.get("/sublet/properties/1/offers/") | ||
res_json = json.loads(response.content) | ||
self.assertEqual(2, len(res_json)) | ||
# TODO: his is really ugly, will clean up later haha | ||
# TODO: this is really ugly, will clean up later haha | ||
offer = res_json[0] | ||
self.assertEqual(offer["email"], "[email protected]") | ||
self.assertEqual(offer["phone_number"], "1234567890") | ||
|
@@ -255,4 +258,56 @@ def test_get_offer_user(self): | |
class TestFavorites(TestCase): | ||
"""Tests Create/Delete/List for favorites""" | ||
|
||
pass | ||
def setUp(self): | ||
self.user = User.objects.create_user("user", "[email protected]", "user") | ||
self.client = APIClient() | ||
self.client.force_authenticate(user=self.user) | ||
test_user = User.objects.create_user("user1", "user") | ||
for i in range(1, 6): | ||
Amenity.objects.create(name=f"Amenity{str(i)}") | ||
# TODO: Not sure how to add these amenities to the sublets, but not important for now | ||
with open("tests/sublet/mock_sublets.json") as data: | ||
data = json.load(data) | ||
sublet1 = Sublet.objects.create(subletter=self.user, **data[0]) | ||
sublet2 = Sublet.objects.create(subletter=test_user, **data[1]) | ||
|
||
def test_create_favorite(self): | ||
response = self.client.post("/sublet/properties/2/favorites/") | ||
self.assertTrue(self.user.sublets_favorited.filter(pk=2).exists()) | ||
self.assertFalse(self.user.sublets_favorited.filter(pk=1).exists()) | ||
# TODO: Write case for erroring out on already favorited once that's been implemented | ||
response = self.client.post("/sublet/properties/1/favorites/") | ||
self.assertTrue(self.user.sublets_favorited.filter(pk=2).exists()) | ||
self.assertTrue(self.user.sublets_favorited.filter(pk=1).exists()) | ||
|
||
def test_delete_favorite(self): | ||
self.client.post("/sublet/properties/2/favorites/") | ||
self.client.post("/sublet/properties/1/favorites/") | ||
response = self.client.delete("/sublet/properties/1/favorites/") | ||
self.assertTrue(self.user.sublets_favorited.filter(pk=2).exists()) | ||
self.assertFalse(self.user.sublets_favorited.filter(pk=1).exists()) | ||
response = self.client.post("/sublet/properties/1/favorites/") | ||
self.assertTrue(self.user.sublets_favorited.filter(pk=2).exists()) | ||
self.assertTrue(self.user.sublets_favorited.filter(pk=1).exists()) | ||
response = self.client.delete("/sublet/properties/1/favorites/") | ||
self.assertTrue(self.user.sublets_favorited.filter(pk=2).exists()) | ||
self.assertFalse(self.user.sublets_favorited.filter(pk=1).exists()) | ||
response = self.client.delete("/sublet/properties/2/favorites/") | ||
self.assertFalse(self.user.sublets_favorited.filter(pk=2).exists()) | ||
self.assertFalse(self.user.sublets_favorited.filter(pk=1).exists()) | ||
|
||
def test_get_favorite_user(self): | ||
self.client.post("/sublet/properties/2/favorites/") | ||
response = self.client.get("/sublet/favorites/") | ||
res_json = json.loads(response.content) | ||
self.assertEqual(len(res_json), 1) | ||
self.assertEqual(res_json[0]["id"], 2) | ||
self.client.post("/sublet/properties/1/favorites/") | ||
response = self.client.get("/sublet/favorites/") | ||
res_json = json.loads(response.content) | ||
self.assertEqual(len(res_json), 2) | ||
self.client.delete("/sublet/properties/2/favorites/") | ||
response = self.client.get("/sublet/favorites/") | ||
res_json = json.loads(response.content) | ||
self.assertEqual(len(res_json), 1) | ||
self.assertEqual(res_json[0]["id"], 1) |