Arbitrary, probably-broken code.
Just found this laying around on my laptop...
This commit is contained in:
parent
88fc224abc
commit
4f2762ad48
|
@ -100,7 +100,7 @@ class UserRole(Model):
|
|||
role = models.ForeignKey(Role, db_column='role_uuid')
|
||||
|
||||
def __repr__(self):
|
||||
return "<UserRole: %s : %s>" % (self.user, self.role)
|
||||
return "<UserRole: %s, %s>" % (self.user, self.role)
|
||||
|
||||
def __unicode__(self):
|
||||
return unicode(self.role or '')
|
||||
|
|
|
@ -36,7 +36,7 @@ from rattail.django.rattail.models import Model, uuid_field
|
|||
|
||||
__all__ = ['Contact', 'PhoneNumber', 'EmailAddress', 'PostalAddress',
|
||||
'Person', 'PersonPhoneNumber', 'PersonEmailAddress', 'PersonPostalAddress',
|
||||
'Party']
|
||||
'Party', 'PartyManager']
|
||||
|
||||
|
||||
class ContactInfoManager(models.Manager):
|
||||
|
@ -358,7 +358,7 @@ class Person(Contact):
|
|||
|
||||
def make_employee(self, **kwargs):
|
||||
if self.employee:
|
||||
return
|
||||
return self.employee
|
||||
|
||||
from rattail.django.rattail.models import Employee
|
||||
employee = Employee(**kwargs)
|
||||
|
|
|
@ -31,11 +31,10 @@ from __future__ import absolute_import
|
|||
from django.db import models
|
||||
from django.core.exceptions import ObjectDoesNotExist
|
||||
|
||||
from edbob.db.extensions.contact.enum import EMAIL_PREFERENCE
|
||||
from edbob import EMAIL_PREFERENCE
|
||||
|
||||
import rattail
|
||||
from rattail.gpc import GPC
|
||||
from rattail.db.extension.enum import EMPLOYEE_STATUS
|
||||
|
||||
from rattail.django.rattail.models import Model, uuid_field
|
||||
from rattail.django.rattail.models.contact import (
|
||||
|
@ -384,7 +383,7 @@ class Employee(Model):
|
|||
db_table = Model.prefix('employees')
|
||||
verbose_name = "Employee"
|
||||
|
||||
EMPLOYEE_STATUS_CHOICES = enum_to_choices(EMPLOYEE_STATUS)
|
||||
EMPLOYEE_STATUS_CHOICES = enum_to_choices(rattail.EMPLOYEE_STATUS)
|
||||
|
||||
uuid = uuid_field()
|
||||
id = models.CharField(max_length=20, blank=True, null=True, verbose_name="ID")
|
||||
|
|
3
rattail/django/rattail/tests/__init__.py
Normal file
3
rattail/django/rattail/tests/__init__.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
from rattail.django.rattail.tests.models import *
|
10
rattail/django/rattail/tests/models/__init__.py
Normal file
10
rattail/django/rattail/tests/models/__init__.py
Normal file
|
@ -0,0 +1,10 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
from django.conf import settings
|
||||
|
||||
from rattail.django.rattail.tests.models.core import *
|
||||
|
||||
if bool(getattr(settings, 'RATTAIL_DJANGO_MANAGED', True)):
|
||||
from rattail.django.rattail.tests.models.managed import *
|
||||
else:
|
||||
from rattail.django.rattail.tests.models.unmanaged import *
|
14
rattail/django/rattail/tests/models/core.py
Normal file
14
rattail/django/rattail/tests/models/core.py
Normal file
|
@ -0,0 +1,14 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
from django.test import TestCase
|
||||
|
||||
from rattail.django.rattail import models
|
||||
|
||||
|
||||
class ModelTestCase(TestCase):
|
||||
|
||||
model = models.Model
|
||||
|
||||
def test_app_label(self):
|
||||
model = self.model()
|
||||
self.assertEqual(model._meta.app_label, 'rattail')
|
430
rattail/django/rattail/tests/models/managed.py
Normal file
430
rattail/django/rattail/tests/models/managed.py
Normal file
|
@ -0,0 +1,430 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
from rattail.django.rattail.tests.models import ModelTestCase
|
||||
from rattail.django.rattail import models
|
||||
|
||||
|
||||
class ModelTests(ModelTestCase):
|
||||
|
||||
def test_managed(self):
|
||||
model = self.model()
|
||||
self.assertTrue(model._meta.managed)
|
||||
self.assertTrue(model._meta.db_table.startswith('rattail_'))
|
||||
|
||||
|
||||
class PhoneNumberTests(ModelTests):
|
||||
model = models.PhoneNumber
|
||||
|
||||
def test_repr(self):
|
||||
phone = models.PhoneNumber()
|
||||
phone.number = '800-555-1234'
|
||||
self.assertEqual(repr(phone), '<PhoneNumber: 800-555-1234>')
|
||||
|
||||
def test_unicode(self):
|
||||
phone = models.PhoneNumber()
|
||||
phone.number = '800-555-1234'
|
||||
self.assertEqual(unicode(phone), u'800-555-1234')
|
||||
|
||||
|
||||
class EmailAddressTests(ModelTests):
|
||||
model = models.EmailAddress
|
||||
|
||||
def test_repr(self):
|
||||
email = models.EmailAddress()
|
||||
email.address = 'test@edbob.org'
|
||||
self.assertEqual(repr(email), '<EmailAddress: test@edbob.org>')
|
||||
|
||||
def test_unicode(self):
|
||||
email = models.EmailAddress()
|
||||
email.address = 'test@edbob.org'
|
||||
self.assertEqual(unicode(email), u'test@edbob.org')
|
||||
|
||||
|
||||
class PostalAddressTests(ModelTests):
|
||||
model = models.PostalAddress
|
||||
|
||||
def test_repr(self):
|
||||
address = models.PostalAddress()
|
||||
address.street = '123 Main St.'
|
||||
self.assertEqual(repr(address), '<PostalAddress: 123 Main St.>')
|
||||
|
||||
def test_unicode(self):
|
||||
address = models.PostalAddress()
|
||||
address.street = '123 Main St.'
|
||||
self.assertEqual(unicode(address), u'123 Main St.')
|
||||
|
||||
|
||||
class ContactTestsMixin(object):
|
||||
|
||||
def test_get_info_dict(self):
|
||||
model = self.model()
|
||||
self.assertRaises(ValueError, model._get_info_dict, object)
|
||||
|
||||
def test_get_info_key(self):
|
||||
model = self.model()
|
||||
self.assertRaises(ValueError, model._get_info_key, object)
|
||||
|
||||
def test_update_phone(self):
|
||||
model = self.model()
|
||||
phone = model.update_phone('test', dict(
|
||||
number='800-555-1234'))
|
||||
self.assertTrue(phone)
|
||||
self.assertEqual(phone.number, '800-555-1234')
|
||||
|
||||
def test_get_phone(self):
|
||||
model = self.model()
|
||||
phone = model.update_phone('test', dict(
|
||||
number='800-555-1234'))
|
||||
self.assertTrue(phone)
|
||||
self.assertIs(model.get_phone('test'), phone)
|
||||
|
||||
def test_set_preferred_phone_single(self):
|
||||
model = self.model()
|
||||
phone = model.update_phone('test', dict(
|
||||
number='800-555-1234'))
|
||||
self.assertTrue(phone)
|
||||
model.set_preferred_phone(phone)
|
||||
self.assertIs(model.get_preferred_phone(), phone)
|
||||
|
||||
def test_set_preferred_phone_multiple(self):
|
||||
model = self.model()
|
||||
phone1 = model.update_phone('test1', dict(
|
||||
number='800-555-1234'))
|
||||
self.assertTrue(phone1)
|
||||
phone2 = model.update_phone('test2', dict(
|
||||
number='800-555-6789'))
|
||||
self.assertTrue(phone2)
|
||||
model.set_preferred_phone(phone2)
|
||||
self.assertIs(model.get_preferred_phone(), phone2)
|
||||
self.assertEqual(phone2.preference, 1)
|
||||
phone1 = model.get_phone('test1')
|
||||
self.assertEqual(phone1.preference, 2)
|
||||
|
||||
def test_get_preferred_phone(self):
|
||||
model = self.model()
|
||||
phone = model.update_phone('test', dict(
|
||||
number='800-555-1234'))
|
||||
self.assertTrue(phone)
|
||||
model.set_preferred_phone(phone)
|
||||
self.assertIs(model.get_preferred_phone(), phone)
|
||||
self.assertIs(model.phone, phone)
|
||||
|
||||
model._preferred.clear()
|
||||
phone = model.get_preferred_phone()
|
||||
self.assertEqual(phone.number, '800-555-1234')
|
||||
|
||||
phone.delete()
|
||||
model._preferred.clear()
|
||||
self.assertIs(model.phone, None)
|
||||
|
||||
def test_update_email(self):
|
||||
model = self.model()
|
||||
email = model.update_email('test', dict(
|
||||
address='test@edbob.org'))
|
||||
self.assertTrue(email)
|
||||
self.assertEqual(email.address, 'test@edbob.org')
|
||||
|
||||
def test_get_email(self):
|
||||
model = self.model()
|
||||
email = model.update_email('test', dict(
|
||||
address='test@edbob.org'))
|
||||
self.assertTrue(email)
|
||||
self.assertIs(model.get_email('test'), email)
|
||||
|
||||
def test_set_preferred_email_single(self):
|
||||
model = self.model()
|
||||
email = model.update_email('test', dict(
|
||||
address='test@edbob.org'))
|
||||
self.assertTrue(email)
|
||||
model.set_preferred_email(email)
|
||||
self.assertIs(model.get_preferred_email(), email)
|
||||
|
||||
def test_set_preferred_email_multiple(self):
|
||||
model = self.model()
|
||||
email1 = model.update_email('email1', dict(
|
||||
address='test@edbob.org'))
|
||||
self.assertTrue(email1)
|
||||
email2 = model.update_email('test2', dict(
|
||||
address='test@edbob.org'))
|
||||
self.assertTrue(email2)
|
||||
model.set_preferred_email(email2)
|
||||
self.assertIs(model.get_preferred_email(), email2)
|
||||
self.assertEqual(email2.preference, 1)
|
||||
phone1 = model.get_email('test1')
|
||||
self.assertEqual(email1.preference, 2)
|
||||
|
||||
def test_get_preferred_email(self):
|
||||
model = self.model()
|
||||
email = model.update_email('test', dict(
|
||||
address='test@edbob.org'))
|
||||
self.assertTrue(email)
|
||||
model.set_preferred_email(email)
|
||||
self.assertIs(model.get_preferred_email(), email)
|
||||
self.assertIs(model.email, email)
|
||||
|
||||
model._preferred.clear()
|
||||
email = model.get_preferred_email()
|
||||
self.assertEqual(email.address, 'test@edbob.org')
|
||||
|
||||
email.delete()
|
||||
model._preferred.clear()
|
||||
self.assertIs(model.email, None)
|
||||
|
||||
def test_update_address(self):
|
||||
model = self.model()
|
||||
address = model.update_address('test', dict(
|
||||
street='123 Main St.'))
|
||||
self.assertTrue(address)
|
||||
self.assertEqual(address.street, '123 Main St.')
|
||||
|
||||
def test_get_address(self):
|
||||
model = self.model()
|
||||
address = model.update_address('test', dict(
|
||||
street='123 Main St.'))
|
||||
self.assertTrue(address)
|
||||
self.assertIs(model.get_address('test'), address)
|
||||
|
||||
def test_set_preferred_address_single(self):
|
||||
model = self.model()
|
||||
address = model.update_address('test', dict(
|
||||
street='123 Main St.'))
|
||||
self.assertTrue(address)
|
||||
model.set_preferred_address(address)
|
||||
self.assertIs(model.get_preferred_address(), address)
|
||||
|
||||
def test_set_preferred_address_multiple(self):
|
||||
model = self.model()
|
||||
address1 = model.update_address('address1', dict(
|
||||
street='123 Main St.'))
|
||||
self.assertTrue(address1)
|
||||
address2 = model.update_address('test2', dict(
|
||||
street='123 Main St.'))
|
||||
self.assertTrue(address2)
|
||||
model.set_preferred_address(address2)
|
||||
self.assertIs(model.get_preferred_address(), address2)
|
||||
self.assertEqual(address2.preference, 1)
|
||||
phone1 = model.get_address('test1')
|
||||
self.assertEqual(address1.preference, 2)
|
||||
|
||||
def test_get_preferred_address(self):
|
||||
model = self.model()
|
||||
address = model.update_address('test', dict(
|
||||
street='123 Main St.'))
|
||||
self.assertTrue(address)
|
||||
model.set_preferred_address(address)
|
||||
self.assertIs(model.get_preferred_address(), address)
|
||||
self.assertIs(model.address, address)
|
||||
|
||||
model._preferred.clear()
|
||||
address = model.get_preferred_address()
|
||||
self.assertEqual(address.street, '123 Main St.')
|
||||
|
||||
address.delete()
|
||||
model._preferred.clear()
|
||||
self.assertIs(model.address, None)
|
||||
|
||||
|
||||
class PersonTests(ModelTests, ContactTestsMixin):
|
||||
model = models.Person
|
||||
|
||||
def test_repr(self):
|
||||
person = models.Person()
|
||||
person.display_name = 'Fred Flintstone'
|
||||
self.assertEqual(repr(person), '<Person: Fred Flintstone>')
|
||||
|
||||
def test_unicode(self):
|
||||
person = models.Person()
|
||||
person.display_name = 'Fred Flintstone'
|
||||
self.assertEqual(unicode(person), u'Fred Flintstone')
|
||||
|
||||
def test_display_name(self):
|
||||
person = models.Person()
|
||||
person.first_name = 'Fred'
|
||||
person.last_name = 'Flintstone'
|
||||
person.update_display_name()
|
||||
self.assertEqual(person.display_name, 'Fred Flintstone')
|
||||
|
||||
def test_display_name_first(self):
|
||||
person = models.Person()
|
||||
person.first_name = 'Fred'
|
||||
person.update_display_name()
|
||||
self.assertEqual(person.display_name, 'Fred')
|
||||
|
||||
def test_display_name_last(self):
|
||||
person = models.Person()
|
||||
person.last_name = 'Flintstone'
|
||||
person.update_display_name()
|
||||
self.assertEqual(person.display_name, 'Flintstone')
|
||||
|
||||
def test_display_name_save(self):
|
||||
person = models.Person()
|
||||
person.first_name = 'Fred'
|
||||
person.last_name = 'Flintstone'
|
||||
person.save()
|
||||
self.assertEqual(person.display_name, 'Fred Flintstone')
|
||||
|
||||
def test_employee(self):
|
||||
person = models.Person()
|
||||
self.assertIs(person.employee, None)
|
||||
person.save()
|
||||
employee = models.Employee()
|
||||
employee.person = person
|
||||
employee.save()
|
||||
self.assertTrue(person.employee)
|
||||
|
||||
def test_make_employee(self):
|
||||
person = models.Person()
|
||||
self.assertIs(person.employee, None)
|
||||
person.make_employee()
|
||||
self.assertTrue(person.employee)
|
||||
# Once more for full code coverage...
|
||||
person.make_employee()
|
||||
|
||||
def test_unmake_employee(self):
|
||||
person = models.Person()
|
||||
person.make_employee()
|
||||
self.assertTrue(person.employee)
|
||||
person.unmake_employee()
|
||||
self.assertIs(person.employee, None)
|
||||
|
||||
|
||||
class PartyTests(ModelTests):
|
||||
model = models.Party
|
||||
|
||||
def test_unicode(self):
|
||||
person = models.Person()
|
||||
person.display_name = 'Fred Flintstone'
|
||||
party = models.Party()
|
||||
party.person = person
|
||||
party.type = 'test'
|
||||
self.assertEqual(unicode(party), u'Fred Flintstone (test)')
|
||||
|
||||
|
||||
class PartyManagerTestsMixin(object):
|
||||
models = models.Party
|
||||
|
||||
def test_queryset(self):
|
||||
# TODO: This should really assert something...
|
||||
qs = self.model.objects
|
||||
qs.all()
|
||||
|
||||
|
||||
class RoleTests(ModelTests):
|
||||
model = models.Role
|
||||
|
||||
def test_repr(self):
|
||||
role = models.Role()
|
||||
role.name = 'Test'
|
||||
self.assertEqual(repr(role), '<Role: Test>')
|
||||
|
||||
def test_unicode(self):
|
||||
role = models.Role()
|
||||
role.name = 'Test'
|
||||
self.assertEqual(unicode(role), u'Test')
|
||||
|
||||
|
||||
class UserTests(ModelTests):
|
||||
model = models.User
|
||||
|
||||
def test_repr(self):
|
||||
user = models.User()
|
||||
user.username = 'test'
|
||||
self.assertEqual(repr(user), '<User: test>')
|
||||
|
||||
def test_unicode(self):
|
||||
user = models.User()
|
||||
user.username = 'test'
|
||||
self.assertEqual(unicode(user), u'test')
|
||||
|
||||
def test_display_name(self):
|
||||
user = models.User()
|
||||
user.username = 'test'
|
||||
self.assertEqual(user.display_name, 'test')
|
||||
|
||||
def test_person_display_name(self):
|
||||
person = models.Person()
|
||||
person.display_name = 'Fred Flintstone'
|
||||
user = models.User()
|
||||
user.person = person
|
||||
self.assertEqual(user.display_name, 'Fred Flintstone')
|
||||
|
||||
|
||||
class UserRoleTests(ModelTests):
|
||||
model = models.UserRole
|
||||
|
||||
def test_repr(self):
|
||||
user = models.User()
|
||||
user.username = 'test'
|
||||
role = models.Role()
|
||||
role.name = 'Test'
|
||||
user_role = models.UserRole()
|
||||
user_role.user = user
|
||||
user_role.role = role
|
||||
self.assertEqual(repr(user_role), '<UserRole: test, Test>')
|
||||
|
||||
def test_unicode(self):
|
||||
role = models.Role()
|
||||
role.name = 'Test'
|
||||
user_role = models.UserRole()
|
||||
user_role.role = role
|
||||
self.assertEqual(unicode(user_role), u'Test')
|
||||
|
||||
|
||||
class StoreTests(ModelTests):
|
||||
model = models.Store
|
||||
|
||||
|
||||
class DepartmentTests(ModelTests):
|
||||
model = models.Department
|
||||
|
||||
|
||||
class SubdepartmentTests(ModelTests):
|
||||
model = models.Subdepartment
|
||||
|
||||
|
||||
class CategoryTests(ModelTests):
|
||||
model = models.Category
|
||||
|
||||
|
||||
class BrandTests(ModelTests):
|
||||
model = models.Brand
|
||||
|
||||
|
||||
class VendorTests(ModelTests):
|
||||
model = models.Vendor
|
||||
|
||||
|
||||
class ProductTests(ModelTests):
|
||||
model = models.Product
|
||||
|
||||
|
||||
class ProductPriceTests(ModelTests):
|
||||
model = models.ProductPrice
|
||||
|
||||
|
||||
class ProductCostTests(ModelTests):
|
||||
model = models.ProductCost
|
||||
|
||||
|
||||
class EmployeeTests(ModelTests):
|
||||
model = models.Employee
|
||||
|
||||
|
||||
class CustomerGroupTests(ModelTests):
|
||||
model = models.CustomerGroup
|
||||
|
||||
|
||||
class CustomerTests(ModelTests):
|
||||
model = models.Customer
|
||||
|
||||
|
||||
class CustomerGroupAssignmentTests(ModelTests):
|
||||
model = models.CustomerGroupAssignment
|
||||
|
||||
|
||||
class CustomerPartyTests(PartyTests, PartyManagerTestsMixin):
|
||||
model = models.CustomerParty
|
||||
|
||||
|
||||
class LabelProfileTests(ModelTests):
|
||||
model = models.LabelProfile
|
11
rattail/django/rattail/tests/models/unmanaged.py
Normal file
11
rattail/django/rattail/tests/models/unmanaged.py
Normal file
|
@ -0,0 +1,11 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
from rattail.django.rattail.tests.models import ModelTestCase
|
||||
|
||||
|
||||
class ModelTests(ModelTestCase):
|
||||
|
||||
def test_unmanaged(self):
|
||||
model = self.model()
|
||||
self.assertFalse(model._meta.managed)
|
||||
self.assertFalse(model._meta.db_table.startswith('rattail_'))
|
0
rattail/django/rattail/tests/settings/__init__.py
Normal file
0
rattail/django/rattail/tests/settings/__init__.py
Normal file
14
rattail/django/rattail/tests/settings/base.py
Normal file
14
rattail/django/rattail/tests/settings/base.py
Normal file
|
@ -0,0 +1,14 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
|
||||
INSTALLED_APPS = (
|
||||
'south',
|
||||
'rattail.django.rattail',
|
||||
'django_nose',
|
||||
)
|
||||
|
||||
|
||||
TEST_RUNNER = 'django_nose.NoseTestSuiteRunner'
|
||||
|
||||
|
||||
from rattail.django.rattail.tests.settings.local import *
|
21
rattail/django/rattail/tests/settings/local.py
Normal file
21
rattail/django/rattail/tests/settings/local.py
Normal file
|
@ -0,0 +1,21 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
|
||||
DATABASES = {
|
||||
'default': {
|
||||
'ENGINE': 'django.db.backends.postgresql_psycopg2',
|
||||
'NAME': 'rattail.django',
|
||||
'USER': 'rattail',
|
||||
'PASSWORD': 'rattail',
|
||||
'HOST': '',
|
||||
'PORT': '',
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
NOSE_ARGS = [
|
||||
'--with-coverage',
|
||||
'--cover-package=rattail.django',
|
||||
'--cover-html',
|
||||
r'--cover-html-dir=C:\envs\rattail.django\app\coverage',
|
||||
]
|
6
rattail/django/rattail/tests/settings/managed.py
Normal file
6
rattail/django/rattail/tests/settings/managed.py
Normal file
|
@ -0,0 +1,6 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
from rattail.django.rattail.tests.settings.base import *
|
||||
|
||||
|
||||
RATTAIL_DJANGO_MANAGED = True
|
6
rattail/django/rattail/tests/settings/unmanaged.py
Normal file
6
rattail/django/rattail/tests/settings/unmanaged.py
Normal file
|
@ -0,0 +1,6 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
from rattail.django.rattail.tests.settings.base import *
|
||||
|
||||
|
||||
RATTAIL_DJANGO_MANAGED = False
|
Loading…
Reference in a new issue