RSSAmplifier

Blog

Tech Blog | Serhat Teker | tech.serhatteker.com

Recent content on Tech Blog | Serhat Teker | tech.serhatteker.com

tech.serhatteker.comRSS feed ↗10 posts

Latest posts

Django Signals - How to Mute Them in Tests with FactoryBoy

Django signals are powerful but can sometimes complicate your testing scenarios. In this guide, we’ll explore how to effectively mute Django signals during testing using FactoryBoy’s mute_signals decorator, along with pytest. Understanding the Problem Django signals can trigger additional operations when models are saved, deleted, or modified. While this is great for production code,…

Django Signals - How to Mute Them in Tests

Intro Django signals provide a powerful way to decouple applications by allowing certain senders to notify a set of receivers when actions occur. However, when writing tests, these signals can sometimes get in the way, making our tests slower and more complex. In this guide, we’ll explore how to effectively mute Django signals in your test suite. Understanding Django Signals Django signals…

Django Signals - Model Save and Signal Flows

Since I usually forget the implementations of model signals, I’d like to write a post to provide a clear and accessible reference. So I’ve included the original code snippets for model signals directly from the Django 4.2 branch. Permalinks to the specific source code locations are also provided for further exploration. Intro When working with Django models, understanding how the…

Django Signals - Abstract Model Class

In Django, it’s often useful to trigger certain actions when a model is saved. While Django provides built-in signals like post_save, there are cases where you might want to define custom behavior for all models inheriting from a common abstract base model. This article will show you how to implement this pattern, include logging, and test it effectively. The Problem Imagine you have an…

Django Signals - Automated Tests

Django signals are a powerful feature that allow decoupled applications to get notified when certain actions occur. However, testing signals can be tricky. In this article, we’ll focus on how to write tests for Django signals, particularly the post_save signal, using pytest, pytest-django, and model-bakery. Prerequisites Before we begin, make sure you have the following packages installed:…

Django Signals - Introduction

Django’s signal system is a powerful feature that allows decoupled applications to get notified when certain actions occur elsewhere in the framework. One of the most commonly used signals is the post_save signal. In this blog post, we’ll explore what the post_save signal is, how it works, and when to use it, complete with detailed examples. Introduction to Django Signals Before we…

Dynamically Passing Parameters to Pytest Fixtures

Testing in Python becomes more robust and elegant with the use of pytest, a powerful testing framework. One of its standout features is the ability to pass parameters dynamically to fixtures, enhancing the flexibility of your tests. In this post, we’ll dive into how to achieve this. What is a Fixture in Pytest? Before we jump into dynamic parameterization, let’s understand what a…

How to 'autouse' a pytest fixture only within a specific class

In pytest, the autouse parameter in a fixture automatically applies the fixture to all tests in the scope where the fixture is defined. However, if you want to use an autouse fixture specifically for tests within a particular class, you can define the fixture within the class itself. Here’s how you can do it: Define the Fixture Inside the Class: Place the fixture method inside the class…

Sign In Vault with Github

Github In order to sign in Hashicorp Vault with Github, you need create a classical PAT (Personal Access Token). You can access the menu from Settings/Developer Settings/Personal access tokens/Tokens (classic) in Github. This is the direct link: token settings On the menu, click “Generate new token”, then “Generate new token (classic)”. Give it a name, select expiration…

DRF - Map Filter QuerySet Parameters (Part V)

Entrée Sometimes we need to map some url parameters to different model fields, due to some restrictions or for backward compability. Let’s say we’d like to show/filter “customer” instead of “user” in our DRF API. # httpie $ http ":8000/authors?customer=3" # or with curl # $ curl http://localhost:8000/authors?customer=3 [ { "first_name": "Name3", "full_name":…