Skip to content

Instantly share code, notes, and snippets.

View martin056's full-sized avatar

Martin Angelov martin056

View GitHub Profile
@martin056
martin056 / fake_it.md
Last active August 23, 2017 09:31
Improve your tests in Django with fakes and factories

TL;DR This article is targeted at programmers who have very little or no experience with fakers and factories. If you are already skilled in the topic this article may not be that interesting to you.

Introduction

In our Django apps we have the M(odel)T(emplate)V(iew) structure (mostly known as MVC). When we want to test its functionality we usually have to create some model instances and work with them and the database.

A nice and easy approach for doing so is to create fake data in our tests in the form of factories and fakers.

In the following article we are going to look over some practical examples and techniques. This will improve your tests readability and behavior.

@martin056
martin056 / mock_everything.md
Last active July 17, 2017 11:32
Explaining the mock technique.

Introduction

Unit testing is essential part of our daily struggles as a programmer. Therefore, if we want to be better in our work we have to advance in this approach.

In the article we are going to look at the mock module of Python's unittest library. In the end you will end up with levelled up unit testing skills.

What is mocking?

This is actually a test technique that allows you to isolate parts of you code and unit test them. You can easily fake function calls in your tests wherever needed.

Introduction

In my previous article I promised you to show you how to properly unit test Celery tasks. Since I keep my promises every time, this is the target of the following article.

You had better be familiar with the mocking technique in the unit test practices before dive into the article. If you are not that sure in your knowledge - check this article.

Repetition is the key to success

I'm going to expand my previous article so you had better take a quick look at it. If you already read it you can take a look at its demo.

@martin056
martin056 / handle_errors_article.md
Last active May 30, 2017 07:23
Handle errors from third-party apps in Django

Handle errors from third-party apps in Django

TL;DR - Here is a demo of what we are going to achieve. Once you have this basic implementation you can use it in many defferent ways - in a View, to send notifications, etc.

Before we start

Things you should be familiar with: