forked from ZU-Hospital/zu-hospital-backend
-
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.
Merge pull request #15 from MohamedHamed12/visit
edit attachments
- Loading branch information
Showing
6 changed files
with
131 additions
and
17 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
48 changes: 48 additions & 0 deletions
48
project/visit/migrations/0002_attachment_file_name_attachment_file_type_and_more.py
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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# Generated by Django 5.0.3 on 2024-05-11 16:46 | ||
|
||
import django.db.models.deletion | ||
from django.conf import settings | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("visit", "0001_initial"), | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="attachment", | ||
name="file_name", | ||
field=models.CharField(blank=True, max_length=255, null=True), | ||
), | ||
migrations.AddField( | ||
model_name="attachment", | ||
name="file_type", | ||
field=models.CharField(blank=True, max_length=255, null=True), | ||
), | ||
migrations.AddField( | ||
model_name="attachment", | ||
name="user", | ||
field=models.ForeignKey( | ||
blank=True, | ||
null=True, | ||
on_delete=django.db.models.deletion.CASCADE, | ||
related_name="user_attachments", | ||
to=settings.AUTH_USER_MODEL, | ||
), | ||
), | ||
migrations.AlterField( | ||
model_name="attachment", | ||
name="visit", | ||
field=models.ForeignKey( | ||
blank=True, | ||
null=True, | ||
on_delete=django.db.models.deletion.CASCADE, | ||
related_name="visit_attachments", | ||
to="visit.visit", | ||
), | ||
), | ||
] |
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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
from django.test import TestCase | ||
from visit.models import Attachment | ||
from django.core.files.uploadedfile import SimpleUploadedFile | ||
from django.urls import reverse | ||
from unittest.mock import patch, MagicMock | ||
|
||
class AttachmentAPITestCase(TestCase): | ||
|
||
def setUp(self): | ||
self.attachment_data = {'file': SimpleUploadedFile("test.txt", b"file_content"), 'notes': "Test notes"} | ||
|
||
@patch('visit.views.AttachmentViewSet') | ||
def test_attachment_api_list(self, MockAttachment): | ||
mock_attachment = MagicMock() | ||
mock_attachment.file.name = 'attachments/test.txt' | ||
MockAttachment.objects.all.return_value = [mock_attachment] | ||
|
||
response = self.client.get(reverse('attachment-list')) | ||
self.assertEqual(response.status_code, 200) | ||
# self.assertContains(response, 'attachments/test.txt') | ||
|
||
@patch('visit.views.AttachmentViewSet') | ||
def test_attachment_api_detail(self, MockAttachment): | ||
mock_attachment = MagicMock() | ||
mock_attachment.file.name = 'attachments/test.txt' | ||
mock_attachment.notes = 'Test notes' | ||
MockAttachment.objects.get.return_value = mock_attachment | ||
|
||
|
||
# response = self.client.get(reverse('attachment-detail', kwargs={'pk': 1})) | ||
# self.assertEqual(response.status_code, 200) | ||
# # self.assertContains(response, 'attachments/test.txt') | ||
# self.assertContains(response, 'Test notes') | ||
|
||
# @patch('visit.views.AttachmentViewSet') | ||
# def test_attachment_api_create(self, MockAttachment): | ||
# MockAttachment.objects.create.return_value = MagicMock() | ||
|
||
# response = self.client.post(reverse('attachment-list'), self.attachment_data, format='multipart') | ||
# self.assertEqual(response.status_code, 201) | ||
# self.assertTrue(MockAttachment.objects.create.called) | ||
|
||
# @patch('myapp.views.AttachmentViewSet') | ||
# def test_attachment_api_update(self, MockAttachment): | ||
# mock_attachment_instance = MagicMock() | ||
# MockAttachment.objects.get.return_value = mock_attachment_instance | ||
|
||
# response = self.client.put(reverse('attachment-detail', kwargs={'pk': 1}), self.attachment_data, format='multipart') | ||
# self.assertEqual(response.status_code, 200) | ||
# mock_attachment_instance.save.assert_called_once() | ||
|
||
# @patch('myapp.views.AttachmentViewSet') | ||
# def test_attachment_api_delete(self, MockAttachment): | ||
# mock_attachment_instance = MagicMock() | ||
# MockAttachment.objects.get.return_value = mock_attachment_instance | ||
|
||
# response = self.client.delete(reverse('attachment-detail', kwargs={'pk': 1})) | ||
# self.assertEqual(response.status_code, 204) | ||
# mock_attachment_instance.delete.assert_called_once() |
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