Skip to content

Commit

Permalink
Add cla
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Oct 23, 2015
1 parent 65f4541 commit 3f9d876
Show file tree
Hide file tree
Showing 7 changed files with 2,767 additions and 0 deletions.
6 changes: 6 additions & 0 deletions chapters/06-create-pull-request.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@

##Google Ngx Pagespeed

CLA: Contributor License Agreement

![Google CLA](./img/google-cla.png)

![Eclipse CLA](./img/eclipse-cla.png)

```
else
cat << END
Expand Down
Binary file modified github-roam.epub
Binary file not shown.
163 changes: 163 additions & 0 deletions github-roam.md
Original file line number Diff line number Diff line change
Expand Up @@ -1184,6 +1184,12 @@ C | 2
##Google Ngx Pagespeed
CLA: Contributor License Agreement
![Google CLA](./img/google-cla.png)
![Eclipse CLA](./img/eclipse-cla.png)
```
else
cat << END
Expand Down Expand Up @@ -1665,6 +1671,163 @@ req.end();
在这种理想的情况下,我们为什么不TDD呢?
##轻量级网站测试TWill
> twill was initially designed for testing Web sites, although since then people have also figured out that it's good for browsing unsuspecting Web sites.
之所以说轻量的原因是他是拿命令行测试的,还有DSL,还有Python。
除此之外,还可以拿它做压力测试,这种压力测试和一般的不一样。可以模拟整个过程,比如同时有多少人登陆你的网站。
不过,它有一个限制是没有JavaScript。
看了一下源码,大概原理就是用``requests``下载html,接着用``lxml``解析html,比较有意思的是内嵌了一个``DSL``。
这是一个Python的库。
pip install twill
##Twill 登陆测试
1.启动我们的应用。
2.进入twill shell
twill-sh
-= Welcome to twill! =-
current page: *empty page*
3.打开网页
>> go http://127.0.0.1:5000/login
==> at http://127.0.0.1:5000/login
current page: http://127.0.0.1:5000/login
4.显示表单
>> showforms
Form #1
## ## __Name__________________ __Type___ __ID________ __Value__________________
1 csrf_token hidden csrf_token 1423387196##5005bdf3496e09b8e2fbf450 ...
2 email email email None
3 password password password None
4 login submit (None) 登入
current page: http://127.0.0.1:5000/login
5.填充表单
formclear 1
fv 1 email [email protected]
fv 1 password test
6.修改action
formaction 1 http://127.0.0.1:5000/login
7.提交表单
>> submit
Note: submit is using submit button: name="login", value="登入"
current page: http://127.0.0.1:5000/
发现重定向到首页了。
##Twill 测试脚本
当然我们也可以用脚本直接来测试``login.twill``:
go http://127.0.0.1:5000/login
showforms
formclear 1
fv 1 email [email protected]
fv 1 password test
formaction 1 http://127.0.0.1:5000/login
submit
go http://127.0.0.1:5000/logout
运行
twill-sh login.twill
结果
>> EXECUTING FILE login.twill
AT LINE: login.twill:0
==> at http://127.0.0.1:5000/login
AT LINE: login.twill:2
Form #1
## ## __Name__________________ __Type___ __ID________ __Value__________________
1 csrf_token hidden csrf_token 1423387345##7a000b612fef39aceab5ca54 ...
2 email email email None
3 password password password None
4 login submit (None) 登入
AT LINE: login.twill:3
AT LINE: login.twill:4
AT LINE: login.twill:5
AT LINE: login.twill:6
Setting action for form (<Element form at 0x10e7cbb50>,) to ('http://127.0.0.1:5000/login',)
AT LINE: login.twill:7
Note: submit is using submit button: name="login", value="登入"
AT LINE: login.twill:9
==> at http://127.0.0.1:5000/login
--
1 of 1 files SUCCEEDED.
一个成功的测试诞生了。
##Fake Server
实践了一下怎么用sinon去fake server,还没用respondWith,于是写一下。
这里需要用到sinon框架来测试。
当我们fetch的时候,我们就可以返回我们想要fake的结果。
var data = {"id":1,"name":"Rice","type":"Good","price":12,"quantity":1,"description":"Made in China"};
beforeEach(function() {
this.server = sinon.fakeServer.create();
this.rices = new Rices();
this.server.respondWith(
"GET",
"http://localhost:8080/all/rice",
[
200,
{"Content-Type": "application/json"},
JSON.stringify(data)
]
);
});
于是在afterEach的时候,我们需要恢复这个server。
afterEach(function() {
this.server.restore();
});
接着写一个jasmine测试来测试
describe("Collection Test", function() {
it("should get data from the url", function() {
this.rices.fetch();
this.server.respond();
var result = JSON.parse(JSON.stringify(this.rices.models[0]));
expect(result["id"])
.toEqual(1);
expect(result["price"])
.toEqual(12);
expect(result)
.toEqual(data);
});
});
#重构
或许你应该知道了,重构是怎样的,你也知道重构能带来什么。在我刚开始学重构和设计模式的时候,我需要去找一些好的示例,以便于我更好的学习。有时候不得不创造一些更好的场景,来实现这些功能。
Expand Down
Loading

0 comments on commit 3f9d876

Please sign in to comment.