Implemented postly unit tests
Browse files- tests/__init__.py +0 -0
- tests/test_plotly.py +61 -0
tests/__init__.py
ADDED
File without changes
|
tests/test_plotly.py
ADDED
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from postly.clients import PostlyClient
|
2 |
+
|
3 |
+
|
4 |
+
class TestYodelrSystem:
|
5 |
+
def setup_method(self):
|
6 |
+
self.postly_instance = PostlyClient()
|
7 |
+
|
8 |
+
# define reference data for testing
|
9 |
+
self.gt_posts = [
|
10 |
+
"just #chilling today",
|
11 |
+
"eating #steak for dinner",
|
12 |
+
"ugh! this #steak tasted like dog food"
|
13 |
+
]
|
14 |
+
self.gt_topics = [["chilling"], ["steak"], ["steak"]]
|
15 |
+
|
16 |
+
# add toy data for testing
|
17 |
+
self.postly_instance.add_user("john")
|
18 |
+
for i, post in enumerate(self.gt_posts):
|
19 |
+
self.postly_instance.add_post("john", post, i)
|
20 |
+
|
21 |
+
def test_add_user(self):
|
22 |
+
assert "john" in self.postly_instance.userPosts
|
23 |
+
|
24 |
+
def test_add_post(self):
|
25 |
+
assert len(self.postly_instance.userPosts["john"]) == 3
|
26 |
+
|
27 |
+
def test_get_posts_for_user(self):
|
28 |
+
retrieved_posts = self.postly_instance.get_posts_for_user("john")
|
29 |
+
|
30 |
+
assert len(retrieved_posts) == 3
|
31 |
+
for post, gt_post in zip(retrieved_posts, self.gt_posts[::-1]):
|
32 |
+
assert post == gt_post
|
33 |
+
|
34 |
+
def test_get_posts_for_topic(self):
|
35 |
+
retrieved_posts = self.postly_instance.get_posts_for_topic("steak")
|
36 |
+
|
37 |
+
assert len(retrieved_posts) == 2
|
38 |
+
for post in retrieved_posts:
|
39 |
+
assert "#steak" in post
|
40 |
+
|
41 |
+
def test_get_trending_topics(self):
|
42 |
+
trending_topics = self.postly_instance.get_trending_topics(1, 3)
|
43 |
+
|
44 |
+
assert len(trending_topics) == 2
|
45 |
+
assert trending_topics == ["steak", "chilling"]
|
46 |
+
|
47 |
+
trending_topics = self.postly_instance.get_trending_topics(2, 3)
|
48 |
+
|
49 |
+
assert len(trending_topics) == 1
|
50 |
+
assert trending_topics == ["steak"]
|
51 |
+
|
52 |
+
def test_delete_user(self):
|
53 |
+
temporary_postly_instance = postlyClient()
|
54 |
+
temporary_postly_instance.add_user("simon")
|
55 |
+
temporary_postly_instance.add_post("simon", "just #coding today", 1)
|
56 |
+
|
57 |
+
assert "simon" in temporary_postly_instance.userPosts
|
58 |
+
|
59 |
+
temporary_postly_instance.delete_user("simon")
|
60 |
+
|
61 |
+
assert "simon" not in temporary_postly_instance.userPosts
|