Repository: deis/deis

Issue:
bug(client): deis apps only shows 100 apps
The client is not using the pagination to return all the apps



Discussion:
@Joshua-Anderson We should have the new Go client handle pagination of API endpoints as part of the rewrite in #3806.


Resolving patch:
diff --git a/controller/deis/settings.py b/controller/deis/settings.py
--- a/controller/deis/settings.py
+++ b/controller/deis/settings.py
@@ -199,6 +199,7 @@
         'rest_framework.renderers.JSONRenderer',
     ),
     'PAGINATE_BY': 100,
+    'PAGINATE_BY_PARAM': 'page_size',
     'TEST_REQUEST_DEFAULT_FORMAT': 'json',
 }
 


Test patch:
diff --git a/client-go/controller/client/client_test.go b/client-go/controller/client/client_test.go
--- a/client-go/controller/client/client_test.go
+++ b/client-go/controller/client/client_test.go
@@ -8,7 +8,7 @@ import (
 	"testing"
 )
 
-const sFile string = `{"username":"t","ssl_verify":false,"controller":"http://d.t","token":"a"}`
+const sFile string = `{"username":"t","ssl_verify":false,"controller":"http://d.t","token":"a","response_limit": 50}`
 
 func createTempProfile(contents string) error {
 	name, err := ioutil.TempDir("", "client")
@@ -62,9 +62,15 @@ func TestLoadSave(t *testing.T) {
 		t.Errorf("Expected %s, Got %s", expected, client.ControllerURL.String())
 	}
 
+	expectedI := 50
+	if client.ResponseLimit != expectedI {
+		t.Errorf("Expected %d, Got %d", expectedI, client.ResponseLimit)
+	}
+
 	client.SSLVerify = true
 	client.Token = "b"
 	client.Username = "c"
+	client.ResponseLimit = 0
 
 	u, err := url.Parse("http://deis.test")
 
@@ -99,6 +105,11 @@ func TestLoadSave(t *testing.T) {
 	if client.ControllerURL.String() != expected {
 		t.Errorf("Expected %s, Got %s", expected, client.ControllerURL.String())
 	}
+
+	expectedI = 100
+	if client.ResponseLimit != expectedI {
+		t.Errorf("Expected %d, Got %d", expectedI, client.ResponseLimit)
+	}
 }
 
 func TestDeleteSettings(t *testing.T) {
diff --git a/client-go/controller/client/http_test.go b/client-go/controller/client/http_test.go
--- a/client-go/controller/client/http_test.go
+++ b/client-go/controller/client/http_test.go
@@ -13,6 +13,22 @@ import (
 
 type fakeHTTPServer struct{}
 
+const limitedFixture string = `
+{
+    "count": 4,
+    "next": "http://replaced.com/limited2/",
+    "previous": null,
+    "results": [
+        {
+            "test": "foo"
+        },
+        {
+            "test": "bar"
+        }
+    ]
+}
+`
+
 func (fakeHTTPServer) ServeHTTP(res http.ResponseWriter, req *http.Request) {
 	res.Header().Add("DEIS_API_VERSION", version.APIVersion)
 
@@ -31,6 +47,11 @@ func (fakeHTTPServer) ServeHTTP(res http.ResponseWriter, req *http.Request) {
 		return
 	}
 
+	if req.URL.Path == "/limited/" && req.Method == "GET" && req.URL.RawQuery == "page_size=2" {
+		res.Write([]byte(limitedFixture))
+		return
+	}
+
 	if req.URL.Path == "/basic/" && req.Method == "POST" {
 		eT := "token abc"
 		if req.Header.Get("Authorization") != eT {
@@ -180,3 +201,38 @@ func TestCheckErrorsReturnsNil(t *testing.T) {
 		}
 	}
 }
+
+func TestLimitedRequest(t *testing.T) {
+	t.Parallel()
+
+	handler := fakeHTTPServer{}
+	server := httptest.NewServer(handler)
+	defer server.Close()
+
+	u, err := url.Parse(server.URL)
+
+	if err != nil {
+		t.Fatal(err)
+	}
+
+	httpClient := CreateHTTPClient(false)
+
+	client := Client{HTTPClient: httpClient, ControllerURL: *u, Token: "abc"}
+
+	expected := `[{"test":"foo"},{"test":"bar"}]`
+	expectedC := 4
+
+	actual, count, err := client.LimitedRequest("/limited/", 2)
+
+	if err != nil {
+		t.Fatal(err)
+	}
+
+	if count != expectedC {
+		t.Errorf("Expected %d, Got %d", expectedC, count)
+	}
+
+	if actual != expected {
+		t.Errorf("Expected %s, Got %s", expected, actual)
+	}
+}
diff --git a/client-go/controller/models/apps/apps_test.go b/client-go/controller/models/apps/apps_test.go
--- a/client-go/controller/models/apps/apps_test.go
+++ b/client-go/controller/models/apps/apps_test.go
@@ -291,7 +291,7 @@ func TestAppsList(t *testing.T) {
 
 	client := client.Client{HTTPClient: httpClient, ControllerURL: *u, Token: "abc"}
 
-	actual, err := List(&client)
+	actual, _, err := List(&client, 100)
 
 	if err != nil {
 		t.Fatal(err)
diff --git a/client-go/controller/models/builds/builds_test.go b/client-go/controller/models/builds/builds_test.go
--- a/client-go/controller/models/builds/builds_test.go
+++ b/client-go/controller/models/builds/builds_test.go
@@ -122,7 +122,7 @@ func TestBuildsList(t *testing.T) {
 
 	client := client.Client{HTTPClient: httpClient, ControllerURL: *u, Token: "abc"}
 
-	actual, err := List(&client, "example-go")
+	actual, _, err := List(&client, "example-go", 100)
 
 	if err != nil {
 		t.Fatal(err)
diff --git a/client-go/controller/models/certs/certs_test.go b/client-go/controller/models/certs/certs_test.go
--- a/client-go/controller/models/certs/certs_test.go
+++ b/client-go/controller/models/certs/certs_test.go
@@ -104,7 +104,7 @@ func TestCertsList(t *testing.T) {
 
 	client := client.Client{HTTPClient: httpClient, ControllerURL: *u, Token: "abc"}
 
-	actual, err := List(&client)
+	actual, _, err := List(&client, 100)
 
 	if err != nil {
 		t.Fatal(err)
diff --git a/client-go/controller/models/domains/domains_test.go b/client-go/controller/models/domains/domains_test.go
--- a/client-go/controller/models/domains/domains_test.go
+++ b/client-go/controller/models/domains/domains_test.go
@@ -110,7 +110,7 @@ func TestDomainsList(t *testing.T) {
 
 	client := client.Client{HTTPClient: httpClient, ControllerURL: *u, Token: "abc"}
 
-	actual, err := List(&client, "example-go")
+	actual, _, err := List(&client, "example-go", 100)
 
 	if err != nil {
 		t.Fatal(err)
diff --git a/client-go/controller/models/keys/keys_test.go b/client-go/controller/models/keys/keys_test.go
--- a/client-go/controller/models/keys/keys_test.go
+++ b/client-go/controller/models/keys/keys_test.go
@@ -113,7 +113,7 @@ func TestKeysList(t *testing.T) {
 
 	client := client.Client{HTTPClient: httpClient, ControllerURL: *u, Token: "abc"}
 
-	actual, err := List(&client)
+	actual, _, err := List(&client, 100)
 
 	if err != nil {
 		t.Fatal(err)
diff --git a/client-go/controller/models/perms/perms_test.go b/client-go/controller/models/perms/perms_test.go
--- a/client-go/controller/models/perms/perms_test.go
+++ b/client-go/controller/models/perms/perms_test.go
@@ -170,7 +170,7 @@ func TestListAdmins(t *testing.T) {
 
 	client := client.Client{HTTPClient: httpClient, ControllerURL: *u, Token: "abc"}
 
-	actual, err := ListAdmins(&client)
+	actual, _, err := ListAdmins(&client, 100)
 
 	if err != nil {
 		t.Fatal(err)
diff --git a/client-go/controller/models/ps/ps_test.go b/client-go/controller/models/ps/ps_test.go
--- a/client-go/controller/models/ps/ps_test.go
+++ b/client-go/controller/models/ps/ps_test.go
@@ -163,7 +163,7 @@ func TestProcessesList(t *testing.T) {
 
 	client := client.Client{HTTPClient: httpClient, ControllerURL: *u, Token: "abc"}
 
-	actual, err := List(&client, "example-go")
+	actual, _, err := List(&client, "example-go", 100)
 
 	if err != nil {
 		t.Fatal(err)
diff --git a/client-go/controller/models/releases/releases_test.go b/client-go/controller/models/releases/releases_test.go
--- a/client-go/controller/models/releases/releases_test.go
+++ b/client-go/controller/models/releases/releases_test.go
@@ -151,7 +151,7 @@ func TestReleasesList(t *testing.T) {
 
 	client := client.Client{HTTPClient: httpClient, ControllerURL: *u, Token: "abc"}
 
-	actual, err := List(&client, "example-go")
+	actual, _, err := List(&client, "example-go", 100)
 
 	if err != nil {
 		t.Fatal(err)
diff --git a/client-go/controller/models/users/users_test.go b/client-go/controller/models/users/users_test.go
--- a/client-go/controller/models/users/users_test.go
+++ b/client-go/controller/models/users/users_test.go
@@ -83,7 +83,7 @@ func TestUsersList(t *testing.T) {
 
 	client := client.Client{HTTPClient: httpClient, ControllerURL: *u, Token: "abc"}
 
-	actual, err := List(&client)
+	actual, _, err := List(&client, 100)
 
 	if err != nil {
 		t.Fatal(err)