class TestAccountsSessions(unittest.TestCase):
    def setUp(self):
        self.connection, self.db = pp_tests.connect_to_mongo()

        self.account_data = {
            'email': '*****@*****.**',
            'password': '******',
            'name': 'Daniel',
            'startup': 'Payparrot',
        }
        self.account = Accounts(self.db, self.account_data)
        self.account.insert()
        
        self.account_session = AccountsSessions(self.db, {'account_id':self.account.id})
        self.account_session.insert()

    
    def tearDown(self):
        pp_tests.tear_down(self.db)
        self.connection.close()

    def test_create_session_setup_default_elements(self):
        self.assertTrue(self.account_session.expires)
        self.assertTrue(self.account_session.account_id)
        self.assertTrue(self.account_session.id)
        self.assertTrue(self.account_session.session_id)
    
    def test_get_account_from_session(self):
        account = Accounts.get_from_session(self.db, id = self.account_session.session_id)
        self.assertEqual(self.account.id, account.id)
class TestFinishPayment(unittest.TestCase):
    @classmethod
    def setUpClass(self):
        self.app = pp_tests.get_app()
        self.db = pp_tests.connect_to_mongo()
        self.account = Accounts(self.db, {
            'email': '*****@*****.**',
            'password': '******',
            'name': 'Daniel',
            'startup': 'Payparrot',
            'url': 'http://payparrot.com/',
            'callback_url': 'http://www.epistemonikos.org',
            'notification_url': 'http://www.epistemonikos.org',
        })
        self.account.insert()
        self.redirect = self.app.get('/parrots/start?external_id=1&token=%s' % self.account.credentials['public_token'])
        print "\n", self.redirect.location
        url = raw_input("Final url? ")
        query_string = urlparse(url).query
        self.finish_response = self.app.get('/parrots/finish?%s' % (query_string))

    @classmethod
    def tearDownClass(self):
        pp_tests.tear_down(self.db)

    def test_status_code(self):
        self.assertEqual(302, self.finish_response.status_int)
    
    def test_location(self):
        self.assertEqual('http://www.epistemonikos.org', self.finish_response.location)
Esempio n. 3
0
class TestStartPayment(unittest.TestCase):
    def setUp(self):
        self.app = pp_tests.get_app()
        self.db = pp_tests.connect_to_mongo()
        self.account = Accounts(self.db, {
            'email': '*****@*****.**',
            'password': '******',
            'name': 'Daniel',
            'startup': 'Payparrot',
            'url': 'http://payparrot.com/',
            'callback_url': 'http://www.epistemonikos.org',
        })
        self.account.insert()
        self.redirect = self.app.get('/parrots/start?external_id=1&token=%s' % self.account.credentials['public_token'])

        
    def tearDown(self):
        self.db.accounts.drop()
        self.db.messages.drop()
        self.db.accounts_sessions.drop()
        self.app.get('/logout')

    def test_redirect(self):
        self.assertEqual(302, self.redirect.status_int)
        self.assertEqual('https://api.twitter.com/oauth/authorize?oauth_token=', self.redirect.location[0:52])
Esempio n. 4
0
def create_account(db):
    params = request.json
    account = Accounts(db,request.json)
    account._data['password'] = sha1(account.salt+params.get('password')).hexdigest()
    account.insert()
    response.status = 201
    return {'id': str(account.id)}
Esempio n. 5
0
def callback(db):
    params = {'startup':'','name':'','email':'','password':''}
    params.update(request.forms)
    account = Accounts.findOne(db, {'email': params.get("email","")})
    status = False
    if not account:
        new_account = Accounts(db, params)
        new_account._data['password'] = sha1(new_account.salt+params.get('password')).hexdigest()
        new_account.insert()
        status = True
    params['status'] = status
    return template('signedup',params)
Esempio n. 6
0
 def test_return_json(self):
     account = Accounts(self.db, self.account_data)
     account.insert()
     expected_json = {
         "id": str(account.id),
         "email": "*****@*****.**",
         "name": "Daniel",
         "startup": "Payparrot",
         "url": "http://payparrot.com/",
         "callback_url": "http://demo.payparrot.com",
         "notification_url": "http://demo.payparrot.com/notifications",
         "notification_active": False,
         "stats": {},
     }
     received_json = account.JSON()
     self.assertEqual(expected_json, received_json)
