Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: sitescripts/notifications/test/notification.py

Issue 29325919: Issue 2982 - Return all notifications that have title and message (Closed)
Patch Set: Created Sept. 4, 2015, 9:03 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: sitescripts/notifications/test/notification.py
===================================================================
--- a/sitescripts/notifications/test/notification.py
+++ b/sitescripts/notifications/test/notification.py
@@ -30,7 +30,9 @@
self.load_notifications_patcher.stop()
def test_no_group(self):
- self.load_notifications_mock.return_value = [{"id": "1"}]
+ self.load_notifications_mock.return_value = [
+ {"id": "1", "title": {"en-US": ""}, "message": {"en-US": ""}}
Felix Dahlke 2015/09/04 09:08:40 Adding title and message this way to each notifica
Sebastian Noack 2015/09/04 11:38:12 DUMMY_TEXTS = {"title": {"en-US": ""}, "message":
Felix Dahlke 2015/09/07 07:54:36 Now that I've gotten rid of the "en-US" checking,
+ ]
result = json.loads(notification.notification({}, lambda *args: None))
self.assertEqual(len(result["notifications"]), 1)
self.assertEqual(result["notifications"][0]["id"], "1")
@@ -38,10 +40,10 @@
def test_not_in_group(self):
self.load_notifications_mock.return_value = [
- {"id": "1"},
+ {"id": "1", "title": {"en-US": ""}, "message": {"en-US": ""}},
{
"id": "a",
- "variants": [{}]
+ "variants": [{"title": {"en-US": ""}, "message": {"en-US": ""}}]
}
]
result = json.loads(notification.notification({
@@ -53,10 +55,10 @@
def test_in_group(self):
self.load_notifications_mock.return_value = [
- {"id": "1"},
+ {"id": "1", "title": {"en-US": ""}, "message": {"en-US": ""}},
{
"id": "a",
- "variants": [{}]
+ "variants": [{"title": {"en-US": ""}, "message": {"en-US": ""}}]
}
]
result = json.loads(notification.notification({
@@ -68,18 +70,18 @@
def test_not_in_one_of_many_groups(self):
self.load_notifications_mock.return_value = [
- {"id": "1"},
+ {"id": "1", "title": {"en-US": ""}, "message": {"en-US": ""}},
{
"id": "a",
- "variants": [{}]
+ "variants": [{"title": {"en-US": ""}, "message": {"en-US": ""}}]
},
{
"id": "b",
- "variants": [{}]
+ "variants": [{"title": {"en-US": ""}, "message": {"en-US": ""}}]
},
{
"id": "c",
- "variants": [{}]
+ "variants": [{"title": {"en-US": ""}, "message": {"en-US": ""}}]
}
]
result = json.loads(notification.notification({
@@ -91,18 +93,18 @@
def test_in_one_of_many_groups(self):
self.load_notifications_mock.return_value = [
- {"id": "1"},
+ {"id": "1", "title": {"en-US": ""}, "message": {"en-US": ""}},
{
"id": "a",
- "variants": [{}]
+ "variants": [{"title": {"en-US": ""}, "message": {"en-US": ""}}]
},
{
"id": "b",
- "variants": [{}]
+ "variants": [{"title": {"en-US": ""}, "message": {"en-US": ""}}]
},
{
"id": "c",
- "variants": [{}]
+ "variants": [{"title": {"en-US": ""}, "message": {"en-US": ""}}]
}
]
result = json.loads(notification.notification({
@@ -114,10 +116,12 @@
def test_not_put_in_group(self):
self.load_notifications_mock.return_value = [
- {"id": "1"},
+ {"id": "1", "title": {"en-US": ""}, "message": {"en-US": ""}},
{
"id": "a",
- "variants": [{"sample": 0}]
+ "variants": [
+ {"sample": 0, "title": {"en-US": ""}, "message": {"en-US": ""}}
+ ]
}
]
result = json.loads(notification.notification({
@@ -129,10 +133,12 @@
def test_put_in_group(self):
self.load_notifications_mock.return_value = [
- {"id": "1"},
+ {"id": "1", "title": {"en-US": ""}, "message": {"en-US": ""}},
{
"id": "a",
- "variants": [{"sample": 1}]
+ "variants": [
+ {"sample": 1, "title": {"en-US": ""}, "message": {"en-US": ""}}
+ ]
}
]
result = json.loads(notification.notification({
@@ -146,13 +152,12 @@
self.load_notifications_mock.return_value = [
{
"id": "a",
- "title.en-GB": "default",
- "message.en-GB": "default",
- "message.de-DE": "vorgabe",
+ "title": {"en-US": "default"},
Felix Dahlke 2015/09/04 09:08:40 No idea why I had that syntax there, it's not vali
+ "message": {"en-US": "default"},
"variants": [
{
"sample": 1,
- "message.en-GB": "variant"
+ "message": {"en-US": "variant"}
}
]
}
@@ -160,9 +165,8 @@
result = json.loads(notification.notification({}, lambda *args: None))
self.assertEqual(len(result["notifications"]), 1)
self.assertEqual(result["notifications"][0]["id"], "a")
- self.assertEqual(result["notifications"][0]["title.en-GB"], "default")
- self.assertEqual(result["notifications"][0]["message.en-GB"], "variant")
- self.assertEqual(result["notifications"][0]["message.de-DE"], "vorgabe")
+ self.assertEqual(result["notifications"][0]["title"]["en-US"], "default")
+ self.assertEqual(result["notifications"][0]["message"]["en-US"], "variant")
self.assertFalse("variants" in result["notifications"][0])
self.assertFalse("sample" in result["notifications"][0])
@@ -184,15 +188,18 @@
"variants": [
{
"sample": 0.5,
- "title.en-GB": "1"
+ "title": {"en-US": "1"},
+ "message": {"en-US": ""}
},
{
"sample": 0.25,
- "title.en-GB": "2"
+ "title": {"en-US": "2"},
+ "message": {"en-US": ""}
},
{
"sample": 0.25,
- "title.en-GB": "3"
+ "title": {"en-US": "3"},
+ "message": {"en-US": ""}
}
]
}
@@ -200,32 +207,32 @@
random_call.return_value = 0
result = json.loads(notification.notification({}, lambda *args: None))
self.assertEqual(len(result["notifications"]), 1)
- self.assertEqual(result["notifications"][0]["title.en-GB"], "1")
+ self.assertEqual(result["notifications"][0]["title"]["en-US"], "1")
self.assertRegexpMatches(result["version"], r"-a/1")
random_call.return_value = 0.5
result = json.loads(notification.notification({}, lambda *args: None))
self.assertEqual(len(result["notifications"]), 1)
- self.assertEqual(result["notifications"][0]["title.en-GB"], "1")
+ self.assertEqual(result["notifications"][0]["title"]["en-US"], "1")
self.assertRegexpMatches(result["version"], r"-a/1")
random_call.return_value = 0.51
result = json.loads(notification.notification({}, lambda *args: None))
self.assertEqual(len(result["notifications"]), 1)
- self.assertEqual(result["notifications"][0]["title.en-GB"], "2")
+ self.assertEqual(result["notifications"][0]["title"]["en-US"], "2")
self.assertRegexpMatches(result["version"], r"-a/2")
random_call.return_value = 0.75
result = json.loads(notification.notification({}, lambda *args: None))
self.assertEqual(len(result["notifications"]), 1)
- self.assertEqual(result["notifications"][0]["title.en-GB"], "2")
+ self.assertEqual(result["notifications"][0]["title"]["en-US"], "2")
self.assertRegexpMatches(result["version"], r"-a/2")
random_call.return_value = 0.751
result = json.loads(notification.notification({}, lambda *args: None))
self.assertEqual(len(result["notifications"]), 1)
- self.assertEqual(result["notifications"][0]["title.en-GB"], "3")
+ self.assertEqual(result["notifications"][0]["title"]["en-US"], "3")
self.assertRegexpMatches(result["version"], r"-a/3")
random_call.return_value = 1
result = json.loads(notification.notification({}, lambda *args: None))
self.assertEqual(len(result["notifications"]), 1)
- self.assertEqual(result["notifications"][0]["title.en-GB"], "3")
+ self.assertEqual(result["notifications"][0]["title"]["en-US"], "3")
self.assertRegexpMatches(result["version"], r"-a/3")
@mock.patch("random.random")
@@ -236,11 +243,13 @@
"variants": [
{
"sample": 0.25,
- "title.en-GB": "1"
+ "title": {"en-US": "1"},
+ "message": {"en-US": ""}
},
{
"sample": 0.25,
- "title.en-GB": "2"
+ "title": {"en-US": "2"},
+ "message": {"en-US": ""}
}
]
},
@@ -249,11 +258,13 @@
"variants": [
{
"sample": 0.25,
- "title.en-GB": "1"
+ "title": {"en-US": "1"},
+ "message": {"en-US": ""}
},
{
"sample": 0.25,
- "title.en-GB": "2"
+ "title": {"en-US": "2"},
+ "message": {"en-US": ""}
}
]
}
@@ -262,25 +273,25 @@
result = json.loads(notification.notification({}, lambda *args: None))
self.assertEqual(len(result["notifications"]), 1)
self.assertEqual(result["notifications"][0]["id"], "a")
- self.assertEqual(result["notifications"][0]["title.en-GB"], "1")
+ self.assertEqual(result["notifications"][0]["title"]["en-US"], "1")
self.assertRegexpMatches(result["version"], r"-a/1-b/0")
random_call.return_value = 0.251
result = json.loads(notification.notification({}, lambda *args: None))
self.assertEqual(len(result["notifications"]), 1)
self.assertEqual(result["notifications"][0]["id"], "a")
- self.assertEqual(result["notifications"][0]["title.en-GB"], "2")
+ self.assertEqual(result["notifications"][0]["title"]["en-US"], "2")
self.assertRegexpMatches(result["version"], r"-a/2-b/0")
random_call.return_value = 0.51
result = json.loads(notification.notification({}, lambda *args: None))
self.assertEqual(len(result["notifications"]), 1)
self.assertEqual(result["notifications"][0]["id"], "b")
- self.assertEqual(result["notifications"][0]["title.en-GB"], "1")
+ self.assertEqual(result["notifications"][0]["title"]["en-US"], "1")
self.assertRegexpMatches(result["version"], r"-a/0-b/1")
random_call.return_value = 0.751
result = json.loads(notification.notification({}, lambda *args: None))
self.assertEqual(len(result["notifications"]), 1)
self.assertEqual(result["notifications"][0]["id"], "b")
- self.assertEqual(result["notifications"][0]["title.en-GB"], "2")
+ self.assertEqual(result["notifications"][0]["title"]["en-US"], "2")
self.assertRegexpMatches(result["version"], r"-a/0-b/2")
def test_invalid_last_version(self):
@@ -295,7 +306,9 @@
lambda *args: None)
def test_version_header_present(self):
- self.load_notifications_mock.return_value = [{"id": "1"}]
+ self.load_notifications_mock.return_value = [
+ {"id": "1", "title": {"en-US": ""}, "message": {"en-US": ""}}
+ ]
response_header_map = {}
def start_response(status, response_headers):
for name, value in response_headers:
@@ -304,5 +317,57 @@
self.assertEqual(result["version"],
response_header_map["ABP-Notification-Version"])
+ def test_default_group_notification_returned_if_valid(self):
+ self.load_notifications_mock.return_value = [
+ {"id": "1", "title": {"en-US": ""}, "message": {"en-US": ""}},
+ {
+ "id": "a",
+ "title": {"en-US": "0"},
+ "message": {"en-US": "0"},
+ "variants": [
+ {"title": {"en-US": "1"}, "message": {"en-US": "1"}}
+ ]
+ }
+ ]
+ result = json.loads(notification.notification({
+ "QUERY_STRING": "lastVersion=197001010000-a/0"
+ }, lambda *args: None))
+ self.assertEqual(len(result["notifications"]), 2)
+ self.assertEqual(result["notifications"][0]["id"], "1")
+ self.assertEqual(result["notifications"][1]["id"], "a")
+ self.assertEqual(result["notifications"][1]["title"]["en-US"], "0")
+ self.assertNotIn("variants", result["notifications"][1])
+ self.assertRegexpMatches(result["version"], r"-a/0")
+
+ def test_default_group_notification_not_returned_if_invalid(self):
+ self.load_notifications_mock.return_value = [
+ {"id": "1", "title": {"en-US": ""}, "message": {"en-US": ""}},
+ {
+ "id": "a",
+ "title": {"en-US": "0"},
+ "variants": [
+ {"title": {"en-US": "1"}, "message": {"en-US": "1"}}
+ ]
+ }
+ ]
+ result = json.loads(notification.notification({
+ "QUERY_STRING": "lastVersion=197001010000-a/0"
+ }, lambda *args: None))
+ self.assertEqual(len(result["notifications"]), 1)
+ self.assertEqual(result["notifications"][0]["id"], "1")
+ self.assertRegexpMatches(result["version"], r"-a/0")
+
+ def test_invalid_notification_not_returned(self):
+ self.load_notifications_mock.return_value = [
+ {"id": "1", "title": {"en-US": ""}, "message": {"en-US": ""}},
+ {"id": "2", "title": {"en-US": ""}},
+ {"id": "3", "title": {}, "message": {"en-US": ""}},
+ {"id": "4", "message": {"en-US": ""}},
+ {"id": "5", "title": {"en-US": ""}, "message": {}},
+ ]
+ result = json.loads(notification.notification({}, lambda *args: None))
+ self.assertEqual(len(result["notifications"]), 1)
+ self.assertEqual(result["notifications"][0]["id"], "1")
+
if __name__ == '__main__':
unittest.main()
« no previous file with comments | « no previous file | sitescripts/notifications/web/notification.py » ('j') | sitescripts/notifications/web/notification.py » ('J')

Powered by Google App Engine
This is Rietveld