Skip to main content

Posts

Showing posts from January, 2016

An Introduction to Mocking in Python

How to Run Unit Tests Without Testing Your Patience More often than not, the software we write directly interacts with what we would label as “dirty” services. In layman’s terms: services that are crucial to our application, but whose interactions have intended but undesired side-effects—that is, undesired in the context of an autonomous test run. For example: perhaps we’re writing a social app and want to test out our new ‘Post to Facebook feature’, but don’t want to actually post to Facebook every time we run our test suite. The Python unit test library includes a subpackage named unittest.mock—or if you declare it as a dependency, simply mock—which provides extremely powerful and useful means by which to mock and stub out these undesired side-effects. Note : mock is newly included in the standard library as of Python 3.3; prior distributions will have to use the Mock library downloadable via PyPI. Fear System Calls To give you another example, and one that we...

Stored Function in SQL

Stored Function in SQL Function is mainly used in the case where it must return a value. Function can be called from SQL statements. You can have DML (insert,update, delete) statements in a function. Function returns 1 value only.  Mysql: Simple function to return cube CREATE FUNCTION `calcube`(`PID` INT)           RETURNS INT(11)           RETURN PID * PID * PID Function to return student division based on marks DELIMITER $$ CREATE FUNCTION resultRemark(mark1 int,mark2 int,mark3 int,mark4 int,mark5 int) RETURNS VARCHAR(50)           DETERMINISTIC BEGIN          DECLARE lvl varchar(50); DECLARE total int; DECLARE percentage double; SET total = mark1 + mark2 + mark3 + mark4 + mark5; SET percentage = (total*100)/500;          IF percentage >= 60 THEN          ...