This repository was archived by the owner on Mar 20, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 32
feat: added unit test with coverage of 68 % #611
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
924f1ee
Merge pull request #1 from googleapis/master
vi3k6i5 df919be
fix: lint_setup_py was failing in Kokoro is not fixed
vi3k6i5 ad5f15c
Merge pull request #2 from googleapis/master
vi3k6i5 5ec9841
Merge pull request #3 from googleapis/master
vi3k6i5 34c4dda
Merge pull request #4 from googleapis/master
vi3k6i5 caf5a43
Merge pull request #5 from googleapis/master
vi3k6i5 129e41e
Merge pull request #6 from googleapis/master
vi3k6i5 a1707fb
Merge branch 'googleapis:master' into master
vi3k6i5 ad8e43e
Merge branch 'googleapis:master' into master
vi3k6i5 57e4be4
feat: added test cases
vi3k6i5 c418e16
test: changed test settings as per review comments
vi3k6i5 95e63a5
Merge branch 'master' into unit_tests_2
c24t File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,13 @@ | ||
| import os | ||
| import django | ||
| from django.conf import settings | ||
|
|
||
| # We manually designate which settings we will be using in an environment | ||
| # variable. This is similar to what occurs in the `manage.py` file. | ||
| os.environ.setdefault("DJANGO_SETTINGS_MODULE", "tests.settings") | ||
|
|
||
|
|
||
| # `pytest` automatically calls this function once when tests are run. | ||
| def pytest_configure(): | ||
| settings.DEBUG = False | ||
| django.setup() |
This file contains hidden or 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 hidden or 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,61 @@ | ||
| # 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. | ||
| """ | ||
| from django.db import models | ||
|
|
||
|
|
||
| # 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 hidden or 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,33 @@ | ||
| # 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 | ||
|
|
||
| from django_spanner.client import DatabaseClient | ||
| from django_spanner.base import DatabaseWrapper | ||
| from django_spanner.operations import DatabaseOperations | ||
| from unittest import TestCase | ||
| import os | ||
|
|
||
|
|
||
| class SpannerSimpleTestClass(TestCase): | ||
| @classmethod | ||
| def setUpClass(cls): | ||
| cls.PROJECT = os.environ["GOOGLE_CLOUD_PROJECT"] | ||
|
|
||
| cls.INSTANCE_ID = "instance_id" | ||
| cls.DATABASE_ID = "database_id" | ||
| cls.USER_AGENT = "django_spanner/2.2.0a1" | ||
| cls.OPTIONS = {"option": "dummy"} | ||
|
|
||
| cls.settings_dict = { | ||
| "PROJECT": cls.PROJECT, | ||
| "INSTANCE": cls.INSTANCE_ID, | ||
| "NAME": cls.DATABASE_ID, | ||
| "user_agent": cls.USER_AGENT, | ||
| "OPTIONS": cls.OPTIONS, | ||
| } | ||
| cls.db_client = DatabaseClient(cls.settings_dict) | ||
| cls.db_wrapper = cls.connection = DatabaseWrapper(cls.settings_dict) | ||
| cls.db_operations = DatabaseOperations(cls.connection) |
This file contains hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.