Esempio n. 1
0
def _act_no_messages(api, moxer):
    _no_messages(api, moxer)

    _mix_random(api, moxer)

    api.PostUpdate(IsA(str)).AndReturn(
        Record(text="epic, fail is epic", user=Record(screen_name="jbell")))
Esempio n. 2
0
    def test_retweet_not_previously_retweeted(self):
        moxer = Mox()

        api = _create_api(moxer)
        bundle = _create_actor_and_delegates(api, moxer)
        actor = bundle.actor
        analyzer = bundle.analyzer

        status_user = Record(screen_name=self.id())
        status_ids = [5, 10, 15]
        timeline = (Record(id=id,
                           text="epic, fail is epic %s" % id,
                           user=status_user) for id in status_ids)
        api.GetFriendsTimeline(count=10).AndReturn(timeline)
        # print "timeline: %s" % [t for t in timeline]

        # I choose a status to be the one I will retweet
        not_already_retweeted_id = status_ids[2]

        moxer.StubOutWithMock(TwitterResponseAccessor, "get_by_message_id")
        moxer.StubOutWithMock(TwitterResponseAccessor, "create")

        print "not_already_retweeted_id: %s " % not_already_retweeted_id
        for status_id in status_ids:
            print "status_id: %s" % status_id
            print "%s != %s == %s" % (status_id, not_already_retweeted_id,
                                      status_id != not_already_retweeted_id)

            if status_id != not_already_retweeted_id:
                # returns a result which means "already retweeted".  id is meaningless
                result = Record(message_id=status_id,
                                response_id=status_id * 10)
                TwitterResponseAccessor.get_by_message_id(
                    IsA(str)).AndReturn(result)
                print "returned %s for %s" % (result, status_id)
                continue

            # this status is the one I will retweet
            status_id_str = str(status_id)
            TwitterResponseAccessor.get_by_message_id(status_id_str)
            _should_retweet(analyzer)

            retweet_id = str(status_id + 1)
            retweet = Record(id=retweet_id, user=self.id())
            api.PostRetweet(status_id).AndReturn(retweet)
            TwitterResponseAccessor.create(status_id_str,
                                           response_id=retweet_id,
                                           tweet_type=TwitterResponse.RETWEET,
                                           user=status_user.screen_name)

        moxer.ReplayAll()
        actor.retweet()
        moxer.VerifyAll()
Esempio n. 3
0
def _create_actor_and_delegates(api, moxer):
    selector = moxer.CreateMock(ActionSelector)
    analyzer = moxer.CreateMock(TweetAnalyzer)
    actor = TwitterActor(selector=selector,
                         twitter_api=api,
                         reporter=Absorber(),
                         analyzer=analyzer)
    return Record(actor=actor, selector=selector, analyzer=analyzer)
Esempio n. 4
0
def _new_status():
    return Record(text="hi", user=Record(screen_name="mhawthorne"))
Esempio n. 5
0
def _fetch_trends(api):
    trends = ((Record(name="#universe"), Record(name="#interesting")),
              (Record(name="#explode"), Record(name="#whywhywhy")))
    api.GetTrendsDaily().AndReturn(trends)
Esempio n. 6
0
 def __msg(self, text):
     return Record(text=text, user=Record(screen_name="mhawthorne"))
Esempio n. 7
0
 def retweet(self, *args):
     tweet_id = args[0]
     r = Record(id=tweet_id)
     self.__decorate_status(r)
     return r
Esempio n. 8
0
 def postUpdate(self, *args):
     msg = args[0]
     self.__post_id += 1
     r = Record(id=self.__post_id)
     self.__decorate_status(r)
     return r
Esempio n. 9
0
 def __decorate_status(self, status):
     status.asDict = lambda: status.to_hash()
     status.user = Record()