Esempio n. 7
0
    def test_cron4_no_subscription(self):
        account = Accounts(self.db, {
            'email': '*****@*****.**',
            'password': '******',
            'name': 'Daniel',
            'startup': 'Payparrot',
            'url': 'http://payparrot.com/',
            'callback_url': 'http://www.epistemonikos.org',
            'notification_url': 'http://www.epistemonikos.org',
        })
        account.insert()
        parrot = Parrots(self.db, {
            'twitter_id': '123123123',
            'oauth_token': 'asd',
            'oauth_token_secret': 'asdf',
            'twitter_info': {},
            'payments': [],
            'twitter_info': {
                'screen_name': 'danielgua'
            }
        })
        parrot.insert()
        subscription = Subscriptions(self.db, {'account_id': account.id, 'active': False, 'parrot_id': parrot.id, 'twitter_screen_name': parrot.twitter_info.get("screen_name")})
        subscription.insert()

        last_date = datetime.now();
        next_action_date = last_date;
        next_payment = NextPayments(self.db, {
            'account_id': account.id,
            'parrot_id': parrot.id,
            'action_date': next_action_date
        });
        next_payment.insert()


        from payparrot_scripts.crons.cron4 import main as cron4
        cron4()

        message = Queue.get_message('payments')
        self.assertFalse(message)

        self.assertEqual(0, self.db.next_payments.find({'_id': next_payment.id}).count())
Esempio n. 8
0
class TestCronsIntegration(unittest.TestCase):
    @classmethod
    def setUpClass(self):
        self.app = pp_tests.get_app()
        self.connection, self.db = pp_tests.connect_to_mongo()
        self.account = Accounts(self.db, {
            'email': '*****@*****.**',
            'password': '******',
            'name': 'Daniel',
            'startup': 'Payparrot',
            'url': 'http://payparrot.com/',
            'callback_url': 'http://www.epistemonikos.org',
            'notification_url': 'http://www.epistemonikos.org',
        })
        self.account.insert()
        
        self.message = Messages(self.db, {
            'account_id': self.account.id,
            'text': 'Hola Mundo %s' % randint(0, 100000),
            'url': 'http://es.wikipedia.org/wiki/Hola_mundo',
            'status': True,
            'active': True
        })
        self.message.insert()
        
        self.redirect = self.app.get('/parrots/start?external_id=1&token=%s' % self.account.credentials['public_token'])
        print "\n", self.redirect.location
        url = raw_input("Final url? ")
        query_string = urlparse(url).query
        self.finish_response = self.app.get('/parrots/finish?%s' % (query_string))

    @classmethod
    def tearDownClass(self):
        pp_tests.tear_down(self.db, queue = True)
        self.connection.close()

    # def test_cron1(self):
    #     from payparrot_scripts.crons.cron1 import main as cron1
    #     cron1()
    #     
    #     subscription = Subscriptions.findOne(self.db, {})
    #     self.assertTrue(subscription.first_tweet)
    #     
    #     self.assertEqual(1, Queue.get_queue('payments').count())
    #     
    #     message = Queue.get_message('payments', visibility_timeout=1)
    #     self.assertEqual({
    #         'subscription_id': str(subscription.id),
    #         'account_id': str(subscription.account_id),
    #         'parrot_id': str(subscription.parrot_id)
    #     }, json.loads(message.get_body()))
    
    def test_crons(self):
        from payparrot_scripts.crons.cron1 import main as cron1
        cron1()
        
        from payparrot_scripts.crons.cron2 import main as cron2
        cron2()
        
        sleep(2)

        parrot = Parrots.findOne(self.db, {})
        
        twitter = Twitter()
        twitter.create_client(parrot.oauth_token, parrot.oauth_token_secret)
        headers, body = twitter.get("http://api.twitter.com/1/statuses/user_timeline.json?user_id=%s&include_rts=false&count=1" % parrot.twitter_info.get('screen_name'))
        json_twitter_status = json.loads(body)

        message_start = self.message.text
        received_message = json_twitter_status[0].get('text')
        self.assertEqual(self.message.text, received_message[0:len(message_start)])

        queue = Queue.get_queue('payments')
        self.assertEqual(0, queue.count())

        from payparrot_scripts.crons.cron3 import main as cron3
        cron3()

        raw_input("Check? ")

        
Esempio n. 9
0
 def test_create_credentials(self):
     account = Accounts(self.db, self.account_data)
     account.insert()
     self.assertTrue(account.credentials.get("private_token"))
     self.assertTrue(account.credentials.get("public_token"))
Esempio n. 10
0
 def test_update_document(self):
     account = Accounts(self.db, self.account_data)
     account.insert()
     account.update({"name": "Felipe"})
     self.assertEqual("Felipe", account.name)
Esempio n. 11
0
 def test_save_should_generate_an_id(self):
     account = Accounts(self.db, self.account_data)
     account.insert()
     self.assertTrue(account.id)