コード例 #1
0
 def test_get_tweets(self):
     tweet_db = models.Tweet(
         username="******",
         content="Test Content",
         posted_at=datetime.datetime.now(),
         last_edited_at=datetime.datetime.now(),
     )
     for tag in ["tag_1", "tag_2"]:
         tweet_db.tags.append(models.Tag(tag=tag))
     tweets = [tweet_db, tweet_db]
     self.twitter_clone_db.get_tweets.return_value = tweets
     all_tweets = []
     t1 = Timestamp()
     t2 = Timestamp()
     for tweet in tweets:
         if tweet.posted_at is not None:
             t1.FromDatetime(tweet.posted_at)
         if tweet.last_edited_at is not None:
             t2.FromDatetime(tweet.last_edited_at)
         else:
             t2 = t1
         ret_tweet = Tweet(
             id=tweet.id,
             username=tweet.username,
             content=tweet.content,
             posted_at=t1,
             last_edited_at=t2,
         )
         for tag in tweet.tags:
             ret_tweet.tag.append(tag.tag)
         all_tweets.append(ret_tweet)
     helper = Helper(self.twitter_clone_db)
     assert helper.get_tweets(self.tweet) == all_tweets
コード例 #2
0
 def GetAllTweets(self, request, context):
     logger.info("Calling GetAllTweets")
     helper = Helper()
     all_tweets = helper.get_all_tweets()
     for tweet in all_tweets:
         yield tweet
コード例 #3
0
 def EditTweet(self, request, context):
     logger.info("Calling EditTweet")
     helper = Helper()
     response = helper.edit_tweet(request.id, request.content, request.tag)
     return response
コード例 #4
0
 def RemoveTweet(self, request, context):
     logger.info("Calling RemoveTweet")
     helper = Helper()
     helper.remove_tweet(request.id)
コード例 #5
0
 def CreateTweet(self, request, context):
     logger.info("Calling CreateTweet")
     helper = Helper()
     response = helper.create_tweet(request.username, request.content, request.tag)
     return response
コード例 #6
0
 def GetTweets(self, request, context):
     logger.info("Calling GetTweets")
     helper = Helper()
     all_tweets = helper.get_tweets(request.username)
     for tweet in all_tweets:
         yield tweet
コード例 #7
0
 def test_get_tweets_returns_empty_list_if_username_not_present(self):
     self.twitter_clone_db.get_tweets.return_value = []
     helper = Helper(self.twitter_clone_db)
     assert helper.get_tweets(self.tweet) == []