-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: using cloudinary to upload files
updated tests
- Loading branch information
Showing
9 changed files
with
47 additions
and
38 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 |
---|---|---|
|
@@ -4,3 +4,4 @@ Pillow==10.2.0 | |
crispy-bootstrap5==0.7 | ||
gunicorn==20.1.0 | ||
whitenoise==6.4.0 | ||
cloudinary==1.40.0 |
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 |
---|---|---|
@@ -1,15 +1,10 @@ | ||
from django.contrib.auth.models import User | ||
from django.db import models | ||
|
||
from cloudinary.models import CloudinaryField | ||
|
||
class Profile(models.Model): | ||
user = models.OneToOneField(User, on_delete=models.CASCADE) | ||
image = models.ImageField(default="default.png", upload_to="users/") | ||
|
||
def save(self, *args, **kwargs): | ||
if self.image != "default.png": | ||
self.image.name = f"{self.user.username}/{self.user.username}.{self.image.name.split('.')[-1]}" | ||
super().save(*args, **kwargs) | ||
image = CloudinaryField('image') | ||
|
||
def __str__(self): | ||
return f"{self.user.username} Profile" |
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 |
---|---|---|
|
@@ -9,13 +9,11 @@ | |
class TestRegisterView(TestCase): | ||
@classmethod | ||
def setUpTestData(cls): | ||
if(os.path.exists(os.path.join(settings.MEDIA_ROOT, "users", "random"))): | ||
os.rmdir(os.path.join(settings.MEDIA_ROOT, "users", "random")) | ||
pass | ||
|
||
@classmethod | ||
def tearDownClass(cls): | ||
if(os.path.exists(os.path.join(settings.MEDIA_ROOT, "users", "random"))): | ||
os.rmdir(os.path.join(settings.MEDIA_ROOT, "users", "random")) | ||
pass | ||
|
||
def test_get_register_view(self): | ||
response = self.client.get("/register/") | ||
|
@@ -46,21 +44,12 @@ def setUpTestData(cls): | |
|
||
@classmethod | ||
def tearDownClass(cls): | ||
media_dir = settings.MEDIA_ROOT | ||
username = cls.user.username | ||
if(os.path.exists(os.path.join(media_dir, 'users', username))): | ||
os.rmdir(os.path.join(media_dir, 'users', username)) | ||
pass | ||
|
||
def test_get_login_view(self): | ||
response = self.client.get("/login/") | ||
self.assertEqual(response.status_code, 200) | ||
|
||
def test_user_directory(self): | ||
username = self.user.username | ||
media_dir = settings.MEDIA_ROOT | ||
user_dir = os.path.join(media_dir, 'users', username) | ||
self.assertTrue(os.path.isdir(user_dir)) # asserts user directory is created with each user | ||
self.assertEqual(len(os.listdir(user_dir)), 0) # asserts user directory is empty | ||
|
||
def test_login(self): | ||
username = self.user.username | ||
|
@@ -75,4 +64,28 @@ def test_login(self): | |
def test_logout(self): | ||
response = self.client.get("/logout/") | ||
self.assertEqual(response.status_code, 200) | ||
|
||
|
||
class TestAboutView(TestCase): | ||
def test_get_about_view(self): | ||
response = self.client.get("/about/") | ||
self.assertEqual(response.status_code, 200) | ||
|
||
|
||
class TestProfileView(TestCase): | ||
|
||
@classmethod | ||
def setUpTestData(cls): | ||
cls.user = User.objects.create_user( | ||
username="random", email="[email protected]", password="randomuser" | ||
) | ||
|
||
def test_login_required(self): | ||
response = self.client.get("/profile/") | ||
self.assertEqual(response.status_code, 302) | ||
|
||
|
||
def test_get_profile_view(self): | ||
self.client.login(username="random", password="randomuser") | ||
response = self.client.get("/profile/") | ||
self.assertEqual(response.status_code, 200) |