Example #1
0
    def test_process_new_tweet_from_double_registered_hashtag_subscribed_only_on_both(self):
        from maxrules.tasks import processTweet
        from .mockers import create_contextA, create_contextB
        from .mockers import subscribe_contextA, subscribe_contextB
        username = '******'
        self.create_user(username)
        self.modify_user(username, {"displayName": "Lionel Messi", "twitterUsername": "******"})
        context_permissions = dict(read='subscribed', write='subscribed', join='restricted', invite='restricted')
        self.create_context(create_contextA, permissions=context_permissions)
        self.modify_context(create_contextA['url'], {"twitterHashtag": "assignatura1"})
        self.subscribe_user_to_context(username, subscribe_contextA)

        self.create_context(create_contextB, permissions=context_permissions)
        self.modify_context(create_contextB['url'], {"twitterHashtag": "assignatura1"})
        self.subscribe_user_to_context(username, subscribe_contextB)

        processTweet('leomessi', 'Ehteee, acabo de batir el récor de goles en el Barça #upc #assignatura1')

        res = self.testapp.get('/people/%s/timeline' % username, "", oauth2Header(username), status=200)
        result = json.loads(res.text)
        self.assertEqual(result.get('totalItems', None), 2)
        self.assertEqual(result.get('items', None)[0].get('actor', None).get('username'), 'messi')
        self.assertEqual(result.get('items', None)[0].get('object', None).get('objectType', None), 'note')
        self.assertEqual(result.get('items', None)[0].get('contexts', None)[0], subscribe_contextB['object'])
        self.assertEqual(result.get('items', None)[1].get('actor', None).get('username'), 'messi')
        self.assertEqual(result.get('items', None)[1].get('object', None).get('objectType', None), 'note')
        self.assertEqual(result.get('items', None)[1].get('contexts', None)[0], subscribe_contextA['object'])
Example #2
0
 def run(self):
     while True:
         import time
         time.sleep(2)
         from maxrules.tasks import processTweet
         processTweet('sneridagh', u'Twitejant com un usuari de twitter assignat a un contexte')
         time.sleep(2)
         processTweet('maxupcnet', u'Twitejant amb el hashtag #upc #gsxf')
Example #3
0
 def run(self):
     while True:
         import time
         time.sleep(2)
         from maxrules.tasks import processTweet
         processTweet(
             'sneridagh',
             u'Twitejant com un usuari de twitter assignat a un contexte')
         time.sleep(2)
         processTweet('maxupcnet', u'Twitejant amb el hashtag #upc #gsxf')
Example #4
0
    def test_process_new_tweet_from_hashtag_to_unsubscribed_context(self):
        from maxrules.tasks import processTweet
        from .mockers import create_contextA
        username = '******'
        self.create_user(username)
        self.modify_user(username, {"displayName": "Lionel Messi", "twitterUsername": "******"})
        context_permissions = dict(read='subscribed', write='subscribed', join='restricted', invite='restricted')
        self.create_context(create_contextA, permissions=context_permissions)
        self.modify_context(create_contextA['url'], {"twitterHashtag": "assignatura1"})

        processTweet('leomessi', 'Ehteee, acabo de batir el récor de goles en el Barça #upc #assignatura1')

        res = self.testapp.get('/people/%s/timeline' % username, "", oauth2Header(username), status=200)
        result = json.loads(res.text)
        self.assertEqual(result.get('totalItems', None), 0)
Example #5
0
    def test_process_new_tweet_from_twitter_username(self):
        from maxrules.tasks import processTweet
        from .mockers import create_contextA, subscribe_contextA
        username = '******'
        self.create_user(username)
        context_permissions = dict(read='subscribed', write='subscribed', join='restricted', invite='restricted')
        self.create_context(create_contextA, permissions=context_permissions)
        self.modify_context(create_contextA['url'], {"twitterUsername": "******"})
        self.subscribe_user_to_context(username, subscribe_contextA)

        processTweet('maxupcnet', 'Ehteee, acabo de batir el récor de goles en el Barça.')

        res = self.testapp.get('/people/%s/timeline' % username, "", oauth2Header(username), status=200)
        result = json.loads(res.text)
        self.assertEqual(result.get('totalItems', None), 1)
        self.assertEqual(result.get('items', None)[0].get('actor', None).get('url'), subscribe_contextA['object']['url'])
        self.assertEqual(result.get('items', None)[0].get('actor', None).get('objectType'), 'context')
        self.assertEqual(result.get('items', None)[0].get('object', None).get('objectType', None), 'note')
        self.assertEqual(result.get('items', None)[0].get('contexts', None)[0], subscribe_contextA['object'])
