def setUp(self): while True: self.inexistent_path = get_random_str() if not os.path.exists(self.inexistent_path): break self.existing_path = get_random_str() os.mkdir(self.existing_path)
def setUp(self): while True: self.inexistent_path = get_random_str() if not os.path.exists(self.inexistent_path): break self.path_with_no_rst = get_random_str() if not os.path.exists(self.path_with_no_rst): os.mkdir(self.path_with_no_rst)
def setUp(self): while True: self.inexistent_path = get_random_str() if not os.path.exists(self.inexistent_path): break self.path_to_file = get_random_str() os.mkdir(self.path_to_file) self.filename = get_random_str() with open(os.path.join(self.path_to_file, self.filename), 'w') as f: f.write("Something that doesn't have the expected format")
def __get_nick_name(self, user_model, session): while True: nick_name = get_random_str(k=8, except_list=['0']) one_user = self.__check_nick_name(user_model, nick_name, session) if not one_user: break return nick_name
def test_generate_site_no_layout_in_metadata(self): file_without_layout = get_random_str() + '.rst' with open(os.path.join(self.input_path, file_without_layout), 'w') as f: f.write("""{"title": "Test"} --- something something""") generate.generate_site(self.input_path, self.output_path) self.assertFalse(os.path.exists(self.output_path))
def test_generate_site_wrong_template_name(self): file_wrong_template = get_random_str() + '.rst' with open(os.path.join(self.input_path, file_wrong_template), 'w') as f: f.write("""{"title": "Test", "layout": "wrong.html"} --- something something""") generate.generate_site(self.input_path, self.output_path) self.assertFalse(os.path.exists(self.output_path))
def send_general_code(cls, code, phone_list): try: business_id = str(get_random_str(24)) phone_nums = ",".join(phone_list) phone_param = {"code": code} template_code = "SMS_145596097" cls.__send_sms(business_id, phone_nums, template_code, phone_param) except Exception, e: logger.error("send sms error, msg(%s)" % e)
def send_activate_code(cls, code, phone_list): # TODO: 批量发送大量的,需要异步处理 try: business_id = str(get_random_str(24)) phone_param = {"code": str(code)} template_code = "SMS_143715662" index = 0 send_phone_list = phone_list[index:index + 1000] while len(send_phone_list) > 0: phone_nums = ",".join(send_phone_list) cls.__send_sms(business_id, phone_nums, template_code, phone_param) time.sleep(3) index += 1000 send_phone_list = phone_list[index:index + 1000] except Exception, e: logger.error("send sms error, msg(%s)" % e)
def setUp(self): self.input_path = get_random_str() self.output_path = get_random_str() os.mkdir(self.input_path)
# -*- coding: utf-8 -*- from utils import get_random_str, get_random_int, get_random_date STRING = get_random_str() NUMBER = get_random_int() DATE = get_random_date()
def test_write_output_correct_output(self): filename = get_random_str() content = get_random_str() generate.write_output(self.existing_path, filename, content) with open(os.path.join(self.existing_path, filename + '.html')) as f: self.assertEqual(f.read(), content)
def test_write_output_creates_file(self): filename = get_random_str() content = get_random_str() generate.write_output(self.existing_path, filename, content) self.assertTrue(path.isfile(os.path.join( self.existing_path, filename + '.html')))
def test_write_output_inexistent_dir(self): generate.write_output(self.inexistent_path, get_random_str(), get_random_str()) self.assertTrue(path.isdir(self.inexistent_path))
# -*- coding: utf-8 -*- from utils import get_random_str, get_random_int TEST_STRING = get_random_str(10) TEST_NUMBER = get_random_int()
def STRING(): return get_random_str(10)