Skip to content

Commit

Permalink
Closes #11: Don't regress number of rows shown in T-Table.
Browse files Browse the repository at this point in the history
  • Loading branch information
Marina Samuel committed Feb 20, 2018
1 parent 466adfb commit 4ec35bd
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 9 deletions.
19 changes: 16 additions & 3 deletions stmoab/StatisticalDashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,14 +196,28 @@ def add_ttable(self, title):
"will not be added to dashboard.").format(title=title))
return

chart_data = self.get_query_ids_and_names()
num_rows_current_ttable = 0

if title in chart_data:
data = self._get_query_results(
chart_data[title]["query"], self.URL_FETCHER_DATA_SOURCE_ID, title)
num_rows_current_ttable = len(data)

# Don't replace the existing T-Table unless we have at least an
# equivalent number of rows.
if len(self._ttables[title]["rows"]) < num_rows_current_ttable:
self._logger.info((
"StatisticalDashboard: T-Table data for {title} is incomplete and "
"will not be added to dashboard.").format(title=title))
return

self._logger.info((
"StatisticalDashboard: Creating a T-Table with "
"title {title}").format(title=title))

FILENAME = '{exp_id}_{title}'.format(exp_id=self._experiment_id, title=title)

chart_data = self.get_query_ids_and_names()

# Remove a table if it already exists
if title in chart_data:
self._logger.info((
Expand All @@ -227,4 +241,3 @@ def add_ttable(self, title):
self.TTABLE_DESCRIPTION,
)
self._add_visualization_to_dashboard(table_id, VizWidth.WIDE)

69 changes: 63 additions & 6 deletions stmoab/tests/test_statistical_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,62 @@ def get_server(url):

mock_json_uploader.stop()

def test_no_requests_made_for_empty_ttable(self):
TABLE_NAME = "Table Name"
self.dash.add_ttable(TABLE_NAME)

# GET calls:
# 1) Create dashboard
# POST calls:
# 1) Create dashboard
# 3) Make dashboard public
self.assertEqual(self.mock_requests_post.call_count, 2)
self.assertEqual(self.mock_requests_get.call_count, 1)

def test_ttable_not_replaced_with_fewer_rows(self):
self.get_calls = 0
TABLE_NAME = "Table Name"
QUERY_RESULTS_RESPONSE = {
"query_result": {
"data": {
"rows": [{"row_1": 1}, {"row_2": 2}]
}
}
}

WIDGETS_RESPONSE = {
"widgets": [[{
"id": "123",
"visualization": {
"query": {
"name": TABLE_NAME,
"id": "abc"
},
},
}]]
}

self.mock_requests_post.return_value = self.get_mock_response(
content=json.dumps(QUERY_RESULTS_RESPONSE))
self.mock_requests_get.return_value = self.get_mock_response(
content=json.dumps(WIDGETS_RESPONSE))

self.dash._ttables[TABLE_NAME] = {}
self.dash._ttables[TABLE_NAME]["rows"] = []
self.dash._ttables[TABLE_NAME]["rows"].append({"row": 1})

self.dash.add_ttable(TABLE_NAME)

# GET calls:
# 1) Create dashboard
# 2) Get dashboard widgets
# POST calls:
# 1) Create dashboard
# 2) Get query results for existing T-Table
# 3) Make dashboard public
self.assertEqual(self.mock_requests_post.call_count, 3)
self.assertEqual(self.mock_requests_get.call_count, 2)

def test_statistical_analysis_graph_exist_deletes_and_creates_new(self):
self.get_calls = 0
TABLE_NAME = "Table Name"
Expand Down Expand Up @@ -398,12 +454,13 @@ def get_server(url):
# 4) Get template
# POST calls:
# 1) Create dashboard
# 2) Update queries (5 events * 2 requests each: update + refresh)
# 3) Get Ttable query results for 5 rows
# 4) Create query for ttable (doesn't return ID, so no refresh)
# 5) Add query to dashboard
# 6) Make dashboard public
self.assertEqual(self.mock_requests_post.call_count, 19)
# 2) Get query results for existing T-Table
# 3) Update queries (5 events * 2 requests each: update + refresh)
# 4) Get Ttable query results for 5 rows
# 5) Create query for ttable (doesn't return ID, so no refresh)
# 6) Add query to dashboard
# 7) Make dashboard public
self.assertEqual(self.mock_requests_post.call_count, 20)
self.assertEqual(self.mock_requests_get.call_count, 5)
self.assertEqual(self.mock_requests_delete.call_count, 2)

Expand Down

0 comments on commit 4ec35bd

Please sign in to comment.