Browsed by
Author: Kenneth Holter

SQLAlchemy + Database Link => ORA-04054

SQLAlchemy + Database Link => ORA-04054

I’ve got this SQLAclhemy table definition that describes a table I’ll be accessing over an Oracle database link: I first created a database link such as this: In SQLAlchemy, access a table column (in a query) via that link would look like tihs I turns out that SQLAlchemy with Oracle database links isn’t a very good match, and easily results in errors such as this: To work around this issue, I created a synonym like this: Now, accessing the table…

Read More Read More

Running Oracle in Docker for development and testing

Running Oracle in Docker for development and testing

I’m working on a Python based microservice that needs to communicate with an Oracle database. My development environment consist only of my laptop, so to do some real testing I decided to spin up Oracle in a Docker container on my laptop. For me, the process of getting things up and running wasn’t very straight forward for an Oracle newbie as myself, so I though I’d share my setup in case others may benefit from it. Let’s start with my…

Read More Read More

Extending business logic functions in unit tests

Extending business logic functions in unit tests

We have a database view, from now on referred to as View, that lists users we need to send an email to, and when we’ve sent the user an email we acknowledge this by updating the corresponding user in a database table (which is one of the tables the above mentioned database view is build from), from now on referred to as Table. For my unit tests I needed to emulate this behavior. I found that by extending the database…

Read More Read More

Using the factory pattern to create different emails based on input parameters

Using the factory pattern to create different emails based on input parameters

I wrote a small service that takes an MQ message as input, and based on the contents of the message creates and sends an email. The different types of incoming MQ messages require different types of emails to be created, so I needed a maintainable way to create different emails. For my use case, I found that the factory pattern was a good fit. Consider this code: My business logic code that uses this code then get to be as…

Read More Read More

Spying on Python functions

Spying on Python functions

I was writing test code for a Python project, and needed to spy on the functions of one of the main object’s, called “server”, object instances called “rest_client”. By simply replacing the “rest_client” instance with a mock that passes the actual call to the wrapped object, I’m able to execute the production code of “rest_client” while later on making assertions.

Developing .NET applications without installing .NET SDK

Developing .NET applications without installing .NET SDK

I recently developed a small .NET application. I considered installing the .NET SDK on my laptop (on which I were to develop the .NET application), but was unsure of which version I would need, and how I would potentially downgrade the SDK version if needed.  Instead of installing the SDK on my laptop, I decided to run the SDK inside a Docker container. This way I could easily switch between SDK versions if needed, as all I’d have to do…

Read More Read More

Docker build fails with “no matching manifest for unknown in the manifest list entries”

Docker build fails with “no matching manifest for unknown in the manifest list entries”

I recently got this error when trying to build a Windows container (specifically microsoft/dotnet-framework:4.7.2-sdk) on my Windows 10 laptop: no matching manifest for unknown in the manifest list entries I was surprised that I couldn’t build Windows containers on my Windows laptop, but then I recalled that Docker for Windows let you choose between running Linux containers or Windows containers. As I until now had exclusively ran Linux containers, my Docker was set up to run Linux containers, but configuring Docker to…

Read More Read More

Patching Python instance methods

Patching Python instance methods

I’m working on a project in which one of our services need to publish messages to a RabbitMQ exchange. Consider this code excerpt from the message queue client:

In my unit tests I wanted to verify that an unsuccessful attempt to publish the message, would cause trigger an exception to be thrown. To test this, I needed basic_publish  to return False. At first I found it tricky to patch instance methods such as basic_publish , but after coming across this excellent…

Read More Read More

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: