Skip to content

Instantly share code, notes, and snippets.

View katiayn's full-sized avatar

Kátia Nakamura katiayn

View GitHub Profile
@katiayn
katiayn / django_5_1_whats_new.py
Last active June 27, 2024 12:19
What's new in Django 5.1: PostgreSQL Connection Pools
# <project>/settings.py
DATABASES = {
"default": {
"ENGINE": "django.db.backends.postgresql",
# ...
"OPTIONS": {
"pool": {
"min_size": 2,
"max_size": 4,
@katiayn
katiayn / django_5_1_whats_new.py
Created June 27, 2024 12:18
What's new in Django 5.1: {% query_string %} template tag
# parameter as a list: genre_list is set to ["drama", "comedy", "sci-fi"]
# current query_sring '?type=movie&genre=comedy&page=2'
{% query_string type=None genre=genre_list page=page.next_page_number %}
# results in '?genre=drama&genre=comedy&genre=sci-fi&page=3'
@katiayn
katiayn / django_5_1_whats_new.py
Last active June 28, 2024 09:52
What's new in Django 5.1: Middleware to require authentication by default
# <project>/settings.py
MIDDLEWARE = [
# ...
'django.contrib.auth.middleware.LoginRequiredMiddleware',
]
# <app>/urls.py
from django.contrib.auth.decorators import login_not_required
class Property(models.Model):
# fields
class Meta:
abstract = True
class Property(models.Model):
price = models.DecimalField(max_digits=15, decimal_places=2)
rooms = models.PositiveIntegerField()
address = models.TextField(null=True, blank=True)
city = models.CharField(max_length=255)
country = models.CharField(max_length=255)
class Meta:
abstract = True
$ # mut.py --target node --unit-test test_node
$ mut.py --target calculator --unit-test test_calculator -m
[*] Start mutation process:
- targets: calculator
- tests: test_calculator
[*] All tests passed:
- test_calculator [0.00031 s]
[*] Start mutants generation and execution:
- [# 1] AOR calculator.py:2 :
--------------------------------------------------------------------
1: def mul(x, y):
~2: return x / y
class ProductQuestionnaireCreateTestCase(SimpleTestCase):
def test_vat_20_if_biscuit_coated_in_chocolate(self):
calc = VATCalculator()
self.assertEqual(
calc.calculate_vat(
is_biscuit=True,
is_coated_in_chocolate=True
), 20)
class VATCalculator(object):
def calculate_vat(self, **kwargs):
is_biscuit = kwargs['is_biscuit']
is_coated_in_chocolate = kwargs['is_coated_in_chocolate']
if is_biscuit and is_coated_in_chocolate:
return 20
class ProductQuestionnaireTestCase(TestCase):
def test_vat_20_if_biscuit_coated_in_chocolate(self):
product = ProductFactory()
form = ProductQuestionnaireForm(data={
'is_biscuit': True,
'is_coated_in_chocolate': True
})
self.assertTrue(form.is_valid())
form.save()