Skip to content

Instantly share code, notes, and snippets.

@Matt3o12
Matt3o12 / readme.md
Last active August 29, 2015 14:04
This test case creates a remote PostreSQL database provided by [postgression.com](http://postgression.com) and saves the credentials in order to limit the databases needed for testing.

What does this TestCase

This test case creates a remote PostreSQL database provided by postgression.com. postgression.com provides you with a PostgreSQL database, so you don't need to set up a PostgreSQL server on your local machine.
Unfortunately, PostgreSQL only provides you with 100 Database per hour, which can be reached very quickly when running lots of tests at the same time. This is where this DatabaseTestCase comes into place. It stores information about the last database used on your machine and reuses it so you won't reach the limit of 100 database.

How do I install/implement this?

Just copy the TestCase class somewhere in your tests folder. Then import the class. Let's say you have a file called setupTests.py in the test folder, the you would have to write:

from .setupTests import DatabaseTestCase

class MyTests(DatabaseTestCase):

import timeit;
import psycopg2
def psy():
with psycopg2.connect(user="Matt3o12", password="", host="localhost", port=5432, database="Matt3o12") as conn:
pass
if __name__ == "__main__":
i = 0
try:
import timeit;
import psycopg2
def psy():
with psycopg2.connect(user="Matt3o12", password="", host="localhost", port=5432, database="Matt3o12") as conn:
pass
if __name__ == "__main__":
i = 0
try:
failed=false
total=1000
for i in $(seq ${total}); do
printf "Status: ${i}/${total}\r"
psql --user "Matt3o12" --no-password --host="localhost" --port=5432 --dbname="Matt3o12" -c "" || failed=true
if [ "$failed" = true ]; then
echo "Error after attempt ${i}."
exit 1
fi
failed=false
total=1000
for i in $(seq ${total}); do
printf "Status: ${i}/${total}\r"
psql --user "Matt3o12" --no-password --host="localhost" --port=5432 --dbname="Matt3o12" -c "" || failed=true
if [ "$failed" = true ]; then
echo "Error after attempt ${i}."
exit 1
fi
Using `unittest.main()`:
python tests.py -b
.F
Stdout:
Should be printed since this test failed.
======================================================================
FAIL: test_print (__main__.TestSequenceFunctions)
----------------------------------------------------------------------
Traceback (most recent call last):
@Matt3o12
Matt3o12 / createRamdisk.py
Created October 22, 2014 21:17
Simple gist for creating a RAM Disk on Mac OS X (only tested on Yosemite, but it should work on Mavericks, too).
#!/usr/bin/env python3.4
import argparse
import sys
import subprocess
class ErrorToleranteParser(argparse.ArgumentParser):
def error(self, message):
sys.stderr.write("error: {}\n".format(message))
self.print_help()
class User (models.Model):
name = models.CharField(max_length=255)
class Manager (models.Model):
registration = models.PositiveInteger()
name = models.CharField(max_length=255)
class ClientHistory (models.Model):
package main
import (
"time"
ui "github.com/gizak/termui"
)
func main() {
err := ui.Init()
@Matt3o12
Matt3o12 / randomizedColorRenderer.go
Created April 16, 2015 17:01
Termui - Wiki - ColorRenderers Example
type RandomRendererFactory struct {
Max int
Min int
}
func NewRandomRendererFactory(min, max int) RandomRendererFactory {
return RandomRendererFactory{Min: min, Max: max}
}
func (f RandomRendererFactory) TextRenderer(text string) TextRenderer {