Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Django models CRUD API testing #151

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
162 changes: 162 additions & 0 deletions frameworks/python/django/src/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@

# Created by https://www.toptal.com/developers/gitignore/api/django
# Edit at https://www.toptal.com/developers/gitignore?templates=django

### Django ###
*.log
*.pot
*.pyc
__pycache__/
local_settings.py
db.sqlite3
db.sqlite3-journal
media

# If your build process includes running collectstatic, then you probably don't need or want to include staticfiles/
# in your Git repository. Update and uncomment the following line accordingly.
# <django-project-name>/staticfiles/

### Django.Python Stack ###
# Byte-compiled / optimized / DLL files
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
pytestdebug.log

# Translations
*.mo

# Django stuff:

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/
doc/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
#poetry.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
# .env
.env/
.venv/
env/
venv/
ENV/
env.bak/
venv.bak/
pythonenv*

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# operating system-related files
# file properties cache/storage on macOS
*.DS_Store
# thumbnail cache on Windows
Thumbs.db

# profiling data
.prof


# End of https://www.toptal.com/developers/gitignore/api/django
Empty file.
3 changes: 3 additions & 0 deletions frameworks/python/django/src/testApp/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
6 changes: 6 additions & 0 deletions frameworks/python/django/src/testApp/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class TestappConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'testApp'
Empty file.
8 changes: 8 additions & 0 deletions frameworks/python/django/src/testApp/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django.db import models

class Person(models.Model):
first_name = models.CharField(max_length=100)
last_name = models.CharField(max_length=100)

def __str__(self):
return self.first_name
Empty file.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# These are testse

from django.test import TestCase
from testApp.models import Person

class CrudTestCase(TestCase):

def setUp(self):
self.test_person_1 = Person.objects.create(first_name="John", last_name="Doe")
self.test_person_2 = Person.objects.create(first_name="Jane", last_name="Doe")

def test_create(self):
new_person = Person.objects.create(first_name="Alice", last_name="Foo")
self.assertEqual(self.test_person_1.id, 1)
self.assertEqual(self.test_person_2.id, 2)
self.assertEqual(new_person.id, 3)

def test_read(self):
persons_in_db = Person.objects.all()
self.assertEqual(len(persons_in_db),2)
person_1, person_2 = persons_in_db
self.assertEqual(person_1.first_name,self.test_person_1.first_name)
self.assertEqual(person_2.first_name,self.test_person_2.first_name)

def test_update(self):
test_person_1 = Person.objects.get(id=1)
test_person_1.first_name = "Johnny"
test_person_1.save()
test_person_2 = Person.objects.get(id=1)
self.assertEqual(test_person_2.first_name,"Johnny")

def test_delete(self):
test_person_1 = Person.objects.get(id=1)
test_person_1.delete()
try:
test_person_2 = Person.objects.get(id=1)
except Person.DoesNotExist:
pass

3 changes: 3 additions & 0 deletions frameworks/python/django/src/testApp/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.shortcuts import render

# Create your views here.
1 change: 1 addition & 0 deletions frameworks/python/django/src/vitess_django/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'testApp'
]

MIDDLEWARE = [
Expand Down