Esempio n. 1
0
 def create(cls):
     "Install initial data."
     for fields in cls.data:
         fields = fields.copy()
         cls.load_client(fields)
         keys = [fields[key] for key in cls.dao.keys]
         if cls.dao.has_client_as_key:
             exists = cls.dao.exists(*keys, **dict(client=fields['client']))
         else:
             exists = cls.dao.exists(*keys)
         if not exists:
             cls.dao.create(**fields)
     db.commit()
Esempio n. 2
0
 def create(cls):
     "Install initial data."
     for fields in cls.data:
         fields = fields.copy()
         cls.load_client(fields)
         keys = [fields[key] for key in cls.dao.keys]
         if cls.dao.has_client_as_key:
             exists = cls.dao.exists(*keys, **dict(client=fields['client']))
         else:
             exists = cls.dao.exists(*keys)
         if not exists:
             cls.dao.create(**fields)
     db.commit()
Esempio n. 3
0
 def test_no_accounts(self):
     "Make sure it works with accounts left out."
     data = {'address': u'no_accounts',
             'client': client_data[0]['name'],
             'owner': u'xomdofj fjkls'}
     self.load_client(data)
     AddressDAO.create(**data)
     db.commit()
     data['accounts'] = []
     obj = AddressDAO.get(data['address'])
     data_dict = obj.data_dict()
     data_dict['client'] = obj.data_obj.client
     self.assertEquals(data_dict, data)
Esempio n. 4
0
 def test_no_accounts(self):
     "Make sure it works with accounts left out."
     data = {
         'address': u'no_accounts',
         'client': client_data[0]['name'],
         'owner': u'xomdofj fjkls'
     }
     self.load_client(data)
     AddressDAO.create(**data)
     db.commit()
     data['accounts'] = []
     obj = AddressDAO.get(data['address'])
     data_dict = obj.data_dict()
     data_dict['client'] = obj.data_obj.client
     self.assertEquals(data_dict, data)
Esempio n. 5
0
 def create(cls):
     RelationshipDAO.create(id=cls.data[0]['relationship'])
     RelationshipDAO.create(id=cls.data[2]['relationship'])
     db.commit()
     super(AccountDAOTest, cls).create()
Esempio n. 6
0
def create_unit_data():
    for unit in unit_data:
        UnitDAO.create(**unit)
    db.commit()
Esempio n. 7
0
def create_client_data():
    for client in client_data:
        c = Client()
        c.name = client['name']
    db.commit()
Esempio n. 8
0
            if content:
                request.parsed_content = json.decode(content)
                if settings.DEBUG: print content
            if settings.DEBUG: print db.session
            # handle outgoing data
            body = SiteResource.render(self, request)
        except Http404, h:
            if settings.DEBUG: traceback.print_exc()
            request.setResponseCode(http.NOT_FOUND)
            body = {'error': str(h)}
        except Exception, e:  # *** this might catch too much
            if settings.DEBUG: traceback.print_exc()
            request.setResponseCode(http.INTERNAL_SERVER_ERROR)
            body = {'error': str(e)}
        else:
            db.commit()
        # close out db session -- very important with threads
        db.close()
        if body not in (None, ''):
            json_body = encode_response(body)
            if settings.DEBUG:
                print json_body
            return json_body
        return ''

def encode_response(response):
    # twisted web expects regular str, which encode('utf-8') gives
    return json.encode(response).encode('utf-8')
    
class ThreadedJSONSiteResource(JSONSiteResource):
    "Run each request in its own thread."
Esempio n. 9
0
 def create(cls):
     RelationshipDAO.create(id=cls.data[0]['relationship'])
     RelationshipDAO.create(id=cls.data[2]['relationship'])
     db.commit()
     super(AccountDAOTest, cls).create()
Esempio n. 10
0
def create_unit_data():
    for unit in unit_data:
        UnitDAO.create(**unit)
    db.commit()
Esempio n. 11
0
def create_client_data():
    for client in client_data:
        c = Client()
        c.name = client['name']
    db.commit()
Esempio n. 12
0
            if content:
                request.parsed_content = json.decode(content)
                if settings.DEBUG: print content
            if settings.DEBUG: print db.session
            # handle outgoing data
            body = SiteResource.render(self, request)
        except Http404, h:
            if settings.DEBUG: traceback.print_exc()
            request.setResponseCode(http.NOT_FOUND)
            body = {'error': str(h)}
        except Exception, e:  # *** this might catch too much
            if settings.DEBUG: traceback.print_exc()
            request.setResponseCode(http.INTERNAL_SERVER_ERROR)
            body = {'error': str(e)}
        else:
            db.commit()
        # close out db session -- very important with threads
        db.close()
        if body not in (None, ''):
            json_body = encode_response(body)
            if settings.DEBUG:
                print json_body
            return json_body
        return ''


def encode_response(response):
    # twisted web expects regular str, which encode('utf-8') gives
    return json.encode(response).encode('utf-8')