Skip to content

Commit

Permalink
🌉 extend pre-commit rules
Browse files Browse the repository at this point in the history
  • Loading branch information
ashleyzhang01 committed Nov 14, 2024
1 parent 1b10057 commit f6034f9
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 10 deletions.
4 changes: 3 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,6 @@ repos:
--warn-redundant-casts,
--no-implicit-optional,
--strict-optional,
]
--warn-unused-ignores,
--disallow-incomplete-defs,
]
1 change: 1 addition & 0 deletions backend/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ max-line-length = 100
exclude = .venv, migrations
inline-quotes = double
ignore = E203, W503, E704
extend-select = F841, F401

[isort]
default_section = THIRDPARTY
Expand Down
4 changes: 1 addition & 3 deletions backend/sublet/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@

class SubletAdmin(admin.ModelAdmin):
def image_tag(self, instance: Sublet) -> SafeText:
images = [
'<img src="%s" height="150" />' for image in instance.images.all() # type: ignore
]
images = ['<img src="%s" height="150" />' for image in instance.images.all()]
return mark_safe("<br>".join(images))

image_tag.short_description = "Sublet Images" # type: ignore[attr-defined]
Expand Down
3 changes: 3 additions & 0 deletions backend/sublet/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.contrib.auth import get_user_model
from django.db import models
from django.db.models import QuerySet
from phonenumber_field.modelfields import PhoneNumberField


Expand Down Expand Up @@ -59,6 +60,8 @@ class Sublet(models.Model):
start_date: models.DateField = models.DateField()
end_date: models.DateField = models.DateField()

images: QuerySet

def __str__(self) -> str:
return f"{self.title} by {self.subletter}"

Expand Down
2 changes: 1 addition & 1 deletion backend/tests/gsr_booking/test_gsr_booking.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def setUp(self) -> None:

self.group = Group.objects.create(owner=self.user1, name="g1", color="blue")
self.group.members.add(self.user1)
memship = self.group.memberships.all()[0] # type: ignore
memship = self.group.memberships.all()[0]
memship.accepted = True
memship.save()
self.client: APIClient = APIClient()
Expand Down
14 changes: 9 additions & 5 deletions backend/tests/sublet/test_sublets.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,11 @@ def test_create_image(self) -> None:
f"/sublet/properties/{str(self.test_sublet1.id)}/images/", {"images": image}
)
self.assertEqual(response.status_code, 201)
images = Sublet.objects.get(id=self.test_sublet1.id).images.all() # type: ignore
images = Sublet.objects.get(id=self.test_sublet1.id).images.all()
self.assertTrue(images.exists())
self.assertEqual(self.test_sublet1.id, images.first().sublet.id)
first_image = images.first()
assert first_image is not None
self.assertEqual(self.test_sublet1.id, first_image.sublet.id)

def test_create_delete_images(self) -> None:
with open("tests/sublet/mock_image.jpg", "rb") as image:
Expand All @@ -273,11 +275,13 @@ def test_create_delete_images(self) -> None:
"multipart",
)
self.assertEqual(response.status_code, 201)
images = Sublet.objects.get(id=self.test_sublet1.id).images.all() # type: ignore
image_id1 = images.first().id
images = Sublet.objects.get(id=self.test_sublet1.id).images.all()
first_image = images.first()
assert first_image is not None
image_id1 = first_image.id
self.assertTrue(images.exists())
self.assertEqual(2, images.count())
self.assertEqual(self.test_sublet1.id, images.first().sublet.id)
self.assertEqual(self.test_sublet1.id, first_image.sublet.id)
response = self.client.delete(f"/sublet/properties/images/{image_id1}/")
self.assertEqual(response.status_code, 204)
self.assertFalse(SubletImage.objects.filter(id=image_id1).exists())
Expand Down

0 comments on commit f6034f9

Please sign in to comment.