   end
 
   test "delete action -- success" do
-    provider = %CloudProvider{id: 1, name: "aws", type: "aws", configuration: "{}"}
-    :meck.expect(Repo, :get, 2, provider)
-    :meck.expect(Repo, :delete, 1, provider)
+    provider = CloudProvider.new(%{name: "aws", type: "aws", configuration: "{}"}) |> Repo.insert
 
-    conn = call(Router, :delete, "/cloud_providers/1")
+    conn = call(Router, :delete, "/cloud_providers/#{provider.id}")
 
     assert conn.status == 204
   end
 
   test "delete action -- not found" do
-    :meck.expect(Repo, :get, 2, nil)
-
     conn = call(Router, :delete, "/cloud_providers/1")
 
     assert conn.status == 404
   end
 
   test "update action -- success" do
-    provider = %CloudProvider{id: 1, name: "aws", type: "aws", configuration: "{}"}
-    updated_provider = %CloudProvider{id: 1, name: "azure", type: "azure", configuration: "{some_config}"}
-    :meck.expect(Repo, :get, 2, provider)
+    provider = CloudProvider.new(%{name: "aws", type: "aws", configuration: "{}"}) |> Repo.insert
 
-    :meck.expect(Repo, :update, 1, updated_provider)
-
-    conn = call(Router, :put, "/cloud_providers/1", Poison.encode!(%{name: "azure", type: "azure", configuration: "{some_config}"}), [{"content-type", "application/json"}])
+    conn = call(Router, :put, "/cloud_providers/#{provider.id}", Poison.encode!(%{name: "azure", type: "azure", configuration: "{some_config}"}), [{"content-type", "application/json"}])
 
     assert conn.status == 204
 


    {_, location} = List.keyfind(conn.resp_headers, "location", 0)

    assert "/cloud_providers/1" == location
  end

  test "update action -- not found" do
    :meck.expect(Repo, :get, 2, nil)

    conn = call(Router, :put, "/cloud_providers/1", Poison.encode!(%{name: "azure", type: "azure", configuration: "{some_config}"}), [{"content-type", "application/json"}])

    assert conn.status == 404
  end

  test "update action -- fails on invalid change" do
    provider = %CloudProvider{id: 1, name: "aws", type: "aws", configuration: "{}"}
    :meck.expect(Repo, :get, 2, provider)

    conn = call(Router, :put, "/cloud_providers/1", Poison.encode!(%{name: "", type: "", configuration: ""}), [{"content-type", "application/json"}])

    assert conn.status == 400


    body = Poison.decode!(conn.resp_body)

    assert length(body) == 0
  end

  test "clusters action -- provider does not exist" do
    provider = CloudProvider.new(%{name: "a", type: "a", configuration: "{}"}) |> Repo.insert
    _cluster1 = EtcdCluster.new(%{etcd_token: "abc125", hosting_provider_id: provider.id}) |> Repo.insert
    _cluster2 = EtcdCluster.new(%{etcd_token: "abc126", hosting_provider_id: provider.id}) |> Repo.insert
