Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,23 @@ class OnPremiseGettingStartedWebTests(flask_unittest.ClientTestCase):
config = GettingStartedWeb.build_config()
app = GettingStartedWeb().build(config, logger).app

# The example's config.json shares usage, so sending is stood in for
# while the tests run and while the pipeline closes, and no usage data
# leaves the machine the tests run on.
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.sending = mock.patch("requests.post")
cls.sending.start()

# The example's pipeline lives as long as its app, so it is closed once
# the tests are finished with the app.
@classmethod
def tearDownClass(cls):
GettingStartedWeb.pipeline.close()
try:
GettingStartedWeb.pipeline.close()
finally:
cls.sending.stop()
super().tearDownClass()

def test_onpremise_getting_started_web(self, client):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,11 @@ def __init__(
if update_matched_useragent is not None:
config.setUpdateMatchedUserAgent(update_matched_useragent)

# Whether the matched User-Agents are recorded, which the native
# default turns on. UserAgents is empty when they are not.
self.update_matched_useragent = (
update_matched_useragent is None or bool(update_matched_useragent))

if allow_unmatched == True or allow_unmatched == False:
config.setAllowUnmatched(allow_unmatched)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ def get_internal(self, key):
return AspectPropertyValue(value = self.swig_results.getDeviceId())

if key == 'useragents':
# Populated only when the engine records the matched
# User-Agents, as its default is an empty list.
if not getattr(self.flow_element, "update_matched_useragent", True):
return AspectPropertyValue(value = [])
# Each component's result has a matched User-Agent, and several
# can match the same one, which is listed once.
useragents = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,10 @@ def test_turned_on_populates_user_agents(self):
self._user_agents(update_matched_useragent=True))

def test_turned_off_leaves_user_agents_empty(self):
user_agents = self._user_agents(update_matched_useragent=False)
self.assertGreaterEqual(len(user_agents), 1)
self.assertEqual([""] * len(user_agents), user_agents)
# UserAgents is populated only when the option is on, and its
# default is an empty list.
self.assertEqual(
[], self._user_agents(update_matched_useragent=False))


@unittest.skipUnless(
Expand Down
Loading