Testing a Flask REST API using Factory Boy and an in-memory sqlite database

Testing a Flask REST API using Factory Boy and an in-memory sqlite database

I’m developing a REST API using Python’s Flask microframework. As I wanted to do test driven development to ensure good test coverage, I needed a working testing framework. After checking out a few different options, I found one that works well for my use case. I thought I’d share my setup in case it may be of help to others. First, this is how I create the server:

Passing custom HTTP headers using Flask’s test_client

Passing custom HTTP headers using Flask’s test_client

Passing custon HTTP headers using Flask’s test_client object should have been as easy as doing this:

For some reason this didn’t work in my Flask project. In case others have the same issue as I did, maybe the solution I found to work may work for others too:

 

Mocking SQLAlchemy models in Python

Mocking SQLAlchemy models in Python

I’m developing an API using Python’s Flask framework. The API uses SQLAlchemy, which means that database rows are made available as regular Python classes (referred to as database models) in my Python code. One of my models looks something like this:

My Data Access Object (DAO) for communicating with the database models looks like this:

While writing tests for the API, I wanted to mock out the database models, so that my tests wouldn’t depend on an actual…

Read More Read More

Alarm clock for kids

Alarm clock for kids

I’ve created a very simple Raspberry Pi project that I use to let my kid know if its daytime or nighttime. When I say goodnight and leave my kids bedroom, I trigger a simple script on my Raspberry Pi with a 7″ touchscreen attached. The screen will display a daytime image for a few minutes, before switching to a nighttime image. The nighttime image is an indication for my kid to put down her toys and go to bed. Over…

Read More Read More

Using the “Oboe” Javascript library to speed up data processing

Using the “Oboe” Javascript library to speed up data processing

One of our node.js applications at work was designed to call an internal rest service, cache the whole response, and iterate over the data to separate relevant data from non-relevant data, and write the relevant data to file. To speed things up a bit, we wanted to process, filter and write the data to file as it arrived. For this task, the excellent Javascript library “Oboe” came in handy:

Keywords: HTTP response streaming

Using Maven to build and run Java applications

Using Maven to build and run Java applications

Say you want to have Maven handle the dependencies for your java application containing the well known “public static void main” method. Create a Maven project, put your MyApplication.java file under the “src”-folder, and add something like this to you pom.xml:

Now you can run your application using the exec-maven-plugin, like this:

“Løp til bussen” – Android-app’en som forteller deg om bussen din er forsinket

“Løp til bussen” – Android-app’en som forteller deg om bussen din er forsinket

For å lære meg litt om Android-programmering jeg har laget en enkel app. App’en er svært enkel, og har som eneste formål å vise sanntidsinfo for din neste reise med buss, bane, tog, trikk eller båt. Utgangspunktet mitt var at jeg enkelt ønsket å finne ut om jeg måtte løpe til bussen eller ikke, for jeg har altfor mange ganger løpt til bussen tidlig om morgenn, for så å bli stående å vente på den fordi den er forsinket.

Simple script for dumping a MySQL database

Simple script for dumping a MySQL database

As file system backups might fail to backup open files, it’s good practice to close any open files before running the backup. Closing a MySQL database file means you will have to stop the MySQL server itself, causing causing a database outage while the backup is running. But fortunately there’s a smarter way to backup you database – simple dump the entire database to a file (which is automatically closed when the dump is completed), and have your file system…

Read More Read More

Setting up Sublime Text as a node.js development environment

Setting up Sublime Text as a node.js development environment

Sublime Text makes a great IDE for node.js development. First, install the node.js software and get your initial project up and running. Various tutorials on the web should get you going. When it’s time to run your app, configure the Sublime Text build system to build it and run it. To avoid having to start and stop your Node server manually, make use of the tool Nodemon – this tool will build and run your app automatically when you edit…

Read More Read More