mirror of
https://github.com/HackSoftware/Django-Styleguide.git
synced 2024-11-25 11:03:46 +03:00
commit
c772716289
19
README.md
19
README.md
|
@ -562,16 +562,11 @@ class FileStandardUploadService:
|
||||||
self.file_obj = file_obj
|
self.file_obj = file_obj
|
||||||
|
|
||||||
def _infer_file_name_and_type(self, file_name: str = "", file_type: str = "") -> Tuple[str, str]:
|
def _infer_file_name_and_type(self, file_name: str = "", file_type: str = "") -> Tuple[str, str]:
|
||||||
if not file_name:
|
file_name = file_name or self.file_obj.name
|
||||||
file_name = self.file_obj.name
|
|
||||||
|
|
||||||
if not file_type:
|
if not file_type:
|
||||||
guessed_file_type, encoding = mimetypes.guess_type(file_name)
|
guessed_file_type, encoding = mimetypes.guess_type(file_name)
|
||||||
|
file_type = guessed_file_type or ""
|
||||||
if guessed_file_type is None:
|
|
||||||
file_type = ""
|
|
||||||
else:
|
|
||||||
file_type = guessed_file_type
|
|
||||||
|
|
||||||
return file_name, file_type
|
return file_name, file_type
|
||||||
|
|
||||||
|
@ -851,7 +846,7 @@ The service:
|
||||||
**Those are our tests:**
|
**Those are our tests:**
|
||||||
|
|
||||||
```python
|
```python
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch, Mock
|
||||||
|
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
|
@ -863,7 +858,9 @@ from django_styleguide.payments.models import Payment, Item
|
||||||
|
|
||||||
class ItemBuyTests(TestCase):
|
class ItemBuyTests(TestCase):
|
||||||
@patch('project.payments.services.items_get_for_user')
|
@patch('project.payments.services.items_get_for_user')
|
||||||
def test_buying_item_that_is_already_bought_fails(self, items_get_for_user_mock):
|
def test_buying_item_that_is_already_bought_fails(
|
||||||
|
self, items_get_for_user_mock: Mock
|
||||||
|
):
|
||||||
"""
|
"""
|
||||||
Since we already have tests for `items_get_for_user`,
|
Since we already have tests for `items_get_for_user`,
|
||||||
we can safely mock it here and give it a proper return value.
|
we can safely mock it here and give it a proper return value.
|
||||||
|
@ -883,7 +880,7 @@ class ItemBuyTests(TestCase):
|
||||||
@patch('project.payments.services.payment_charge.delay')
|
@patch('project.payments.services.payment_charge.delay')
|
||||||
def test_buying_item_creates_a_payment_and_calls_charge_task(
|
def test_buying_item_creates_a_payment_and_calls_charge_task(
|
||||||
self,
|
self,
|
||||||
payment_charge_mock
|
payment_charge_mock: Mock
|
||||||
):
|
):
|
||||||
# How we prepare our tests is a topic for a different discussion
|
# How we prepare our tests is a topic for a different discussion
|
||||||
user = given_a_user(username="Test user")
|
user = given_a_user(username="Test user")
|
||||||
|
@ -902,7 +899,7 @@ class ItemBuyTests(TestCase):
|
||||||
|
|
||||||
self.assertFalse(payment.successful)
|
self.assertFalse(payment.successful)
|
||||||
|
|
||||||
payment_charge_mock.assert_called()
|
payment_charge_mock.assert_called_once()
|
||||||
```
|
```
|
||||||
|
|
||||||
## APIs & Serializers
|
## APIs & Serializers
|
||||||
|
|
Loading…
Reference in New Issue
Block a user