Skip to content

Commit

Permalink
Merge branch 'hotfix/disable-parent-area-count'
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-nick17 committed Jan 6, 2023
2 parents 3edf8bf + a18426b commit f19ed43
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 91 deletions.
2 changes: 1 addition & 1 deletion assets/templates/partials/census/variables-table.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
{{ if $dim.IsDefaultCoverage }}
{{- localise "AreaTypeDefaultCoverage" $language 1 -}}
{{ else }}
{{- $dim.Title }} ({{ thousandsSeparator $dim.TotalItems -}})
{{- $dim.Title }}
{{ end }}
</div>
{{else}}
Expand Down
58 changes: 30 additions & 28 deletions handlers/filter_output.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func FilterOutput(zc ZebedeeClient, fc FilterClient, pc PopulationClient, dc Dat
func filterOutput(w http.ResponseWriter, req *http.Request, zc ZebedeeClient, dc DatasetClient, fc FilterClient, pc PopulationClient, rend RenderClient, cfg config.Config, collectionID, lang, apiRouterVersion, userAccessToken string) {
const numOptsSummary = 1000
var initialVersion dataset.Version
var initialVersionReleaseDate, supVar string
var initialVersionReleaseDate string
var form = req.URL.Query().Get("f")
var format = req.URL.Query().Get("format")
var isValidationError bool
Expand Down Expand Up @@ -221,30 +221,31 @@ func filterOutput(w http.ResponseWriter, req *http.Request, zc ZebedeeClient, dc
return nil, 0, fmt.Errorf("failed to get dimension areas")
}

if dim.FilterByParent != "" {
count, err := pc.GetParentAreaCount(ctx, population.GetParentAreaCountInput{
AuthTokens: population.AuthTokens{
UserAuthToken: userAccessToken,
},
PopulationType: filterOutput.PopulationType,
AreaTypeID: dim.ID,
ParentAreaTypeID: dim.FilterByParent,
Areas: optsIDs,
SVarID: supVar,
})
if err != nil {
log.Error(ctx, "failed to get parent area count", err, log.Data{
"dataset_id": filterOutput.PopulationType,
"area_type_id": dim.ID,
"parent_area_type_id": dim.FilterByParent,
"areas": optsIDs,
"supplementary_variable_id": supVar,
})
return nil, 0, err
}

totalCount = count
}
// TODO: pc.GetParentAreaCount is causing production issues
// if dim.FilterByParent != "" {
// count, err := pc.GetParentAreaCount(ctx, population.GetParentAreaCountInput{
// AuthTokens: population.AuthTokens{
// UserAuthToken: userAccessToken,
// },
// PopulationType: filterOutput.PopulationType,
// AreaTypeID: dim.ID,
// ParentAreaTypeID: dim.FilterByParent,
// Areas: optsIDs,
// SVarID: supVar,
// })
// if err != nil {
// log.Error(ctx, "failed to get parent area count", err, log.Data{
// "dataset_id": filterOutput.PopulationType,
// "area_type_id": dim.ID,
// "parent_area_type_id": dim.FilterByParent,
// "areas": optsIDs,
// "supplementary_variable_id": supVar,
// })
// return nil, 0, err
// }

// totalCount = count
// }

return options, totalCount, nil
}
Expand All @@ -259,9 +260,10 @@ func filterOutput(w http.ResponseWriter, req *http.Request, zc ZebedeeClient, dc

var fDims []model.FilterDimension
for i := len(filterOutput.Dimensions) - 1; i >= 0; i-- {
if filterOutput.Dimensions[i].IsAreaType == nil || !*filterOutput.Dimensions[i].IsAreaType {
supVar = filterOutput.Dimensions[i].ID
}
// TODO: pc.GetParentAreaCount is causing production issues
// if filterOutput.Dimensions[i].IsAreaType == nil || !*filterOutput.Dimensions[i].IsAreaType {
// supVar = filterOutput.Dimensions[i].ID
// }
options, count, err := getOptions(filterOutput.Dimensions[i])
if err != nil {
log.Error(ctx, "failed to get options for dimension", err, log.Data{"dimension_name": filterOutput.Dimensions[i].Name})
Expand Down
125 changes: 63 additions & 62 deletions handlers/filter_output_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -635,10 +635,11 @@ func TestFilterOutputHandler(t *testing.T) {
EXPECT().
GetArea(gomock.Any(), gomock.Any()).
Return(population.GetAreaResponse{}, nil)
mockPc.
EXPECT().
GetParentAreaCount(gomock.Any(), gomock.Any()).
Return(0, nil)
// TODO: pc.GetParentAreaCount is causing production issues
// mockPc.
// EXPECT().
// GetParentAreaCount(gomock.Any(), gomock.Any()).
// Return(0, nil)

mockRend := NewMockRenderClient(mockCtrl)
mockRend.
Expand Down Expand Up @@ -893,69 +894,69 @@ func TestFilterOutputHandler(t *testing.T) {
// GetVersion(ctx, userAuthToken, serviceAuthToken, collectionID, "", "12345", "2021", "1").
// Return(versions.Items[0], nil)

Convey("and the additional call to pc.GetParentAreaCount fails", func() {
mockDc := NewMockDatasetClient(mockCtrl)
mockDc.
EXPECT().
Get(ctx, userAuthToken, serviceAuthToken, collectionID, "12345").
Return(dataset.DatasetDetails{
Contacts: &[]dataset.Contact{{Name: "Nick"}},
Type: "flexible",
URI: "/economy/grossdomesticproduct/datasets/gdpjanuary2018",
Links: dataset.Links{
LatestVersion: dataset.Link{
URL: "/datasets/12345/editions/2021/versions/1",
},
},
ID: "12345",
}, nil)
mockDc.
EXPECT().
GetVersions(ctx, userAuthToken, serviceAuthToken, collectionID, "", "12345", "2021", &dataset.QueryParams{Offset: 0, Limit: 1000}).
Return(versions, nil)
mockDc.
EXPECT().
GetVersion(ctx, userAuthToken, serviceAuthToken, collectionID, "", "12345", "2021", "1").
Return(versions.Items[0], nil)
// Convey("and the additional call to pc.GetParentAreaCount fails", func() {
// mockDc := NewMockDatasetClient(mockCtrl)
// mockDc.
// EXPECT().
// Get(ctx, userAuthToken, serviceAuthToken, collectionID, "12345").
// Return(dataset.DatasetDetails{
// Contacts: &[]dataset.Contact{{Name: "Nick"}},
// Type: "flexible",
// URI: "/economy/grossdomesticproduct/datasets/gdpjanuary2018",
// Links: dataset.Links{
// LatestVersion: dataset.Link{
// URL: "/datasets/12345/editions/2021/versions/1",
// },
// },
// ID: "12345",
// }, nil)
// mockDc.
// EXPECT().
// GetVersions(ctx, userAuthToken, serviceAuthToken, collectionID, "", "12345", "2021", &dataset.QueryParams{Offset: 0, Limit: 1000}).
// Return(versions, nil)
// mockDc.
// EXPECT().
// GetVersion(ctx, userAuthToken, serviceAuthToken, collectionID, "", "12345", "2021", "1").
// Return(versions.Items[0], nil)

mockFc := NewMockFilterClient(mockCtrl)
mockFc.
EXPECT().
GetOutput(ctx, gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).
Return(filterModels[3], nil)
mockFc.
EXPECT().
GetDimensionOptions(ctx, gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).
Return(filter.DimensionOptions{
Items: []filter.DimensionOption{
{
Option: "area 1",
},
},
TotalCount: 1,
}, "", nil)
// mockFc := NewMockFilterClient(mockCtrl)
// mockFc.
// EXPECT().
// GetOutput(ctx, gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).
// Return(filterModels[3], nil)
// mockFc.
// EXPECT().
// GetDimensionOptions(ctx, gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).
// Return(filter.DimensionOptions{
// Items: []filter.DimensionOption{
// {
// Option: "area 1",
// },
// },
// TotalCount: 1,
// }, "", nil)

mockPc := NewMockPopulationClient(mockCtrl)
mockPc.
EXPECT().
GetArea(gomock.Any(), gomock.Any()).
Return(population.GetAreaResponse{}, nil)
mockPc.
EXPECT().
GetParentAreaCount(gomock.Any(), gomock.Any()).
Return(0, errors.New("area parent count client error"))
// mockPc := NewMockPopulationClient(mockCtrl)
// mockPc.
// EXPECT().
// GetArea(gomock.Any(), gomock.Any()).
// Return(population.GetAreaResponse{}, nil)
// mockPc.
// EXPECT().
// GetParentAreaCount(gomock.Any(), gomock.Any()).
// Return(0, errors.New("area parent count client error"))

w := httptest.NewRecorder()
req := httptest.NewRequest("GET", "/datasets/12345/editions/2021/versions/1/filter-outputs/67890", nil)
// w := httptest.NewRecorder()
// req := httptest.NewRequest("GET", "/datasets/12345/editions/2021/versions/1/filter-outputs/67890", nil)

router := mux.NewRouter()
router.HandleFunc("/datasets/{datasetID}/editions/{editionID}/versions/{versionID}/filter-outputs/{filterOutputID}", FilterOutput(mockZebedeeClient, mockFc, mockPc, mockDc, NewMockRenderClient(mockCtrl), cfg, ""))
// router := mux.NewRouter()
// router.HandleFunc("/datasets/{datasetID}/editions/{editionID}/versions/{versionID}/filter-outputs/{filterOutputID}", FilterOutput(mockZebedeeClient, mockFc, mockPc, mockDc, NewMockRenderClient(mockCtrl), cfg, ""))

router.ServeHTTP(w, req)
Convey("Then the status code is 500", func() {
So(w.Code, ShouldEqual, http.StatusInternalServerError)
})
})
// router.ServeHTTP(w, req)
// Convey("Then the status code is 500", func() {
// So(w.Code, ShouldEqual, http.StatusInternalServerError)
// })
// })
})
})
}
Expand Down

0 comments on commit f19ed43

Please sign in to comment.