Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update required params for TheMediaGrid adapter #1188

Merged
merged 19 commits into from
Mar 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 43 additions & 1 deletion adapters/grid/grid.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,53 @@ type GridAdapter struct {
endpoint string
}

func processImp(imp *openrtb.Imp) error {
// get the grid extension
var ext adapters.ExtImpBidder
var gridExt openrtb_ext.ExtImpGrid
if err := json.Unmarshal(imp.Ext, &ext); err != nil {
return err
}
if err := json.Unmarshal(ext.Bidder, &gridExt); err != nil {
return err
}

if gridExt.Uid == 0 {
err := &errortypes.BadInput{
Message: "uid is empty",
}
return err
}
// no error
return nil
}

// MakeRequests makes the HTTP requests which should be made to fetch bids.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a couple more tests in supplemental to cover the if statements shown in red below?
image

func (a *GridAdapter) MakeRequests(request *openrtb.BidRequest, reqInfo *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) {
var errors = make([]error, 0)

reqJSON, err := json.Marshal(request)
// copy the request, because we are going to mutate it
requestCopy := *request
// this will contain all the valid impressions
var validImps []openrtb.Imp
// pre-process the imps
for _, imp := range requestCopy.Imp {
if err := processImp(&imp); err == nil {
validImps = append(validImps, imp)
} else {
errors = append(errors, err)
}
}
if len(validImps) == 0 {
err := &errortypes.BadInput{
Message: "No valid impressions for grid",
}
errors = append(errors, err)
return nil, errors
}
requestCopy.Imp = validImps

reqJSON, err := json.Marshal(requestCopy)
if err != nil {
errors = append(errors, err)
return nil, errors
Expand Down
8 changes: 6 additions & 2 deletions adapters/grid/gridtest/exemplary/simple-banner.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
}]
},
"ext": {
"bidder": {}
"bidder": {
"uid": 1
}
}
}]
},
Expand All @@ -35,7 +37,9 @@
}]
},
"ext": {
"bidder": {}
"bidder": {
"uid": 1
}
}
}]
}
Expand Down
8 changes: 6 additions & 2 deletions adapters/grid/gridtest/exemplary/simple-video.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
"h": 250
},
"ext": {
"bidder": {}
"bidder": {
"uid": 1
}
}
}]
},
Expand All @@ -35,7 +37,9 @@
"h": 250
},
"ext": {
"bidder": {}
"bidder": {
"uid": 1
}
}
}]
}
Expand Down
5 changes: 4 additions & 1 deletion adapters/grid/gridtest/params/race/banner.json
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
{}
{
"uid": 1
}

33 changes: 33 additions & 0 deletions adapters/grid/gridtest/supplemental/bad_bidder_request.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"mockBidRequest": {
"id": "test-request-id",
"imp": [
{
"id": "test-imp-id",
"banner": {
"format": [
{
"w": 300,
"h": 250
}
]
},
"ext": {
"bidder": "some not exist"
}
}
]
},
"expectedMakeRequestsErrors": [
{
"value": "json: cannot unmarshal string into Go value of type openrtb_ext.ExtImpGrid",
"comparison": "literal"
},
{
"value": "No valid impressions for grid",
"comparison": "literal"
}
],
"httpCalls":[],
"expectedBidResponses": []
}
30 changes: 30 additions & 0 deletions adapters/grid/gridtest/supplemental/bad_ext_request.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"mockBidRequest": {
"id": "test-request-id",
"imp": [
{
"id": "test-imp-id",
"banner": {
"format": [
{
"w": 300,
"h": 250
}
]
},
"ext": "any"
}
]
},
"expectedMakeRequestsErrors": [
{
"value": "json: cannot unmarshal string into Go value of type adapters.ExtImpBidder",
"comparison": "literal"
},
{
"value": "No valid impressions for grid",
"comparison": "literal"
}
],
"httpCalls": []
}
2 changes: 2 additions & 0 deletions adapters/grid/gridtest/supplemental/bad_response.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
},
"ext": {
"bidder": {
"uid": 1
}
}
}
Expand All @@ -39,6 +40,7 @@
},
"ext": {
"bidder": {
"uid": 1
}
}
}
Expand Down
33 changes: 33 additions & 0 deletions adapters/grid/gridtest/supplemental/empty_uid_request.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"mockBidRequest": {
"id": "test-request-id",
"imp": [
{
"id": "test-imp-id",
"banner": {
"format": [
{
"w": 300,
"h": 250
}
]
},
"ext": {
"bidder": {}
}
}
]
},
"expectedMakeRequestsErrors": [
{
"value": "uid is empty",
"comparison": "literal"
},
{
"value": "No valid impressions for grid",
"comparison": "literal"
}
],
"httpCalls":[],
"expectedBidResponses": []
}
13 changes: 13 additions & 0 deletions adapters/grid/gridtest/supplemental/no_imp_request.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"mockBidRequest": {
"id": "test-request-id",
"imp": []
},
"expectedMakeRequestsErrors": [
{
"value": "No valid impressions for grid",
"comparison": "literal"
}
],
"httpCalls":[]
}
2 changes: 2 additions & 0 deletions adapters/grid/gridtest/supplemental/status_204.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
},
"ext": {
"bidder": {
"uid": 1
}
}
}
Expand All @@ -39,6 +40,7 @@
},
"ext": {
"bidder": {
"uid": 1
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions adapters/grid/gridtest/supplemental/status_400.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
},
"ext": {
"bidder": {
"uid": 1
}
}
}
Expand All @@ -39,6 +40,7 @@
},
"ext": {
"bidder": {
"uid": 1
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions adapters/grid/gridtest/supplemental/status_418.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
},
"ext": {
"bidder": {
"uid": 1
}
}
}
Expand All @@ -39,6 +40,7 @@
},
"ext": {
"bidder": {
"uid": 1
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions openrtb_ext/imp_grid.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package openrtb_ext

// ExtImpGrid defines the contract for bidrequest.imp[i].ext.grid
type ExtImpGrid struct {
Uid int `json:"uid"`
}
7 changes: 6 additions & 1 deletion static/bidder-params/grid.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
"title": "TheMediaGrid Adapter Params",
"description": "A schema which validates params accepted by TheMediaGrid adapter",
"type": "object",
"properties": {},
"properties": {
"uid": {
"type": "integer",
"description": "An ID which identifies this placement of the impression"
}
},
"required": []
}