导入sql
source 路径
反向从数据库将表模型导入django的model中
python manage.py inspectdb > school/models.py
报表
class Student(models.Model):
name = models.CharField(max_length=256, blank=True, null=True)
stu_no = models.CharField(max_length=16, blank=True, null=True)
# 在反向建表的过程中
lessons = models.ManyToManyField(Lesson, through='StudentLesson')
class Meta:
managed = False
db_table = 'student'
百度统计
- 创建索引
create index category_index on wanted(category)
测试
- 白盒测试
- 可以知道内部功能进行测试
- 黑盒测试
- 不知道内部功能,只知道调用方法
- 冒烟测试
- 只要找到问题,就可以打回去,让修改
- 单元测试
- python -m unittest 文件名
# 单元测试代码
import unittest
class TestClass01(unittest.TestCase):
# 方法名不能改变01表示测试中的排序
def test_case01(self):
my_str = "Carmack"
my_int = 999
# 断言my_str是字符串类型
self.assertTrue(my_str, str)
self.assertTrue(my_int,int)
def test_case02(self):
my_pi = 3.14
self.assertFalse(my_pi,int)
if __name__ == '__main__':
unittest.main()
import unittest
# 准备函数,先执行
def setUpMoule():
print("In setUpModule()...")
def tearDownModule():
print('In tearDownModule()...')
class TestClass02(unittest.TestCase):
# 类方法
@classmethod
def setUpClass(cls):
print('In setUpClass()...')
@classmethod
def tearDownClass(cls):
print('In tearDownClass()...')
def setUp(self):
print('\nIn setUp()...')
def tearDown(self):
print('In tearDown()...')
def test_case01(self):
self.assertTrue('PYTHON'.isupper())
print('In test_case01()')
if __name__ == '__main__':
unittest.main()
- 数据结构
- 数据和结构
- 链表 和 列表
- 链表 删除消耗少,查询慢
- 列表 删除消耗大,查询快
- 堆栈和队列
- 堆栈 先进后出
- 队列 先进先出
class Node:
def __init__(self, value):
self.value = value
self.next_node = None
def set_next_node(self, node):
self.next_node = node
node1 = Node('carmack')
noed2 = Node('Jon')
node3 = Node('Lisa')
node4 = Node('James')
node1.set_next_node(node2)
node2.set_next_node(node3)
node3.set_next_node(node4)
class LinkedList:
def __init__(self):
self.start_node = None
self.end_node = None
def append(self, node):
if not self.start_node:
self.start_node = node
self.end_node = node
else:
self.end_node.next_node = node
self.end_node = node
return self.end_node
class Sim_Stack(object):
def __init__(self, length=5):
self.stack = []
self.length = length
def add(self, item):
if len(self.stack) == self.length:
raise Exception
else:
self.stack.append(item)
return True
def pop(self):
del_item = self.stack.pop()
return del_item
def len(self):
s_length = len(self.stack)
return s_length
def is_empty(self):
if len(self.stack) == 0:
return True
else:
return False
def is_full(self):
if len(self.stack) == self.length:
return True
else:
return False
def index(self, num):
ret = self.stack[num]
return ret
def clear(self):
self.stack = []
def __str__(self):
return self.stack
import unittest
from test_stack import Sim_Stack
class TestClass01(unittest.TestCase):
@classmethod
def setUpClass(cls):
print('hheh')
cls.my_stack = Sim_Stack()
def testCase01(self):
my_num = 5
self.assertTrue(self.my_stack.add(my_num))
print('1')
def test_Case02(self):
# my_num = 6
# self.my_stack.add(my_num)
self.assertTrue(self.my_stack.pop(), 5)
print('2')
def test_Case03(self):
self.assertTrue(self.my_stack.is_empty())
def test_Case04(self):
self.my_stack.add(1)
self.my_stack.add(2)
self.assertEqual(self.my_stack.len(), 2)
def test_Case05(self):
self.my_stack.add(3)
self.assertFalse(self.my_stack.is_full())
self.my_stack.add(4)
self.my_stack.add(5)
self.assertTrue(self.my_stack.is_full())
def test_Case06(self):
self.assertEqual(self.my_stack.index(3), 4)
def test_Case07(self):
self.my_stack.clear()
self.assertEqual(self.my_stack.len(), 0)
if __name__ == '__main__':
unittest.main()
web测试
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import unittest
class NewVisitorTest(unittest.TestCase):
def setUp(self):
self.timeout = 40
self.browser = webdriver.Chrome()
self.browser.set_page_load_timeout(self.timeout)
self.wait = WebDriverWait(self.browser, self.timeout)
def tearDown(self):
self.browser.quit()
def test_can_start_a_list_and_retrieve_it_later(self):
self.browser.get('https://www.baidu.com')
self.assertIn('百度', self.browser.title)
login_link = self.wait.until(
EC.element_to_be_clickable((By.LINK_TEXT, '登录')))
login_link.click()
login_link_2 = self.wait.until(
EC.element_to_be_clickable((By.ID, 'TANGRAM__PSP_10__footerULoginBtn')))
login_link_2.click()
username_input = self.wait.until(
EC.presence_of_element_located((By.ID, 'TANGRAM__PSP_10__userName')))
username_input.clear()
username_input.send_keys('')
password_input = self.wait.until(
EC.presence_of_element_located((By.ID, 'TANGRAM__PSP_10__password')))
password_input.clear()
password_input.send_keys('')
login_submit_button = self.wait.until(
EC.element_to_be_clickable((By.ID, 'TANGRAM__PSP_10__submit')))
login_submit_button.click()
username_span = self.wait.until(
EC.presence_of_element_located((By.CSS_SELECTOR, '#s_username_top > span')))
self.assertEqual(username_span.text, 'PebbleApp')
# user_login_link = self.browser.find_element_by_id('TANGRAM__PSP_10__footerULoginBtn')
# user_login_link.click()
if __name__ == '__main__':
unittest.main(warnings='ignore')
压力测试(Stress Testing)
- loadrunner(收费)
- jmeter(开源)