Ejemplo n.º 1
0
 def test_does_not_tweet_when_recently_tweeted(self):
     # make sure it can't send an actual tweet by removing the credentials
     cache_helpers.reset_cache()
     self.config.remove([
         'ckanext.twitter.key', 'ckanext.twitter.secret',
         'ckanext.twitter.token_key', 'ckanext.twitter.token_secret'
     ])
     # turn off debug so it skips that check
     self.config.update({'debug': False, 'ckanext.twitter.debug': False})
     # emulate successful tweet by manually inserting into the cache
     cache_helpers.cache(self.df.public_records['id'])
     # try to tweet
     tweeted, reason = twitter_api.post_tweet('This is a test tweet.',
                                              self.df.public_records['id'])
     eq_(tweeted, False)
     eq_(reason, 'insufficient rest period')
Ejemplo n.º 2
0
 def test_does_tweet_when_new(self):
     # make sure it can't send an actual tweet by removing the credentials
     cache_helpers.reset_cache()
     self.config.remove([
         'ckanext.twitter.key', 'ckanext.twitter.secret',
         'ckanext.twitter.token_key', 'ckanext.twitter.token_secret'
     ])
     # turn off debug so it skips that check
     self.config.update({'debug': False, 'ckanext.twitter.debug': False})
     # refresh the database to see if it's sending tweets during creation
     self.df.refresh()
     pkg_dict = self.df.public_records
     # try to tweet
     tweeted, reason = twitter_api.post_tweet('This is a test tweet.',
                                              pkg_dict['id'])
     eq_(tweeted, False)
     eq_(reason, 'not authenticated')
Ejemplo n.º 3
0
 def send(self, pkg_id):
     '''
     Posts the tweet given in the request body. The package ID is
     required for caching. Returns json data for displaying success/error
     messages.
     :param pkg_id: The package ID (for caching).
     :return: str
     '''
     body = dict(c.pylons.request.postvars)
     text = body.get('tweet_text', None)
     if text:
         posted, reason = twitter_api.post_tweet(text, pkg_id)
     else:
         posted = False
         reason = 'no tweet defined'
     return json.dumps({
         'success': posted,
         'reason': reason,
         'tweet': text if text else 'tweet not defined'
         })
Ejemplo n.º 4
0
 def test_does_not_tweet_when_debug(self):
     self.config.update({'ckanext.twitter.debug': True})
     tweeted, reason = twitter_api.post_tweet('This is a test tweet.',
                                              self.df.public_records['id'])
     eq_(tweeted, False)
     eq_(reason, 'debug')