0%

1
2
3
4
5
6
7
8
class Author(models.Model):
first_name = models.CharField(max_length=30)
last_name = models.CharField(max_length=40)
email - models.EmailField()

class Book(models.Model):
title = models.CharField(max_length=200)
authors = models.ManyToManyField(Author)

从Book角度查询Author:

1
2
3
book = Book.objects.get(id=1)
book.authors.all() # 查询id为1的Book的所有Author
book.authors.filter(first_name='jack') # 查询id为的Author中first_name为jack的Author

从Author角度查询Book:

1
2
author = Author.objects.get(id=1)
author.book_set.all() # 查询id为1的Author的所有Book

有时候需要测试一些需要登录的接口,或者测试一些需要特定权限才能调用的接口,而这些都需要登录, 在写测试用例的时候可以继承django.test.TestCase, 然后调用self.client.login(self, **credentials)self.client.force_login(self, user, backend=None)来进行登录。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'mydatabase',
'USER': 'mydatabaseuser',
'PASSWORD': 'mypassword',
'HOST': '127.0.0.1',
'PORT': '5432',
'TEST': {
'CHARSET': 'utf8',
'COLLATION': 'utf8_general_ci',
'NAME': 'test_mydatabase',
}
}
}

注意:

  1. 创建数据库:CREATE DATABASE mydatabase CHARACTER SET utf8;
  2. 安装mysql依赖:pip install pymysql
  3. 配置参数中CHARSETCOLLATION,若没有这两个参数的话,执行测试用例的时候会报编码错误。

1
alias curlw='curl -i -w "\n\n----------------\ntime_connect: %{time_connect}\ntime_starttransfer: %{time_starttransfer}\ntime_total: %{time_total}\n"'
  • time_namelookup: DNS解析域名的时间
  • time_connect: client和server端建立TCP连接的时间
  • time_starttransfer: 从client发出请求;到web得到server响应第一个字节的时间
  • time_total: client发出请求;到web得到server发送所有的相应数据的时间
  • speed_download: 下载速度,单位byte/s

DNSmasq是一个小巧且方便地用于配置DNS和DHCP的工具,适用于小型网络,它提供了DNS功能和可选择的DHCP功能。 它服务那些只在本地适用的域名,这些域名是不会在全球的DNS服务器中出现的。 DHCP服务器和DNS服务器结合,并且允许DHCP分配的地址能在DNS中正常解析, 而这些DHCP分配的地址和相关命令可以配置到每台主机中,也可以配置到一台核心设备中(比如路由器), DNSmasq支持静态和动态两种DHCP配置方式。

安装DNSmasq

安装

1
brew install dnsmasq

配置

拷贝默认配置文件

1
cp /usr/local/opt/dnsmasq/dnsmasq.conf.example /usr/local/etc/dnsmasq.conf

设置dnsmasq的DNS服务

打开文件/usr/local/etc/resolv.dnsmasq.conf,设置以下内容:

1
2
3
4
5
# google dns
nameserver 8.8.8.8
# open dns
nameserver 208.67.222.222
nameserver 208.67.220.220

打开文件/usr/local/etc/dnsmasq.conf,设置以下内容:

1
2
resolv-file=/usr/local/etc/resolv.dnsmasq.conf
address=/xxx.com/127.0.0.1

启动服务

1
2
sudo cp -fv /usr/local/opt/dnsmasq/*.plist /Library/LaunchDaemons
sudo launchctl load /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist

测试

1
dig @127.0.0.1 xxx.com

使用时需要将本机DNS改为127.0.0.1

重启DNSmasq

如果修改了配置文件,可以通过下面命令重启dnsmasq:

1
2
sudo launchctl stop homebrew.mxcl.dnsmasq
sudo launchctl start homebrew.mxcl.dnsmasq

使用线面命令清除dns缓存:

1
sudo killall -HUP mDNSResponder

1
2
3
4
5
6
git init
git remote add -f origin https://xxx/git/xxx.git
git config core.sparsecheckout true
echo "docs" >> .git/info/sparse-checkout
git pull origin master
git branch --set-upstream-to=origin/master master

执行以下命令安装:

1
apt-get update && apt-get install -y mysql-server mysql-client libmysqlclient-dev

注意:安装时候中间需要输入mysql数据库的密码,如果不想在安装过程中输入密码,可以在安装之前执行下面命令:

1
2
debconf-set-selections <<< 'mysql-server mysql-server/root_password password your_password'
debconf-set-selections <<< 'mysql-server mysql-server/root_password_again password your_password'

安装

1
npm install -g gitbook-cli

配置

修改文件book.json:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
{
"title": "$title$",
"author": "$author$",
"description": "$description$",
"repository": {
"type": "git",
"url": "$url$"
},
"plugins": [
"theme-opendocs", "advanced-emoji", "bg-nest",
"ace", "codeblock-label",
"simpletabs",
"include",
"katex",
"-highlight", "prism",
"-lunr", "-search", "search-pro",
"-sharing",
"-fontsettings"
],
"gitbook": ">=3.0.0",
"pluginsConfig": {}
}

在用户home目录下新建文件~/.pip/pip.conf

1
2
3
4
5
[global]
index-url=https://mirrors.aliyun.com/pypi/simple/

[install]
trusted-host=mirrors.aliyun.com

根据nvm进行安装,安装之后会在你的profile(~/.bash_profile, ~/.zshrc, ~/.profile, or ~/.bashrc)文件中添加以下两行:

1
2
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm

然后在后面添加一行:

1
2
NVM_NODEJS_ORG_MIRROR=https://npm.taobao.org/mirrors/node
NVM_IOJS_ORG_MIRROR=https://npm.taobao.org/mirrors/iojs