Beispiel #1
0
 def test_institution_to_json(self):
     institution = Institution(_id=1,
                               name="Test Bank",
                               type=Institution.TYPES[1],
                               user_id=1)
     self.assertEqual(
         {
             "_id": "1",
             "name": "Test Bank",
             "type": Institution.TYPES[1],
             "user_id": 1
         }, institution.to_json())
Beispiel #2
0
    def test_institution_constructor_requirements(self):
        with self.assertRaises(ValueError):
            Institution()

        with self.assertRaises(ValueError):
            Institution(name="Test Bank", type=None)

        with self.assertRaises(ValueError):
            Institution(type=Institution.TYPES[0])

        with self.assertRaises(ValueError):
            Institution(name="Test Bank", type="Bad Type")
Beispiel #3
0
 def test_institution_repr(self):
     institution = Institution(_id=1,
                               name="Test Bank",
                               type=Institution.TYPES[1],
                               user_id=1)
     self.assertEqual(
         '{"user_id": 1, "_id": "1", "type": "SAVING", "name": "Test Bank"}',
         repr(institution))
Beispiel #4
0
 def test_institution_str(self):
     institution = Institution(_id=1,
                               name="Test Bank",
                               type=Institution.TYPES[1],
                               user_id=1)
     self.assertEqual(
         "<Institution: _id=1, name=Test Bank, type=SAVING, user_id=1>",
         str(institution))
    def post(self):
        logger.debug("------ %s\n%s" % (self.request.headers, self.request.body))
        params = self.json_args
        name = None
        type = Institution.TYPES[3]
        user_id = None

        for field in params:
            logger.info("Field = %s" % field)
            if field[u'name'] == u'name':
                name = field[u'value']
            if field[u'name'] == u'type':
                type = field[u'value']
            if field[u'name'] == u'user_id':
                user_id = field[u'value']

        institution = Institution(name=name, type=type, user_id=user_id)
        logger.debug(">>>>>>>>> %s" % institution)
        db = self.settings['db']
        result = yield db.institutions.insert(institution.to_motor_create_json())
        logger.debug("XXXXXXXX result = %s" % result)
        self.finish()
Beispiel #6
0
    def post(self):
        logger.debug("------ %s\n%s" %
                     (self.request.headers, self.request.body))
        params = self.json_args
        name = None
        type = Institution.TYPES[3]
        user_id = None

        for field in params:
            logger.info("Field = %s" % field)
            if field[u'name'] == u'name':
                name = field[u'value']
            if field[u'name'] == u'type':
                type = field[u'value']
            if field[u'name'] == u'user_id':
                user_id = field[u'value']

        institution = Institution(name=name, type=type, user_id=user_id)
        logger.debug(">>>>>>>>> %s" % institution)
        db = self.settings['db']
        result = yield db.institutions.insert(
            institution.to_motor_create_json())
        logger.debug("XXXXXXXX result = %s" % result)
        self.finish()
 def get(self, args=None):
     logger.debug("--json=%s-- %s\n%s\n%s" % (self.produce_json, self.request.headers, self.request.body, args))
     db = self.settings['db']
     cursor = db.institutions.find()
     institutions = []
     while (yield cursor.fetch_next):
         document = cursor.next_object()
         inst = Institution.from_db_rep(document)
         dict=inst.to_json()
         user = yield db.users.find_one(id)  # This doesn't work.  I think I need to make it all in one doc. Yay nosql
         dict['user_name'] = user['name']
         institutions.append(dict)
     if self.produce_json:
         self.write(dict(result=institutions))
     else:
         self.render("templ_institution.html")
Beispiel #8
0
 def get(self, args=None):
     logger.debug(
         "--json=%s-- %s\n%s\n%s" %
         (self.produce_json, self.request.headers, self.request.body, args))
     db = self.settings['db']
     cursor = db.institutions.find()
     institutions = []
     while (yield cursor.fetch_next):
         document = cursor.next_object()
         inst = Institution.from_db_rep(document)
         dict = inst.to_json()
         user = yield db.users.find_one(
             id
         )  # This doesn't work.  I think I need to make it all in one doc. Yay nosql
         dict['user_name'] = user['name']
         institutions.append(dict)
     if self.produce_json:
         self.write(dict(result=institutions))
     else:
         self.render("templ_institution.html")
Beispiel #9
0
 def test_basic_institution_constructor(self):
     institution = Institution(name="Test Bank", type=Institution.TYPES[0])
     self.assertEqual(institution.name, "Test Bank")
     self.assertEqual(institution.type, Institution.TYPES[0])
 def test_institution_to_json(self):
     institution = Institution(_id=1, name="Test Bank", type=Institution.TYPES[1], user_id=1)
     self.assertEqual({"_id": "1", "name": "Test Bank", "type": Institution.TYPES[1], "user_id": 1},
                      institution.to_json())