|
1 | 1 | from dateutil.tz import tzlocal |
2 | 2 | import stream |
3 | 3 | import time |
4 | | -from stream.exceptions import ApiKeyException, InputException |
| 4 | +from stream.exceptions import ApiKeyException, InputException, StreamApiException |
5 | 5 | import random |
6 | 6 | import jwt |
7 | 7 |
|
@@ -1210,7 +1210,9 @@ def test_reaction_get(self): |
1210 | 1210 | self.assertEqual(reaction["data"], {}) |
1211 | 1211 | self.assertEqual(reaction["latest_children"], {}) |
1212 | 1212 | self.assertEqual(reaction["children_counts"], {}) |
1213 | | - self.assertEqual(reaction["activity_id"], "54a60c1e-4ee3-494b-a1e3-50c06acb5ed4") |
| 1213 | + self.assertEqual( |
| 1214 | + reaction["activity_id"], "54a60c1e-4ee3-494b-a1e3-50c06acb5ed4" |
| 1215 | + ) |
1214 | 1216 | self.assertEqual(reaction["kind"], "like") |
1215 | 1217 | self.assertIn("created_at", reaction) |
1216 | 1218 | self.assertIn("updated_at", reaction) |
@@ -1249,31 +1251,55 @@ def test_reaction_filter_random(self): |
1249 | 1251 |
|
1250 | 1252 | def _first_result_should_be(self, response, element): |
1251 | 1253 | el = element.copy() |
1252 | | - el.pop('duration') |
| 1254 | + el.pop("duration") |
1253 | 1255 | self.assertEqual(len(response["results"]), 1) |
1254 | 1256 | self.assertEqual(response["results"][0], el) |
1255 | 1257 |
|
1256 | 1258 | def test_reaction_filter(self): |
1257 | 1259 | activity_id = str(uuid1()) |
1258 | 1260 | user = str(uuid1()) |
1259 | 1261 |
|
1260 | | - response = self.c.reactions.add( |
1261 | | - "like", activity_id, user |
1262 | | - ) |
1263 | | - child = self.c.reactions.add_child( |
1264 | | - "like", response["id"], user |
1265 | | - ) |
| 1262 | + response = self.c.reactions.add("like", activity_id, user) |
| 1263 | + child = self.c.reactions.add_child("like", response["id"], user) |
1266 | 1264 | reaction = self.c.reactions.get(response["id"]) |
1267 | | - r = self.c.reactions.filter( |
1268 | | - reaction_id=reaction["id"], |
1269 | | - ) |
| 1265 | + r = self.c.reactions.filter(reaction_id=reaction["id"]) |
1270 | 1266 | self._first_result_should_be(r, child) |
1271 | 1267 |
|
1272 | | - r = self.c.reactions.filter( |
1273 | | - activity_id=activity_id, |
1274 | | - id_lte=reaction["id"], |
1275 | | - ) |
| 1268 | + r = self.c.reactions.filter(activity_id=activity_id, id_lte=reaction["id"]) |
1276 | 1269 | self._first_result_should_be(r, reaction) |
1277 | 1270 |
|
1278 | 1271 | r = self.c.reactions.filter(user_id=user, id_lte=reaction["id"]) |
1279 | 1272 | self._first_result_should_be(r, reaction) |
| 1273 | + |
| 1274 | + def test_user_add(self): |
| 1275 | + self.c.users.add(str(uuid1())) |
| 1276 | + |
| 1277 | + def test_user_add_twice(self): |
| 1278 | + user_id = str(uuid1()) |
| 1279 | + self.c.users.add(user_id) |
| 1280 | + with self.assertRaises(StreamApiException): |
| 1281 | + self.c.users.add(user_id) |
| 1282 | + |
| 1283 | + def test_user_add_get_or_create(self): |
| 1284 | + user_id = str(uuid1()) |
| 1285 | + r1 = self.c.users.add(user_id) |
| 1286 | + r2 = self.c.users.add(user_id, get_or_create=True) |
| 1287 | + self.assertEqual(r1["id"], r2["id"]) |
| 1288 | + self.assertEqual(r1["created_at"], r2["created_at"]) |
| 1289 | + self.assertEqual(r1["updated_at"], r2["updated_at"]) |
| 1290 | + |
| 1291 | + def test_user_get(self): |
| 1292 | + response = self.c.users.add(str(uuid1())) |
| 1293 | + user = self.c.users.get(response["id"]) |
| 1294 | + self.assertEqual(user["data"], {}) |
| 1295 | + self.assertIn("created_at", user) |
| 1296 | + self.assertIn("updated_at", user) |
| 1297 | + self.assertIn("id", user) |
| 1298 | + |
| 1299 | + def test_user_update(self): |
| 1300 | + response = self.c.users.add(str(uuid1())) |
| 1301 | + self.c.users.update(response["id"], {"changed": True}) |
| 1302 | + |
| 1303 | + def test_user_delete(self): |
| 1304 | + response = self.c.users.add(str(uuid1())) |
| 1305 | + self.c.users.delete(response["id"]) |
0 commit comments