Exemple #1
0
    def test_update_or_create(self):
        d = {'name': 'winboat'}
        e = twsu.update_or_create(self.DBTestCls1, d)
        self.session.flush()
        assert(e.id == 2)
        assert(e.name == 'winboat')

        d = {'id': 1, 'name': 'winboat'}
        e = twsu.update_or_create(self.DBTestCls1, d)
        self.session.flush()
        assert(e.id == 1)
        assert(e.name == 'winboat')
Exemple #2
0
    def test_update_or_create(self):
        d = {'name': 'winboat'}
        e = twsu.update_or_create(self.DBTestCls1, d)
        self.session.flush()
        assert (e.id == 2)
        assert (e.name == 'winboat')

        d = {'id': 1, 'name': 'winboat'}
        e = twsu.update_or_create(self.DBTestCls1, d)
        self.session.flush()
        assert (e.id == 1)
        assert (e.name == 'winboat')
Exemple #3
0
 def test_update_or_create_exception(self):
     d = {'id': 55, 'name': 'failboat'}
     try:
         e = twsu.update_or_create(self.DBTestCls1, d)
         assert (False)
     except Exception, e:
         assert ([s in str(e) for s in ['cannot create', 'with pk']])
Exemple #4
0
 def test_update_or_create_exception(self):
     d = {
         'id': 55,
         'name': 'failboat'
     }
     try:
         e = twsu.update_or_create(self.DBTestCls1, d)
         assert(False)
     except Exception, e:
         assert([s in str(e) for s in ['cannot create', 'with pk']])
Exemple #5
0
    def test_update_or_create_with_zero(self):
        """ Ensure that 0 doesn't get interpreted as None.

        For the following issue:  http://bit.ly/OiFUfb
        """

        d = {'name': 'winboat', 'some_number': 0}
        e = twsu.update_or_create(self.DBTestCls1, d)
        self.session.flush()
        eq_(e.some_number, 0)
Exemple #6
0
    def test_update_or_create_with_zero(self):
        """ Ensure that 0 doesn't get interpreted as None.

        For the following issue:  http://bit.ly/OiFUfb
        """

        d = {'name': 'winboat', 'some_number': 0}
        e = twsu.update_or_create(self.DBTestCls1, d)
        self.session.flush()
        eq_(e.some_number, 0)
Exemple #7
0
 def insert_or_update(cls, data):
     """ Wrapper for tw2.sqla.utils update_or_create() 
         Basically checks object for primary key values then
         either inserts into or updates the DB accordingly""" 
     sautil.update_or_create(cls.entity, data)