LoginSignup
4
4

More than 5 years have passed since last update.

TestLink の REST API を触ってみた

Last updated at Posted at 2013-12-08

数日前に TestLink の XML-RPC についての記事を書かしてもらいましたが、
現状のTestLinkにあるREST もどんな状況なのかな?
というのが気になったので、触ってみました。

結論

結論から言うと、まだまだ業務に使用できるほどの機能は実装されていない
という感じです。

逆に、今のうちにゴリゴリ実装して、pull リクエストでも投げてみたら
取り込んでもらえる可能性大ってところでしょうか。

やったこと

REST API ソースチェック

REST API のソースは TestLinkディレクトリから lib/api/rest/v1 と辿った先にある
tlRestApi.class.php がそれです。

その中のコンストラクタの中に使える api の一覧があります。
私の環境では以下の通りでした。

Type API 内容 Api Key の指定
GET /who ltRestApi : Get Route /who の文字列を返す 必要なし
GET /whoAmI ltRestApi : Get Route /whoAmI の文字列を返す 必要
GET /testporjects テストプロジェクト情報の一覧を取得 必要
GET /testprojects/:id :id で指定したテストプロジェクト情報を取得 必要
POST /testprojects *未調査 ( テストプロジェクトを作成する ? ) * 必要
POST /executions *未調査 ( テスト結果を記録する ? ) * 必要
POST /testplans *未調査 ( テスト計画を作成する ? ) * 必要
POST /testplans/:id *未調査 ( テスト計画を編集する ? ) * 必要
POST /testsuites *未調査 ( テストスイートを作成する ? ) * 必要
POST /testcases *未調査 ( テストケースを作成する ? ) * 必要

Ruby で REST API にアクセス

以下のようなサンプルプログラムを作成しました

test.rb
require 'net/http'
require 'uri'
require 'pp'
require 'json'

class TestLinkRestBase
  class << self
    attr_accessor :site
    attr_accessor :prefix
    attr_accessor :collection_name
    attr_accessor :header

    def start
      url = URI.parse(site)
      api_url = "#{prefix}/#{collection_name}"
      p api_url
      Net::HTTP.start(url.host, url.port) { |http|
        http.get(api_url, header)
      }
    end
  end
end

class Who < TestLinkRestBase
  self.site = 'http://localhost/'
  self.prefix = '/testlink-1.9.9/lib/api/rest/v1/'
  self.collection_name = 'who'
end

class WhoAmI < TestLinkRestBase
  self.site = 'http://localhost/'
  self.prefix = '/testlink-1.9.9/lib/api/rest/v1/'
  self.collection_name = 'whoAmI'

  self.header = {
    "PHP-AUTH-USER" => "XXXXXXXXX" # ここはTestLinkで生成したAPIキーを指定
  }
end


puts "Get /who"
res = Who.start
pp res.body #=> "tlRestApi : Get Route /who"
# who の 結果はJSONでパースできない文字列で返ってきます

puts "Get /whoAmI"
res = WhoAmI.start
pp JSON.parse(res.body) #=> {"name" => "tlRestApi : Get Route /whoAmI"}
4
4
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4