Example #6
0
    def test_process_new_tweet_from_hashtag_different_case_in_max(self):
        """
        Test the case where we create a context with a specific case setting hashtag associated, and we try
        to match it with a tweet that is different in letter-case.
        """
        from maxrules.tasks import processTweet
        from .mockers import create_contextA, subscribe_contextA
        username = '******'
        self.create_user(username)
        self.modify_user(username, {"displayName": "Lionel Messi", "twitterUsername": "******"})
        context_permissions = dict(read='subscribed', write='subscribed', join='restricted', invite='restricted')
        self.create_context(create_contextA, permissions=context_permissions)
        self.modify_context(create_contextA['url'], {"twitterHashtag": "Assignatura1"})
        self.subscribe_user_to_context(username, subscribe_contextA)

        processTweet('leomessi', 'Ehteee, acabo de batir el récor de goles en el Barça #UPC #assignaTURA1')

        res = self.testapp.get('/people/%s/timeline' % username, "", oauth2Header(username), status=200)
        result = json.loads(res.text)
        self.assertEqual(result.get('totalItems', None), 1)
        self.assertEqual(result.get('items', None)[0].get('actor', None).get('username'), 'messi')
        self.assertEqual(result.get('items', None)[0].get('object', None).get('objectType', None), 'note')
        self.assertEqual(result.get('items', None)[0].get('contexts', None)[0], subscribe_contextA['object'])
Example #7
0
    def test_process_new_tweet_from_twitter_username_different_case_in_max(self):
        """
        Test the case where we create a user with specific letter-case-setting twitter username associated, and we try
        to match it with a tweet with username that is different in letter-case
        """
        from maxrules.tasks import processTweet
        from .mockers import create_contextA, subscribe_contextA
        username = '******'
        self.create_user(username)
        context_permissions = dict(read='subscribed', write='subscribed', join='restricted', invite='restricted')
        self.create_context(create_contextA, permissions=context_permissions)
        self.modify_context(create_contextA['url'], {"twitterUsername": "******"})
        self.subscribe_user_to_context(username, subscribe_contextA)

        processTweet('maxUpcnet', 'Ehteee, acabo de batir el récor de goles en el Barça.')

        res = self.testapp.get('/people/%s/timeline' % username, "", oauth2Header(username), status=200)
        result = json.loads(res.text)
        self.assertEqual(result.get('totalItems', None), 1)
        self.assertEqual(result.get('items', None)[0].get('actor', None).get('url'), subscribe_contextA['object']['url'])
        self.assertEqual(result.get('items', None)[0].get('actor', None).get('objectType'), 'context')
        self.assertEqual(result.get('items', None)[0].get('object', None).get('objectType', None), 'note')
        self.assertEqual(result.get('items', None)[0].get('contexts', None)[0], subscribe_contextA['object'])
Example #8
0
    def test_process_new_tweet_from_hashtag_uppercase_from_twitter(self):
        """
        Test the case where we lower the case of the hashtag to match the lowercased from uppercase,
        which whe know it's in database
        """
        from maxrules.tasks import processTweet
        from .mockers import create_contextA, subscribe_contextA
        username = '******'
        self.create_user(username)
        self.modify_user(username, {"displayName": "Lionel Messi", "twitterUsername": "******"})
        context_permissions = dict(read='subscribed', write='subscribed', join='restricted', invite='restricted')
        self.create_context(create_contextA, permissions=context_permissions)
        self.modify_context(create_contextA['url'], {"twitterHashtag": "assignatura1"})
        self.subscribe_user_to_context(username, subscribe_contextA)

        processTweet('leomessi', 'Ehteee, acabo de batir el récor de goles en el Barça #UPC #ASSIGNATURA1')

        res = self.testapp.get('/people/%s/timeline' % username, "", oauth2Header(username), status=200)
        result = json.loads(res.text)
        self.assertEqual(result.get('totalItems', None), 1)
        self.assertEqual(result.get('items', None)[0].get('actor', None).get('username'), 'messi')
        self.assertEqual(result.get('items', None)[0].get('object', None).get('objectType', None), 'note')
        self.assertEqual(result.get('items', None)[0].get('contexts', None)[0], subscribe_contextA['object'])