Пример #1
0
 def test_dbkey(self):
     obj = objects.BadHuman()
     obj.name = "Anne"
     obj.email = "*****@*****.**"
     _id = obj.save()
     dic = obj.find_one({"_id": _id}, as_dict=True)
     dic.get("em")
Пример #2
0
 def post(self, *args, **kwargs):
     context = {"success":False, "data":None, "html":None}
     try:
         submit = json.loads(self.get_argument("form", "{}"))
         print submit
     except Exception as e:
         print e
     else:
         obj = objects.BadHuman()
         form = objects.SimpleForm(object=obj, action="/", id="test", data=submit)
         try:
             form.validate()
             id = obj.save()
             context['data'] = str(id)
             context['success'] = True
         except orm.DocumentException as e:
             context['success'] = False
             obj = {}
             for k,v in e.errors.iteritems():
                 obj[k] = v.message
             context['data'] = obj
         finally:
             context['html'] = self.render_string("form.html", form=form)
             print context
             self.finish(json.dumps(context))
Пример #3
0
 def test_choice_render(self):
     _id = self.car.save()
     select = self.choice_html % str(_id)
     obj = objects.BadHuman()
     text = widget.Select(object=obj._get("car"),
                          item_render=objects.car_disp,
                          name='car').render(cls="Woot")
     self.assertEqual(text.strip(), select.strip())
Пример #4
0
    def test_validation(self):
        obj = objects.BadHuman()
        obj.state = "Illinois"
        with self.assertRaises(orm.DocumentException) as cm:
            obj.save()

        obj.country = "USA"
        obj.state = "Illinois"
Пример #5
0
 def test_checkbox(self):
     obj = objects.BadHuman()
     text = widget.CheckBox(object=obj._get("active")).render()
     print text
     with self.assertRaises(Exception) as cm:
         correct = text.index("CHECKED")
     obj.active = True
     checked = widget.CheckBox(object=obj._get("active")).render()
     print checked
     correct = checked.index("CHECKED")
     self.assertGreater(correct, -1)
Пример #6
0
    def test_email(self):
        obj = objects.BadHuman()
        obj.name = "Anne"
        obj.email = "sdsdff"
        self.assertEqual(obj._get("email")._error.__class__.__name__, "FieldException")

        obj.email = "test@trest"
        self.assertEqual(obj._get("email")._error.__class__.__name__, "FieldException")

        obj.email = "*****@*****.**"
        self.assertEqual(obj.email, "*****@*****.**")
Пример #7
0
    def test_phone(self):
        obj = objects.BadHuman()
        print obj._get("phone")
        obj.name = "Anne"
        obj.phone = "sjkdhfkjshdfksjhdf"
        print obj._get("phone")
        self.assertEqual(obj._get("phone")._error.__class__.__name__, "FieldException")

        obj.phone = "810-542.0141"
        self.assertEqual(obj.phone, u"+18105420141")

        obj.phone = "1-810-542.0141"
        self.assertEqual(obj.phone, u"+18105420141")
Пример #8
0
 def setUp(self):
     self.obj = objects.BadHuman()
     self.obj.name = "Anne"
     self.obj.age = 27
     self.obj.height = 65
     self.obj.weight = 120
     self.submit = {
         "name": "",
         "human_id": "32226",
         "age": None,
         "weight": "175",
         "location-city": "Chicago",
         "location-state": "IL"
     }
Пример #9
0
    def test_mongo_exception(self):
        obj = objects.BadHuman()
        obj._coll.ensure_index("name", unique=True)
        obj.name = "Test"
        obj.save()

        obj2 = objects.BadHuman()
        obj2.name = "Test"
        with self.assertRaises(Exception) as cm:
            _id = obj2.save()

        obj.__class__.__remove__()
        obj3 = objects.BadHuman()
        obj3.name = "Test"
        obj3.save()

        obj4 = objects.BadHuman()
        obj4.name = "Tester"
        obj4.save()
        obj4.name = "Test"
        with self.assertRaises(Exception) as cm:
            _id2 = obj4.save()

        obj._coll.drop_indexes()
Пример #10
0
    def test_file(self):
        obj = objects.BadHuman()
        obj.name = "Anne"
        path = os.path.dirname(__file__)
        print path
        obj.avatar = file("%s/%s" % (path, "penguin.jpg"))
        f_id = obj.avatar
        self.assertEqual(obj._get("avatar").exists(), True)
        _id = obj.save()
        o = objects.BadHuman(id=_id)
        self.assertEqual(o.avatar, f_id)
        print o._get("avatar")()
        print o._get("avatar").list()
        print o._get("avatar").delete()
        self.assertEqual(obj._get("avatar").exists(), False)
        obj2 = objects.BadHuman()
        with self.assertRaises(FieldException) as cm:
            obj2._get("avatar")()

        obj2.name = "Anne"
        obj2.avatar = objects.BadHuman()
        with self.assertRaises(orm.DocumentException) as cm:
            obj2.save()
            print cm.exception.errors
Пример #11
0
 def test_empty(self):
     obj = objects.BadHuman()
     with self.assertRaises(orm.DocumentException) as cm:
         obj.save()