Created
February 24, 2014 12:40
-
-
Save codeinthehole/9187671 to your computer and use it in GitHub Desktop.
Execute custom SQL before tests run (uses the Nose testrunner)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
from django.db import connection | |
def setUp(): | |
""" | |
Create custom database tables before test suite runs | |
""" | |
execute_from_file('stores_table.sql') | |
execute_from_file('category_table.sql') | |
def execute_from_file(filename): | |
""" | |
Execute an SQL file | |
""" | |
filepath = os.path.realpath(os.path.join( | |
os.path.dirname(__file__), 'sql/', filename)) | |
assert os.path.exists(filepath), "%s does not exist!" % filepath | |
cursor = connection.cursor() | |
cursor.execute(open(filepath, 'r').read()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment