Skip to content

Commit

Permalink
Run the tests by default with postgresql
Browse files Browse the repository at this point in the history
Most real-world instances will use postgresql instead of sqlite so it's
better to use postgres for the tests. This also allows us to easily add
tests for concurrency issues which is not supported by sqlite
  • Loading branch information
mvantellingen committed Mar 30, 2017
1 parent 2574e18 commit 644a845
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 8 deletions.
39 changes: 39 additions & 0 deletions tests/_site/myauth/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.6 on 2017-03-30 14:35
from __future__ import unicode_literals

import django.core.validators
from django.db import migrations, models
import django.utils.timezone
import re


class Migration(migrations.Migration):

initial = True

dependencies = [
('auth', '0008_alter_user_username_max_length'),
]

operations = [
migrations.CreateModel(
name='User',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('password', models.CharField(max_length=128, verbose_name='password')),
('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')),
('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')),
('email', models.EmailField(max_length=254, unique=True, verbose_name='email address')),
('first_name', models.CharField(blank=True, max_length=255, verbose_name='First name')),
('last_name', models.CharField(blank=True, max_length=255, verbose_name='Last name')),
('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='Staff status')),
('is_active', models.BooleanField(default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='Active')),
('date_joined', models.DateTimeField(default=django.utils.timezone.now, verbose_name='date joined')),
('username', models.CharField(help_text='Required. 30 characters or fewer. Letters, numbers and @/./+/-/_ characters', max_length=30, unique=True, validators=[django.core.validators.RegexValidator(re.compile('^[\\w.@+-]+$', 32), 'Enter a valid username.', 'invalid')], verbose_name='username')),
('extra_field', models.CharField(blank=True, max_length=5, verbose_name='Nobody needs me')),
('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.Group', verbose_name='groups')),
('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.Permission', verbose_name='user permissions')),
],
),
]
Empty file.
10 changes: 5 additions & 5 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


def pytest_addoption(parser):
parser.addoption('--postgres', action='store_true')
parser.addoption('--sqlite', action='store_true')
parser.addoption(
'--deprecation', choices=['strict', 'log', 'none'], default='log')

Expand All @@ -26,8 +26,8 @@ def pytest_configure(config):
# Deprecation warnings are ignored by default
pass

if config.getoption('postgres'):
os.environ['DATABASE_ENGINE'] = 'django.db.backends.postgresql_psycopg2'
os.environ['DATABASE_NAME'] = 'oscar'
if config.getoption('sqlite'):
os.environ['DATABASE_ENGINE'] = 'django.db.backends.sqlite3'
os.environ['DATABASE_NAME'] = ':memory:'

django.setup()
django.setup()
6 changes: 3 additions & 3 deletions tests/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

DATABASES = {
'default': {
'ENGINE': os.environ.get('DATABASE_ENGINE', 'django.db.backends.sqlite3'),
'NAME': os.environ.get('DATABASE_NAME', ':memory:'),
},
'ENGINE': os.environ.get('DATABASE_ENGINE', 'django.db.backends.postgresql_psycopg2'),
'NAME': os.environ.get('DATABASE_NAME', 'oscar'),
}
}

INSTALLED_APPS = [
Expand Down

0 comments on commit 644a845

Please sign in to comment.