Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
5 changes: 5 additions & 0 deletions server/integration_tests/standalone/adversarial.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
from absl import flags
import requests

from shared.lib.constants import CRON_TEST_SURFACE, SURFACE_HEADER_NAME
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

To improve maintainability and centralize header definitions, it's better to define a CRON_TEST_SURFACE_HEADER constant in shared/lib/constants.py and import it here. This avoids importing CRON_TEST_SURFACE and SURFACE_HEADER_NAME just to construct the header.

Suggested change
from shared.lib.constants import CRON_TEST_SURFACE, SURFACE_HEADER_NAME
from shared.lib.constants import CRON_TEST_SURFACE_HEADER


FLAGS = flags.FLAGS

INPUT_DIR = "input"
Expand Down Expand Up @@ -327,6 +329,9 @@ def run_query(self, query: str) -> Result:
'contextHistory': {},
'dc': f'{post_dc_param}',
},
headers={
SURFACE_HEADER_NAME: CRON_TEST_SURFACE
},
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

By using a predefined CRON_TEST_SURFACE_HEADER constant, you can simplify this call and ensure consistency across different parts of the codebase that need to send this header.

          headers=CRON_TEST_SURFACE_HEADER,

timeout=30)
except requests.exceptions.ReadTimeout:
result.status = ResultStatus.TIMED_OUT
Expand Down
7 changes: 6 additions & 1 deletion server/integration_tests/standalone/nodejs_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
from absl import flags
import requests

from shared.lib.constants import CRON_TEST_SURFACE, SURFACE_HEADER_NAME
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

To improve maintainability and centralize header definitions, it's better to define a CRON_TEST_SURFACE_HEADER constant in shared/lib/constants.py and import it here. This avoids importing CRON_TEST_SURFACE and SURFACE_HEADER_NAME just to construct the header.

Suggested change
from shared.lib.constants import CRON_TEST_SURFACE, SURFACE_HEADER_NAME
from shared.lib.constants import CRON_TEST_SURFACE_HEADER


FLAGS = flags.FLAGS

OUTPUT_DIR = 'output'
Expand Down Expand Up @@ -61,7 +63,10 @@ def run_test():
all_charts = test_case.get('all_charts', '')
client = test_case.get('client', '')
resp = requests.get(
f'{FLAGS.base_url}/nodejs/query?q={query}&allCharts={all_charts}&client={client}'
f'{FLAGS.base_url}/nodejs/query?q={query}&allCharts={all_charts}&client={client}',
headers={
SURFACE_HEADER_NAME: CRON_TEST_SURFACE
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

By using a predefined CRON_TEST_SURFACE_HEADER constant, you can simplify this call and ensure consistency across different parts of the codebase that need to send this header.

        headers=CRON_TEST_SURFACE_HEADER

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Response to all of these comments: I just used the test surface header instead -- figured I don't actually need a separate cron test header

).json()
for chart in resp.get('charts', []):
chart['chartUrl'] = ''
Expand Down
1 change: 1 addition & 0 deletions shared/lib/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@
SURFACE_HEADER_NAME = "x-surface"
WEBSITE_SURFACE = "website"
TEST_SURFACE = "integration-test"
CRON_TEST_SURFACE = "cron-tests"
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

To improve maintainability and avoid duplicating the header dictionary construction, consider defining a constant for the cron test surface header, similar to TEST_SURFACE_HEADER. You can then use this constant in adversarial.py and nodejs_query.py.

Suggested change
CRON_TEST_SURFACE = "cron-tests"
CRON_TEST_SURFACE = "cron-tests"
CRON_TEST_SURFACE_HEADER = {SURFACE_HEADER_NAME: CRON_TEST_SURFACE}

TEST_SURFACE_HEADER = {SURFACE_HEADER_NAME: "integration-test"}
# This is passed into mixer if no other x-surface header is provided, and indicates
# that this call came from an unknown DC surface via the website. This is set here to
Expand Down