Files
@ f66126ca6fec
Branch filter:
Location: rattail-project/rattail/tests/db/test_model.py
f66126ca6fec
4.4 KiB
text/x-python
Added `--do-not-daemonize` flag to `dbsync` command on Linux.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
from unittest import TestCase
from . import DataTestCase
from rattail.db.extension import model
from sqlalchemy.exc import IntegrityError
class TestCustomer(DataTestCase):
def test_repr(self):
customer = model.Customer(uuid='whatever')
self.assertEqual(repr(customer), "Customer(uuid='whatever')")
def test_unicode(self):
customer = model.Customer()
self.assertEqual(unicode(customer), u'None')
customer = model.Customer(name='Fred')
self.assertEqual(unicode(customer), u'Fred')
def test_cascade_delete_assignment(self):
customer = model.Customer()
assignment = model.CustomerGroupAssignment(
customer=customer, group=model.CustomerGroup(), ordinal=1)
self.session.add_all([customer, assignment])
self.session.commit()
self.assertEqual(self.session.query(model.CustomerGroupAssignment).count(), 1)
self.session.delete(customer)
self.session.commit()
self.assertEqual(self.session.query(model.CustomerGroupAssignment).count(), 0)
class TestCustomerPerson(DataTestCase):
def test_repr(self):
assoc = model.CustomerPerson(uuid='whatever')
self.assertEqual(repr(assoc), "CustomerPerson(uuid='whatever')")
def test_customer_required(self):
assoc = model.CustomerPerson(person=model.Person())
self.session.add(assoc)
self.assertRaises(IntegrityError, self.session.commit)
self.session.rollback()
self.assertEqual(self.session.query(model.CustomerPerson).count(), 0)
assoc.customer = model.Customer()
self.session.add(assoc)
self.session.commit()
self.assertEqual(self.session.query(model.CustomerPerson).count(), 1)
def test_person_required(self):
assoc = model.CustomerPerson(customer=model.Customer())
self.session.add(assoc)
self.assertRaises(IntegrityError, self.session.commit)
self.session.rollback()
self.assertEqual(self.session.query(model.CustomerPerson).count(), 0)
assoc.person = model.Person()
self.session.add(assoc)
self.session.commit()
self.assertEqual(self.session.query(model.CustomerPerson).count(), 1)
def test_ordinal_autoincrement(self):
customer = model.Customer()
self.session.add(customer)
assoc = model.CustomerPerson(person=model.Person())
customer._people.append(assoc)
self.session.commit()
self.assertEqual(assoc.ordinal, 1)
assoc = model.CustomerPerson(person=model.Person())
customer._people.append(assoc)
self.session.commit()
self.assertEqual(assoc.ordinal, 2)
class TestCustomerGroupAssignment(DataTestCase):
def test_repr(self):
assignment = model.CustomerGroupAssignment(uuid='whatever')
self.assertEqual(repr(assignment), "CustomerGroupAssignment(uuid='whatever')")
def test_customer_required(self):
assignment = model.CustomerGroupAssignment(group=model.CustomerGroup())
self.session.add(assignment)
self.assertRaises(IntegrityError, self.session.commit)
self.session.rollback()
self.assertEqual(self.session.query(model.CustomerGroupAssignment).count(), 0)
assignment.customer = model.Customer()
self.session.add(assignment)
self.session.commit()
self.assertEqual(self.session.query(model.CustomerGroupAssignment).count(), 1)
def test_group_required(self):
assignment = model.CustomerGroupAssignment(customer=model.Customer())
self.session.add(assignment)
self.assertRaises(IntegrityError, self.session.commit)
self.session.rollback()
self.assertEqual(self.session.query(model.CustomerGroupAssignment).count(), 0)
assignment.group = model.CustomerGroup()
self.session.add(assignment)
self.session.commit()
self.assertEqual(self.session.query(model.CustomerGroupAssignment).count(), 1)
def test_ordinal_autoincrement(self):
customer = model.Customer()
self.session.add(customer)
assignment = model.CustomerGroupAssignment(group=model.CustomerGroup())
customer._groups.append(assignment)
self.session.commit()
self.assertEqual(assignment.ordinal, 1)
assignment = model.CustomerGroupAssignment(group=model.CustomerGroup())
customer._groups.append(assignment)
self.session.commit()
self.assertEqual(assignment.ordinal, 2)
|