 
   @opts Api.Router.init([])
 
-  test "show rights" do
-    assert show_rights("user-1", "pass-1") == ["a", "b", "c", "d"]
-    assert show_rights("user-2", "pass-2") == ["a", "b", "c"]
-    assert show_rights("user-3", "pass-3") == ["a", "b"]
+  setup context do
+    if login_info = context[:login] do
+      {name, pass} = login_info
+      [token: sign_in(name, pass)]
+    else
+      :ok
+    end
   end
 
+  test "show rights - anonymous" do
+    assert show_rights() == ["a"]
+  end
+  @tag login: {"user-1", "pass-1"}
+  test "show rights - user-1", context do
+    assert show_rights(context.token) == ["a", "b", "c", "d"]
+  end
+  @tag login: {"user-2", "pass-2"}
+  test "show rights - user-2", context do
+    assert show_rights(context.token) == ["a", "b", "c"]
+  end
+  @tag login: {"user-3", "pass-3"}
+  test "show rights - user-3", context do
+    assert show_rights(context.token) == ["a", "b"]
+  end
+  
   test "get document" do
     {conn, doc} = get_doc "doc-of-proj-a"
 

  end

  defp get_doc id do
    get_doc id, nil, nil
  end
  defp get_doc id, user, pass do
    conn = call_get "/documents/" <> id, user, pass
    { conn, Core.Utils.atomize(Poison.decode!(conn.resp_body)) }
  end
  defp get_docs do
    get_docs nil, nil
  end
  defp get_docs user, pass do
    call_get "/documents/", user, pass
  end
  defp get_geometries do
    get_geometries nil, nil
  end
  defp get_geometries user, pass do
    call_get "/documents/map", user, pass
  end

  defp show_rights user, pass do
    conn = call_get "/auth/show", user, pass
    Core.Utils.atomize(Poison.decode!(conn.resp_body)).rights.readable_projects
  end

  defp call_get path, user, pass do
    conn = conn(:get, path)
    conn = if user == nil do conn else put_req_header(conn, "authorization", sign_in(user, pass)) end
    Api.Router.call(conn, @opts)
  end
end
    assert List.first(result.documents).project == "a"
  end

  @tag login: {"user-1", "pass-1"}
  test "show geometries - all documents for user-1", context do
    conn = get_geometries context.token
    result = Core.Utils.atomize(Poison.decode!(conn.resp_body))
    
    assert length(result.documents) == 2
