def wrapper(*args, **kwargs): self = args[0] sign = self.get_argument('sign', None) if not sign: raise ValueError(4) appid = self.get_argument('appid', None) if not appid: raise ValueError(5) model_base = Base() arguments = sorted(self.request.arguments.iteritems(), key=lambda x: x[0]) result_string = ''.join([k+v[0] for k, v in arguments if k != 'sign']) appsecret = model_base.getAppSercet(appid) if not appsecret: raise ValueError(5) def default(*args): raise ValueError(3) def md5Method(result_string, appsecret): return hashlib.md5(appsecret + result_string + appsecret).hexdigest() switch = { 'md5': md5Method, } mysign = switch.get(self.get_argument('sign_method', None), default)(result_string, appsecret) logger.info("sign:%s" % mysign) if mysign != sign: raise ValueError(2) return func(*args, **kwargs)
def test_to_json_string_none(self): self.assertEqual(Base.to_json_string(None), '[]')
def test_id_increment(self): ob2 = Base() self.assertEqual(ob2.id, 2)
def test_1_3(self): ''' aaaaaaaaaaaaaa ''' b7 = Base() self.assertEqual(type(b7), Base) self.assertTrue(isinstance(b7, Base))
def test_dictionary(self): """Comment""" re1 = Rectangle(10, 7, 2, 8, 70) dictionary = re1.to_dictionary() json_dictionary = Base.to_json_string([dictionary]) self.assertEqual(type(json_dictionary), str)
def test_type(self): """ Test type and instance """ b = Base() self.assertEqual(type(b), Base) self.assertTrue(isinstance(b, Base))
def test_id_none(self): bo = Base() self.assertEqual(bo.id, 1) bo = Base(None) self.assertEqual(bo.id, 2)
def test00(self): """Test number 0 for base""" b_0 = Base() b_1 = Base() self.assertEqual(b_0.id, 1) self.assertEqual(b_1.id, 2)
def test02(self): """Test number 2 for base""" b_0 = Base(24) self.assertEqual(b_0.id, 24)
def __init__(self, **argvs): Base.__init__(self, **argvs)
def test10(self): """Test number 10 for base""" rect = Base.to_json_string(None) self.assertEqual(rect, "[]")
def test_to_json_none(self): """Checks the json represntation with None.""" input = None expected = "[]" self.assertEqual(Base.to_json_string(input), expected)
def test_to_json_empty(self): """Checks the json represntation with an empty list.""" input = [] expected = "[]" self.assertEqual(Base.to_json_string(input), expected)
def test_to_json(self): """Checks the json represntation.""" input = [{"x": 2, "width": 10, "id": 1, "height": 7, "y": 8}] expected = json.dumps(input) self.assertEqual(Base.to_json_string(input), expected)
import logging import logging.config import tornado.web import tornado.ioloop from models.base import Base import modules.user.routes application = tornado.web.Application( modules.user.routes.routes ) if __name__ == '__main__': # Configure Logging logging.config.fileConfig('logging.ini', disable_existing_loggers=False) logger = logging.getLogger(__name__) # Create database Base.instance().create_tables() logger.debug( "Starting application..." ) application.listen(8888) tornado.ioloop.IOLoop.instance().start()
def test03(self): """Test number 3 for base""" b_0 = Base("test") self.assertEqual(b_0.id, "test")
def __init__(self, *args, **kwargs): Base.__init__(self, *args, **kwargs) self.suppress_alert = 1 self.details = {} self.balance_plan = None
def test04(self): """Test number 4 for base""" b_0 = Base(-57) self.assertEqual(b_0.id, -57)
def test_id_negative(self): bo = Base(-4) self.assertEqual(bo.id, -4) bo = Base(-10) self.assertEqual(bo.id, -10)
def test05(self): """Test number 5 for base.""" b_0 = Base(None) self.assertEqual(b_0.id, 1)
def test_id_string(self): bo = Base("st") self.assertEqual(bo.id, "st") bo = Base("st2") self.assertEqual(bo.id, "st2")
def test06(self): """Test number 6 for base""" b_0 = Base({"test": "test"}) self.assertEqual(b_0.id, {"test": "test"})
def test_save_to_file(self): """Test class method save_to_file with normal types.""" with self.assertRaises(AttributeError) as e: Base.save_to_file([Base(1), Base(2)]) self.assertEqual("'Base' object has no attribute 'to_dictionary'", str(e.exception))
def test07(self): """Test number 7 for base""" b_0 = Base([1, 2, 3]) self.assertEqual(b_0.id, [1, 2, 3])
def tests_id(self): b = Base() self.assertEqual(1, b.id)
def test08(self): """Test number 8 for base""" b_0 = Base(27.8) self.assertEqual(b_0.id, 27.8)
def test_id(self): '''test that base id works in init method''' ob1 = Base() self.assertEqual(ob1.id, 1)
def test09(self): """Test number 9 for base""" b_0 = Base() self.assertEqual(str(type(b_0)), "<class 'models.base.Base'>") self.assertEqual(b_0.__dict__, {"id": 1})
def test_declare_id(self): ob89 = Base(89) self.assertEqual(ob89.id, 89)
def test_txt(self): """ Enter id = "txt" """ base_0 = Base("holbie") self.assertEqual(base_0.id, "holbie")
def test_to_json_string_empty(self): self.assertEqual(Base.to_json_string([]), '[]')
def test_to_json(self): """ to json string """ a = Base.to_json_string(None) self.assertEqual(a, "[]")
def empty(cls, num_preprocessing_features, num_features): return cls(Base.empty_vector(num_preprocessing_features), Base.empty_vector(num_features), Base.empty_label())
def test_id_positive(self): bo = Base(23) self.assertEqual(bo.id, 23) bo = Base(34) self.assertEqual(bo.id, 34)
def __init__(self, *args, **kwargs): Base.__init__(self, *args, **kwargs) self.suppress_alert = 1 self.details = {}
def empty(cls, num_features): return cls(Base.empty_vector(num_features), Base.empty_label())