testing an idea

This commit is contained in:
James Turk 2015-05-28 00:21:04 -04:00
commit b80f5eee04
6 changed files with 73 additions and 0 deletions

14
fkreplace/__init__.py Normal file
View File

@ -0,0 +1,14 @@
# thanks to https://djangosnippets.org/snippets/2283/ for inspiration on m2m
def migrate(from_obj, to_obj):
for related in from_obj._meta.get_all_related_objects():
accessor_name = related.get_accessor_name()
varname = related.field.name
getattr(from_obj, accessor_name).all().update(**{varname: to_obj})
for related_m2m in from_obj._meta.get_all_related_many_to_many_objects():
accessor_name = related.get_accessor_name()
varname = related.field.name
#for obj in getattr(from_obj, varname)

15
runtests.py Executable file
View File

@ -0,0 +1,15 @@
#!/usr/bin/env python
import os
import sys
import django
from django.conf import settings
from django.test.utils import get_runner
if __name__ == "__main__":
os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.settings'
django.setup()
TestRunner = get_runner(settings)
test_runner = TestRunner()
failures = test_runner.run_tests(["tests"])
sys.exit(bool(failures))

0
tests/__init__.py Normal file
View File

21
tests/models.py Normal file
View File

@ -0,0 +1,21 @@
from django.db import models
class Person(models.Model):
name = models.CharField(max_length=100)
friends = models.ManyToManyField('self')
class Number(models.Model):
person = models.ForeignKey(Person, related_name='numbers')
number = models.CharField(max_length=10)
class SSN(models.Model):
person = models.OneToOneField(Person)
number = models.CharField(max_length=10)
class Group(models.Model):
name = models.CharField(max_length=100)
people = models.ManyToManyField(Person)

15
tests/settings.py Normal file
View File

@ -0,0 +1,15 @@
SECRET_KEY = 'so-secret'
INSTALLED_APPS = (
'fkreplace',
)
MIDDLEWARE_CLASSES = ()
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'db.sqlite3',
}
}

8
tests/tests.py Normal file
View File

@ -0,0 +1,8 @@
from django.test import TestCase
from .models import Person, Number, SSN
def setUp():
a = Person.objects.create(name='alf')
b = Person.objects.create(name='bee')
Number.objects.create(person=a, number='123')
Number.objects.create(person=a, number='1234')