In an earlier article, I demonstrated how to use
patch using MagicMock to stub a method. In that example though, there was one inherent problem. Once you patch that method using the string representation, future patches will become ineffective/not work at all. Let me demonstrate this with an example.
Assume I want to mock
urllib.request.urlopen to return a custom MagicMock, I could do it like this using the
Writing tests is essential in any programming language irrespective of the framework in use. In one of the recent projects in Python/Django which is relatively new to me, I had to write a substantial amount of tests. Some of these tests execute code which talks to the internet. And in the Python ecosystem, MagicMock is there to help us.
How to mock an external API and return value when the function is chained. Here is my application code
Connecting to Salesforce’s REST endpoint is fairly straightforward from a Ruby on Rails application. However, there are few steps you have to take. Before starting, ensure that you have full administrator privileges in Salesforce.
First thing we need to do is to create a Connected App. Its more like a bridge between the Salesforce resources and the outside world. Here is where you can also limit the scope what resources can be shared, their granularity etc.,
When we started using Clickhouse, the concepts of MergeTree and SummingMergeTree was very confusing. Not only should one understand what each mean, it is extremely crucial to know when to use what as using a wrong one for the other would either result in Resolution/Data loss or would incur huge amount of storage space.
Assume CompanyX has a fleet of Trucks running on the streets. The current speed of each truck is being sent every second to a live server. …
Materialized Views are not something very new if you are familiar with Database views and have worked with Time series/Analytical database. However, when used in Clickhouse, they are blazing fast. So fast, that not many databases in the similar domain can even come closer to it.
Why is Clickhouse very very fast?
The reasons that could be termed for the speed as given in their website are,
GCP is right up there in the top three race to cloud infrastructure only behind Amazon Web Services and Microsoft Azure. It has almost everything you need from classical VM instances, Serverless, Hosted Kubernetes, Docker container registries, ML, Vision - almost everything!
In this article, I am going to focus on how you might get milked out with a fat invoice every month if you aren’t careful enough. We learnt the hard way shelling out thousands of dollars a month only to realize you can achieve the same with a different infrastructure provider with almost one tenth the cost.
With the development community leaning a lot towards front-end, and framework like Rails mostly moving to mostly serve back-end, it is important to keep this separation clean and straightforward in a Production environment as well.
To make this work via nginx is not straightforward, yet doable. But why should one fiddle a lot with a syntax that is difficult to learn for a developer and is not clean enough. Plus, nginx still does not support https out of the box.
If you are still using nginx for your web server, you would be pleasantly surprised to know Caddy which comes…
In one of the projects I worked on, I had written close to thousands (sic) of Regex as they help in having a strong foundation in Natural Language Processing besides the existing libraries available.
However, one of the most important piece in Regex is that it could get complicated so fast when you have to cover a lot of different scenarios. For the untrained eye, this could look totally like a foreign language, however, when you have the knack of identifying the right one, things become easier.
I am going to list the most common Regex patterns you might end…
Refactoring is nothing but restructuring the existing code such that the existing behavior that is accessed through the outside world, remain the same. It’s often referred to as “under the hood” changes.
Why would someone want to refactor when the external behavior is not going to change. There may be many reasons behind this. Some of the common reasons yet not exhaustive reasons could be
One of the sexy features of capistrano if you had used it with Rails is how super simple it is deploy a Rails project. The DSL (Domain Specific Language) it uses is very straightforward for even a beginner to understand. However, with time, Rails at least in our experience has moved mostly to serve the backend alone with the Front end being taken over by the likes of Vue, React etc.,
In case of Vue, we now end up building the script for in the production machine itself. And if you want to deploy it in cost effective machines (that…