Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
1,087 additions
and
15 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Copyright 2021 Google LLC | ||
# | ||
# Use of this source code is governed by a BSD-style | ||
# license that can be found in the LICENSE file or at | ||
# https://developers.google.com/open-source/licenses/bsd | ||
|
||
DEBUG = True | ||
USE_TZ = True | ||
|
||
INSTALLED_APPS = [ | ||
"django_spanner", # Must be the first entry | ||
"django.contrib.contenttypes", | ||
"django.contrib.auth", | ||
"django.contrib.sites", | ||
"django.contrib.sessions", | ||
"django.contrib.messages", | ||
"django.contrib.staticfiles", | ||
"tests", | ||
] | ||
|
||
TIME_ZONE = "UTC" | ||
|
||
DATABASES = { | ||
"default": { | ||
"ENGINE": "django_spanner", | ||
"PROJECT": "emulator-local", | ||
"INSTANCE": "django-test-instance", | ||
"NAME": "django-test-db", | ||
} | ||
} | ||
SECRET_KEY = "spanner emulator secret key" | ||
|
||
PASSWORD_HASHERS = [ | ||
"django.contrib.auth.hashers.MD5PasswordHasher", | ||
] | ||
|
||
SITE_ID = 1 | ||
|
||
CONN_MAX_AGE = 60 | ||
|
||
ENGINE = "django_spanner" | ||
PROJECT = "emulator-local" | ||
INSTANCE = "django-test-instance" | ||
NAME = "django-test-db" | ||
OPTIONS = {} | ||
AUTOCOMMIT = True |
Empty file.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# Copyright 2021 Google LLC | ||
# | ||
# Use of this source code is governed by a BSD-style | ||
# license that can be found in the LICENSE file or at | ||
# https://developers.google.com/open-source/licenses/bsd | ||
""" | ||
Different models used for testing django-spanner code. | ||
""" | ||
import os | ||
from django.db import models | ||
import django | ||
|
||
# Load django settings before loading django models. | ||
os.environ["DJANGO_SETTINGS_MODULE"] = "tests.settings" | ||
django.setup() | ||
|
||
|
||
# Register transformations for model fields. | ||
class UpperCase(models.Transform): | ||
lookup_name = "upper" | ||
function = "UPPER" | ||
bilateral = True | ||
|
||
|
||
models.CharField.register_lookup(UpperCase) | ||
models.TextField.register_lookup(UpperCase) | ||
|
||
|
||
# Models | ||
class ModelDecimalField(models.Model): | ||
field = models.DecimalField() | ||
|
||
|
||
class ModelCharField(models.Model): | ||
field = models.CharField() | ||
|
||
|
||
class Item(models.Model): | ||
item_id = models.IntegerField() | ||
name = models.CharField(max_length=10) | ||
created = models.DateTimeField() | ||
modified = models.DateTimeField(blank=True, null=True) | ||
|
||
class Meta: | ||
ordering = ["name"] | ||
|
||
|
||
class Number(models.Model): | ||
num = models.IntegerField() | ||
decimal_num = models.DecimalField(max_digits=5, decimal_places=2) | ||
item = models.ForeignKey(Item, models.CASCADE) | ||
|
||
|
||
class Author(models.Model): | ||
name = models.CharField(max_length=40) | ||
last_name = models.CharField(max_length=40) | ||
num = models.IntegerField(unique=True) | ||
created = models.DateTimeField() | ||
modified = models.DateTimeField(blank=True, null=True) | ||
|
||
|
||
class Report(models.Model): | ||
name = models.CharField(max_length=10) | ||
creator = models.ForeignKey(Author, models.CASCADE, null=True) | ||
|
||
class Meta: | ||
ordering = ["name"] |
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
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
Oops, something went wrong.