SlideShare a Scribd company logo
1 of 42
Download to read offline
$ python tests/api_books_test.py
* GET /api/2/books
- [pass] returns list of books.
- [Fail] accepts 'size' parameter.
---------------------------------------------
[Fail] API_Test > GET /api/2/books

> 002: accepts 'size' parameter.
File "tests/api_books_test.py", line 268
ok (len(items)) == 20
AssertionError: 33 == 20 : failed.
---------------------------------------------
class BooksAPI_Test(TestCase):
with subject("/api/v1/books"):
@test("accepts 'size' parameter.")
def _(self, api):
qs = "size=20"
resp = api.GET('/api/v1/books?'+qs)
books = resp.json['books']
ok (len(books)) == 20
$ ls app/**/*.py | wc -l
123
$ ls app/api/**.py | wc -l
23
$ ls app/models/**.py | wc -l
45
$ ls app/usecases/**.py | wc -l
55
GET /api/v1/books
class BooksAPI
def do_list()
class BooksService
def find_books()
class BookService(Service):
def find_books(self, **kwargs):
q = db.query(Book)
order = kwargs.pop('order')
if order: q = q.order_by(order)
limit = kwargs.pop('limit')
if limit: q = q.limit(limit)
if kwargs: q = q.filter_by(**kwargs)
return q.all()
class BookService(Service):
def find_books(self, **kwargs):
q = db.query(Book)
order = kwargs.pop('order')
if order: q = q.order_by(order)
#; [!mf7cw] accepts 'size' parameter.
limit = kwargs.pop('limit')
if limit: q = q.limit(limit)
if kwargs: q = q.filter_by(**kwargs)
return q.all()
class BooksAPI_Test(TestCase):
with subject("/api/v1/books"):
@test("[!mf7cw] accepts 'size' parameter.")
def _(self, api):
qs = "size=20"
resp = api.GET('/api/v1/books?'+qs)
books = resp.json['books']
ok (len(books)) == 20
$ python tests/api_books_test.py
* GET /api/2/books
- [pass] returns list of books.
- [Fail] accepts 'size' parameter.
---------------------------------------------
[Fail] API_Test > GET /api/2/books

> 002: [!mf7cw] accepts 'size' parameter.
File "tests/api_books_test.py", line 268
ok (len(items)) == 20
AssertionError: 33 == 20 : failed.
---------------------------------------------
## -n: -r:
$ grep -nr mf7cw app
app/services/book_service.py:199: #; [!mf7cw]
accepts 'size' parameter.
## file: app/services/book_service.py
194: class BookService(Service):
195: def find_books(self, **kwargs):
196: q = db.query(Book)
197: order = kwargs.pop('order')
198: if order: q = q.order_by(order)
199: #; [!mf7cw] accepts 'size' parameter.
200: limit = kwargs.pop('limit')
201: if limit: q = q.limit(limit)
202: if kwargs: q = q.filter_by(**kwargs)
203: return q.all()
$ less /var/log/postgresql/pg9.3-main.log
2016-12-01 12:34:56 JST [46212]
LOG: duration: 2671.751 ms
statement:
select * from books
where title like '%SQL%'
order by title
limit 100
.....
$ ls app/**/*.py | wc -l
123
$ ls app/api/**.py | wc -l
23
$ ls app/models/**.py | wc -l
45
$ ls app/usecases/**.py | wc -l
55
sql = """
/* [sql:dolxq] */
select *
from books
where title like :pattern
order by title
limit :limit
"""
vars = {"title": "%SQL%", limit: 10}
result = db.execute(sql, vars)
2016-12-01 12:34:56 JST [46212]
LOG: duration: 2671.751 ms
statement:
/* [sql:dolxq] */
select * from books
where title like '%SQL%'
order by title
limit 100
## grep ag (SilverSearcher)
$ ag dolxq app
app/services/book_service.py
79: /* [sql:dolxq] */
## file: app/services/book_service.py
78: sql = """
79: /* [sql:dolxq] */
80: select *
81: from books
82: where title like :pattern
83: order by title
84: limit :limit
85: """
86: vars = {"title": "%SQL%", limit: 10}
87: result = db.execute(sql, vars)
<p>
<form>
Name: <input name="name">
Comment: <input name="comment">
<input type="submit">
</form>
</p>
$ ls app/**/*.html* | wc -l
302
$ ls app/**/*.py | wc -l
123
<!-- [!v5ozp] -->
<p>
<form>
Name: <input name="name">
Comment: <input name="comment">
<input type="submit">
</form>
</p>
<p data-eid="!v5ozp">
<form>
Name: <input name="name">
Comment: <input name="comment">
<input type="submit">
</form>
</p>
<!-- [!v5ozp] -->
<p>
<form>
Name: <input name="name">
Comment: <input name="comment">
<input type="submit">
</form>
</p>
## rak (ruby) ack (perl)
$ rak v5ozp app
app/templates/example_form.html.tjn

25| <!-- [!v5ozp] -->
## file: example_form.html.tjn
24:
25: <!-- [!v5ozp] -->
26: <p>
27: <form>
28: Name: <input name="name">
29: Comment: <input name="comment">
30: <input type="submit">
31: </form>
32: </p>
function render() {
return (
<div data-eid="!1tscw">
<h3>TODO</h3>
<TodoList items={this.state.items} />
<form onSubmit={this.handleSubmit}>
<input value={this.state.text} />
<button>Add</button>
</form>
</div>
);
}









More Related Content

What's hot

openstack源码分析(1)
openstack源码分析(1)openstack源码分析(1)
openstack源码分析(1)
cannium
 
Book integrated assignment
Book integrated assignmentBook integrated assignment
Book integrated assignment
Akash gupta
 
PerlApp2Postgresql (2)
PerlApp2Postgresql (2)PerlApp2Postgresql (2)
PerlApp2Postgresql (2)
Jerome Eteve
 
Monitoring with Syslog and EventMachine (RailswayConf 2012)
Monitoring  with  Syslog and EventMachine (RailswayConf 2012)Monitoring  with  Syslog and EventMachine (RailswayConf 2012)
Monitoring with Syslog and EventMachine (RailswayConf 2012)
Wooga
 
Qtp Training Deepti 4 Of 4493
Qtp Training Deepti 4 Of 4493Qtp Training Deepti 4 Of 4493
Qtp Training Deepti 4 Of 4493
Azhar Satti
 

What's hot (20)

openstack源码分析(1)
openstack源码分析(1)openstack源码分析(1)
openstack源码分析(1)
 
Apache Spark in your likeness - low and high level customization
Apache Spark in your likeness - low and high level customizationApache Spark in your likeness - low and high level customization
Apache Spark in your likeness - low and high level customization
 
Python queue solution with asyncio and kafka
Python queue solution with asyncio and kafkaPython queue solution with asyncio and kafka
Python queue solution with asyncio and kafka
 
Book integrated assignment
Book integrated assignmentBook integrated assignment
Book integrated assignment
 
Building Distributed System with Celery on Docker Swarm
Building Distributed System with Celery on Docker SwarmBuilding Distributed System with Celery on Docker Swarm
Building Distributed System with Celery on Docker Swarm
 
App-o-Lockalypse now!
App-o-Lockalypse now!App-o-Lockalypse now!
App-o-Lockalypse now!
 
Read, store and create xml and json
Read, store and create xml and jsonRead, store and create xml and json
Read, store and create xml and json
 
Ethiopian multiplication in Perl6
Ethiopian multiplication in Perl6Ethiopian multiplication in Perl6
Ethiopian multiplication in Perl6
 
Using Logstash, elasticsearch & kibana
Using Logstash, elasticsearch & kibanaUsing Logstash, elasticsearch & kibana
Using Logstash, elasticsearch & kibana
 
An Introduction To PostgreSQL Triggers
An Introduction To PostgreSQL TriggersAn Introduction To PostgreSQL Triggers
An Introduction To PostgreSQL Triggers
 
Using ngx_lua in UPYUN
Using ngx_lua in UPYUNUsing ngx_lua in UPYUN
Using ngx_lua in UPYUN
 
PerlApp2Postgresql (2)
PerlApp2Postgresql (2)PerlApp2Postgresql (2)
PerlApp2Postgresql (2)
 
Angular&node js upload file
Angular&node js upload fileAngular&node js upload file
Angular&node js upload file
 
Common Performance Pitfalls in Odoo apps
Common Performance Pitfalls in Odoo appsCommon Performance Pitfalls in Odoo apps
Common Performance Pitfalls in Odoo apps
 
Bootstrap
BootstrapBootstrap
Bootstrap
 
Monitoring with Syslog and EventMachine (RailswayConf 2012)
Monitoring  with  Syslog and EventMachine (RailswayConf 2012)Monitoring  with  Syslog and EventMachine (RailswayConf 2012)
Monitoring with Syslog and EventMachine (RailswayConf 2012)
 
Postgre sql unleashed
Postgre sql unleashedPostgre sql unleashed
Postgre sql unleashed
 
Apache Spark Structured Streaming + Apache Kafka = ♡
Apache Spark Structured Streaming + Apache Kafka = ♡Apache Spark Structured Streaming + Apache Kafka = ♡
Apache Spark Structured Streaming + Apache Kafka = ♡
 
More than syntax
More than syntaxMore than syntax
More than syntax
 
Qtp Training Deepti 4 Of 4493
Qtp Training Deepti 4 Of 4493Qtp Training Deepti 4 Of 4493
Qtp Training Deepti 4 Of 4493
 

Similar to なんでもID

Large Scale Log Analytics with Solr: Presented by Rafał Kuć & Radu Gheorghe, ...
Large Scale Log Analytics with Solr: Presented by Rafał Kuć & Radu Gheorghe, ...Large Scale Log Analytics with Solr: Presented by Rafał Kuć & Radu Gheorghe, ...
Large Scale Log Analytics with Solr: Presented by Rafał Kuć & Radu Gheorghe, ...
Lucidworks
 
Curscatalyst
CurscatalystCurscatalyst
Curscatalyst
Kar Juan
 
Perl web frameworks
Perl web frameworksPerl web frameworks
Perl web frameworks
diego_k
 
Oracle 10g Performance: chapter 00 sampling
Oracle 10g Performance: chapter 00 samplingOracle 10g Performance: chapter 00 sampling
Oracle 10g Performance: chapter 00 sampling
Kyle Hailey
 

Similar to なんでもID (20)

Large Scale Log Analytics with Solr: Presented by Rafał Kuć & Radu Gheorghe, ...
Large Scale Log Analytics with Solr: Presented by Rafał Kuć & Radu Gheorghe, ...Large Scale Log Analytics with Solr: Presented by Rafał Kuć & Radu Gheorghe, ...
Large Scale Log Analytics with Solr: Presented by Rafał Kuć & Radu Gheorghe, ...
 
New Tuning Features in Oracle 11g - How to make your database as boring as po...
New Tuning Features in Oracle 11g - How to make your database as boring as po...New Tuning Features in Oracle 11g - How to make your database as boring as po...
New Tuning Features in Oracle 11g - How to make your database as boring as po...
 
Advanced pg_stat_statements: Filtering, Regression Testing & more
Advanced pg_stat_statements: Filtering, Regression Testing & moreAdvanced pg_stat_statements: Filtering, Regression Testing & more
Advanced pg_stat_statements: Filtering, Regression Testing & more
 
Scala active record
Scala active recordScala active record
Scala active record
 
Spark Sql for Training
Spark Sql for TrainingSpark Sql for Training
Spark Sql for Training
 
Introduce to Spark sql 1.3.0
Introduce to Spark sql 1.3.0 Introduce to Spark sql 1.3.0
Introduce to Spark sql 1.3.0
 
03 2017Emea_RoadshowMilan-WhatsNew-Mariadbserver10_2andmaxscale 2_1
03 2017Emea_RoadshowMilan-WhatsNew-Mariadbserver10_2andmaxscale 2_103 2017Emea_RoadshowMilan-WhatsNew-Mariadbserver10_2andmaxscale 2_1
03 2017Emea_RoadshowMilan-WhatsNew-Mariadbserver10_2andmaxscale 2_1
 
Datagrids with Symfony 2, Backbone and Backgrid
Datagrids with Symfony 2, Backbone and BackgridDatagrids with Symfony 2, Backbone and Backgrid
Datagrids with Symfony 2, Backbone and Backgrid
 
Datagrids with Symfony 2, Backbone and Backgrid
Datagrids with Symfony 2, Backbone and BackgridDatagrids with Symfony 2, Backbone and Backgrid
Datagrids with Symfony 2, Backbone and Backgrid
 
Makezine
MakezineMakezine
Makezine
 
Hadoop on aws amazon
Hadoop on aws amazonHadoop on aws amazon
Hadoop on aws amazon
 
Hadoop on aws amazon
Hadoop on aws amazonHadoop on aws amazon
Hadoop on aws amazon
 
G*ワークショップ in 仙台 Grails(とことん)入門
G*ワークショップ in 仙台 Grails(とことん)入門G*ワークショップ in 仙台 Grails(とことん)入門
G*ワークショップ in 仙台 Grails(とことん)入門
 
Analytics Metrics delivery and ML Feature visualization: Evolution of Data Pl...
Analytics Metrics delivery and ML Feature visualization: Evolution of Data Pl...Analytics Metrics delivery and ML Feature visualization: Evolution of Data Pl...
Analytics Metrics delivery and ML Feature visualization: Evolution of Data Pl...
 
Curscatalyst
CurscatalystCurscatalyst
Curscatalyst
 
Perl web frameworks
Perl web frameworksPerl web frameworks
Perl web frameworks
 
Oracle 10g Performance: chapter 00 sampling
Oracle 10g Performance: chapter 00 samplingOracle 10g Performance: chapter 00 sampling
Oracle 10g Performance: chapter 00 sampling
 
Best Practices in Handling Performance Issues
Best Practices in Handling Performance IssuesBest Practices in Handling Performance Issues
Best Practices in Handling Performance Issues
 
Rails3 way
Rails3 wayRails3 way
Rails3 way
 
Relational Database Access with Python ‘sans’ ORM
Relational Database Access with Python ‘sans’ ORM  Relational Database Access with Python ‘sans’ ORM
Relational Database Access with Python ‘sans’ ORM
 

More from kwatch

文字列結合のベンチマークをいろんな処理系でやってみた
文字列結合のベンチマークをいろんな処理系でやってみた文字列結合のベンチマークをいろんな処理系でやってみた
文字列結合のベンチマークをいろんな処理系でやってみた
kwatch
 
I have something to say about the buzz word "From Java to Ruby"
I have something to say about the buzz word "From Java to Ruby"I have something to say about the buzz word "From Java to Ruby"
I have something to say about the buzz word "From Java to Ruby"
kwatch
 

More from kwatch (20)

How to make the fastest Router in Python
How to make the fastest Router in PythonHow to make the fastest Router in Python
How to make the fastest Router in Python
 
Migr8.rb チュートリアル
Migr8.rb チュートリアルMigr8.rb チュートリアル
Migr8.rb チュートリアル
 
Nippondanji氏に怒られても仕方ない、配列型とJSON型の使い方
Nippondanji氏に怒られても仕方ない、配列型とJSON型の使い方Nippondanji氏に怒られても仕方ない、配列型とJSON型の使い方
Nippondanji氏に怒られても仕方ない、配列型とJSON型の使い方
 
【SQLインジェクション対策】徳丸先生に怒られない、動的SQLの安全な組み立て方
【SQLインジェクション対策】徳丸先生に怒られない、動的SQLの安全な組み立て方【SQLインジェクション対策】徳丸先生に怒られない、動的SQLの安全な組み立て方
【SQLインジェクション対策】徳丸先生に怒られない、動的SQLの安全な組み立て方
 
O/Rマッパーによるトラブルを未然に防ぐ
O/Rマッパーによるトラブルを未然に防ぐO/Rマッパーによるトラブルを未然に防ぐ
O/Rマッパーによるトラブルを未然に防ぐ
 
正規表現リテラルは本当に必要なのか?
正規表現リテラルは本当に必要なのか?正規表現リテラルは本当に必要なのか?
正規表現リテラルは本当に必要なのか?
 
【公開終了】Python4PHPer - PHPユーザのためのPython入門 (Python2.5)
【公開終了】Python4PHPer - PHPユーザのためのPython入門 (Python2.5)【公開終了】Python4PHPer - PHPユーザのためのPython入門 (Python2.5)
【公開終了】Python4PHPer - PHPユーザのためのPython入門 (Python2.5)
 
DBスキーマもバージョン管理したい!
DBスキーマもバージョン管理したい!DBスキーマもバージョン管理したい!
DBスキーマもバージョン管理したい!
 
PHPとJavaScriptにおけるオブジェクト指向を比較する
PHPとJavaScriptにおけるオブジェクト指向を比較するPHPとJavaScriptにおけるオブジェクト指向を比較する
PHPとJavaScriptにおけるオブジェクト指向を比較する
 
SQL上級者こそ知って欲しい、なぜO/Rマッパーが重要か?
SQL上級者こそ知って欲しい、なぜO/Rマッパーが重要か?SQL上級者こそ知って欲しい、なぜO/Rマッパーが重要か?
SQL上級者こそ知って欲しい、なぜO/Rマッパーが重要か?
 
Fantastic DSL in Python
Fantastic DSL in PythonFantastic DSL in Python
Fantastic DSL in Python
 
What is wrong on Test::More? / Test::Moreが抱える問題点とその解決策
What is wrong on Test::More? / Test::Moreが抱える問題点とその解決策What is wrong on Test::More? / Test::Moreが抱える問題点とその解決策
What is wrong on Test::More? / Test::Moreが抱える問題点とその解決策
 
PHP5.5新機能「ジェネレータ」初心者入門
PHP5.5新機能「ジェネレータ」初心者入門PHP5.5新機能「ジェネレータ」初心者入門
PHP5.5新機能「ジェネレータ」初心者入門
 
Pretty Good Branch Strategy for Git/Mercurial
Pretty Good Branch Strategy for Git/MercurialPretty Good Branch Strategy for Git/Mercurial
Pretty Good Branch Strategy for Git/Mercurial
 
Oktest - a new style testing library for Python -
Oktest - a new style testing library for Python -Oktest - a new style testing library for Python -
Oktest - a new style testing library for Python -
 
文字列結合のベンチマークをいろんな処理系でやってみた
文字列結合のベンチマークをいろんな処理系でやってみた文字列結合のベンチマークをいろんな処理系でやってみた
文字列結合のベンチマークをいろんな処理系でやってみた
 
I have something to say about the buzz word "From Java to Ruby"
I have something to say about the buzz word "From Java to Ruby"I have something to say about the buzz word "From Java to Ruby"
I have something to say about the buzz word "From Java to Ruby"
 
Cより速いRubyプログラム
Cより速いRubyプログラムCより速いRubyプログラム
Cより速いRubyプログラム
 
Javaより速いLL用テンプレートエンジン
Javaより速いLL用テンプレートエンジンJavaより速いLL用テンプレートエンジン
Javaより速いLL用テンプレートエンジン
 
Underlaying Technology of Modern O/R Mapper
Underlaying Technology of Modern O/R MapperUnderlaying Technology of Modern O/R Mapper
Underlaying Technology of Modern O/R Mapper
 

Recently uploaded

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Recently uploaded (20)

ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 

なんでもID

  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6. $ python tests/api_books_test.py * GET /api/2/books - [pass] returns list of books. - [Fail] accepts 'size' parameter. --------------------------------------------- [Fail] API_Test > GET /api/2/books
 > 002: accepts 'size' parameter. File "tests/api_books_test.py", line 268 ok (len(items)) == 20 AssertionError: 33 == 20 : failed. ---------------------------------------------
  • 7. class BooksAPI_Test(TestCase): with subject("/api/v1/books"): @test("accepts 'size' parameter.") def _(self, api): qs = "size=20" resp = api.GET('/api/v1/books?'+qs) books = resp.json['books'] ok (len(books)) == 20
  • 8. $ ls app/**/*.py | wc -l 123 $ ls app/api/**.py | wc -l 23 $ ls app/models/**.py | wc -l 45 $ ls app/usecases/**.py | wc -l 55
  • 9. GET /api/v1/books class BooksAPI def do_list() class BooksService def find_books()
  • 10. class BookService(Service): def find_books(self, **kwargs): q = db.query(Book) order = kwargs.pop('order') if order: q = q.order_by(order) limit = kwargs.pop('limit') if limit: q = q.limit(limit) if kwargs: q = q.filter_by(**kwargs) return q.all()
  • 11.
  • 12. class BookService(Service): def find_books(self, **kwargs): q = db.query(Book) order = kwargs.pop('order') if order: q = q.order_by(order) #; [!mf7cw] accepts 'size' parameter. limit = kwargs.pop('limit') if limit: q = q.limit(limit) if kwargs: q = q.filter_by(**kwargs) return q.all()
  • 13. class BooksAPI_Test(TestCase): with subject("/api/v1/books"): @test("[!mf7cw] accepts 'size' parameter.") def _(self, api): qs = "size=20" resp = api.GET('/api/v1/books?'+qs) books = resp.json['books'] ok (len(books)) == 20
  • 14. $ python tests/api_books_test.py * GET /api/2/books - [pass] returns list of books. - [Fail] accepts 'size' parameter. --------------------------------------------- [Fail] API_Test > GET /api/2/books
 > 002: [!mf7cw] accepts 'size' parameter. File "tests/api_books_test.py", line 268 ok (len(items)) == 20 AssertionError: 33 == 20 : failed. ---------------------------------------------
  • 15. ## -n: -r: $ grep -nr mf7cw app app/services/book_service.py:199: #; [!mf7cw] accepts 'size' parameter.
  • 16. ## file: app/services/book_service.py 194: class BookService(Service): 195: def find_books(self, **kwargs): 196: q = db.query(Book) 197: order = kwargs.pop('order') 198: if order: q = q.order_by(order) 199: #; [!mf7cw] accepts 'size' parameter. 200: limit = kwargs.pop('limit') 201: if limit: q = q.limit(limit) 202: if kwargs: q = q.filter_by(**kwargs) 203: return q.all()
  • 17.
  • 18.
  • 19.
  • 20. $ less /var/log/postgresql/pg9.3-main.log 2016-12-01 12:34:56 JST [46212] LOG: duration: 2671.751 ms statement: select * from books where title like '%SQL%' order by title limit 100 .....
  • 21. $ ls app/**/*.py | wc -l 123 $ ls app/api/**.py | wc -l 23 $ ls app/models/**.py | wc -l 45 $ ls app/usecases/**.py | wc -l 55
  • 22.
  • 23. sql = """ /* [sql:dolxq] */ select * from books where title like :pattern order by title limit :limit """ vars = {"title": "%SQL%", limit: 10} result = db.execute(sql, vars)
  • 24. 2016-12-01 12:34:56 JST [46212] LOG: duration: 2671.751 ms statement: /* [sql:dolxq] */ select * from books where title like '%SQL%' order by title limit 100
  • 25. ## grep ag (SilverSearcher) $ ag dolxq app app/services/book_service.py 79: /* [sql:dolxq] */
  • 26. ## file: app/services/book_service.py 78: sql = """ 79: /* [sql:dolxq] */ 80: select * 81: from books 82: where title like :pattern 83: order by title 84: limit :limit 85: """ 86: vars = {"title": "%SQL%", limit: 10} 87: result = db.execute(sql, vars)
  • 27.
  • 28.
  • 29.
  • 30. <p> <form> Name: <input name="name"> Comment: <input name="comment"> <input type="submit"> </form> </p>
  • 31. $ ls app/**/*.html* | wc -l 302 $ ls app/**/*.py | wc -l 123
  • 32.
  • 33. <!-- [!v5ozp] --> <p> <form> Name: <input name="name"> Comment: <input name="comment"> <input type="submit"> </form> </p>
  • 34. <p data-eid="!v5ozp"> <form> Name: <input name="name"> Comment: <input name="comment"> <input type="submit"> </form> </p>
  • 35. <!-- [!v5ozp] --> <p> <form> Name: <input name="name"> Comment: <input name="comment"> <input type="submit"> </form> </p>
  • 36. ## rak (ruby) ack (perl) $ rak v5ozp app app/templates/example_form.html.tjn
 25| <!-- [!v5ozp] -->
  • 37. ## file: example_form.html.tjn 24: 25: <!-- [!v5ozp] --> 26: <p> 27: <form> 28: Name: <input name="name"> 29: Comment: <input name="comment"> 30: <input type="submit"> 31: </form> 32: </p>
  • 38.
  • 39. function render() { return ( <div data-eid="!1tscw"> <h3>TODO</h3> <TodoList items={this.state.items} /> <form onSubmit={this.handleSubmit}> <input value={this.state.text} /> <button>Add</button> </form> </div> ); }
  • 40.
  • 42.