Пример #1
0
    def check_or_create(self, token, auth_type):
        if auth_type == 'github':
            github = Github()
            user_info = github.get_user_info(token)
            user = User.objects(github_id=user_info['id']).first()

            if not user:
                user = User()
                email_github = github.get_email(token)

                user.token_github = token
                user.github = user_info['html_url']
                user.email = email_github[0]
                user.name = user_info['name']
                user.username = user_info['login']
                user.city = user_info['location']
                user.gravatar_id = user_info['gravatar_id']
                user.github_id = user_info['id']

                user.save()
                self.create_auth_session(user.id, token, auth_type)

            return self.create_auth_session(user.id, token, auth_type)
        else:
            return False
Пример #2
0
    def check_or_create(self, token, auth_type):
        if auth_type == 'github':
            github = Github()
            user_info = github.get_user_info(token)
            user = User.objects(github_id=user_info['id']).first()
            
            if not user:
                user = User()
                email_github = github.get_email(token)
                
                user.token_github = token
                user.github = user_info['html_url']
                user.email = email_github[0]
                user.name = user_info['name']
                user.username = user_info['login']
                user.city     = user_info['location']
                user.gravatar_id = user_info['gravatar_id']
                user.github_id =user_info['id']

                user.save()
                self.create_auth_session(user.id, token, auth_type)

            return self.create_auth_session(user.id, token, auth_type)
        else:
            return False
Пример #3
0
    def testUserSettingSave(self):
        with app.test_client() as c:
            with c.session_transaction() as sess:
                sess['user_id'] = self.id

            post = dict(
                username='******',
                email='*****@*****.**',
                job='Test Job 2',
                city='Test City 2',
                name='Test Name 2',
                github='Test github 2',
                twitter='Test twitter 2',
                linkedin='Test linkedin 2',
                facebook='Test facebook 2',
                googleplus='Test googleplus 2',
                foursquare='Test foursquare 2',
                personal_web='Test personal web 2',
            )
            rv = c.post('/user/settings', data=post)

            self.assertEquals(rv.status_code, 200)
            self.assertTrue('Test username 2' in rv.data)
            self.assertTrue('*****@*****.**' in rv.data)
            self.assertTrue('Test Job 2' in rv.data)
            self.assertTrue('Test City 2' in rv.data)
            self.assertTrue('Test Name 2' in rv.data)
            self.assertTrue('Test github 2' in rv.data)
            self.assertTrue('Test twitter 2' in rv.data)
            self.assertTrue('Test linkedin 2' in rv.data)
            self.assertTrue('Test facebook 2' in rv.data)
            self.assertTrue('Test googleplus 2' in rv.data)
            self.assertTrue('Test foursquare 2' in rv.data)
            self.assertTrue('Test personal web 2' in rv.data)

            user = User.objects(id=self.id).first()

            self.assertEquals(post['username'], user.username)
            self.assertEquals(post['email'], user.email)
            self.assertEquals(post['job'], user.job)
            self.assertEquals(post['city'], user.city)
            self.assertEquals(post['name'], user.name)
            self.assertEquals(post['github'], user.github)
            self.assertEquals(post['twitter'], user.twitter)
            self.assertEquals(post['linkedin'], user.linkedin)
            self.assertEquals(post['facebook'], user.facebook)
            self.assertEquals(post['googleplus'], user.googleplus)
            self.assertEquals(post['foursquare'], user.foursquare)
            self.assertEquals(post['personal_web'], user.personal_web)
Пример #4
0
 def testFoursquare(self):
     user = User.objects(id=self.id).first()
     self.assertEquals(user.foursquare, 'Test foursquare')
Пример #5
0
 def testGooglePlus(self):
     user = User.objects(id=self.id).first()
     self.assertEquals(user.googleplus, 'Test googleplus')
Пример #6
0
 def testFaceBook(self):
     user = User.objects(id=self.id).first()
     self.assertEquals(user.facebook, 'Test facebook')
Пример #7
0
 def testLinkedin(self):
     user = User.objects(id=self.id).first()
     self.assertEquals(user.linkedin, 'Test linkedin')
Пример #8
0
 def testTwitter(self):
     user = User.objects(id=self.id).first()
     self.assertEquals(user.twitter, 'Test twitter')
Пример #9
0
 def testGithub(self):
     user = User.objects(id=self.id).first()
     self.assertEquals(user.github, 'Test github')
Пример #10
0
 def testName(self):
     user = User.objects(id=self.id).first()
     self.assertEquals(user.name, 'Test Name')
Пример #11
0
 def testCity(self):
     user = User.objects(id=self.id).first()
     self.assertEquals(user.city, 'Test City')
Пример #12
0
 def testJob(self):
     user = User.objects(id=self.id).first()
     self.assertEquals(user.job, 'Test Job')
Пример #13
0
 def testGithubID(self):
     user = User.objects(id=self.id).first()
     self.assertEquals(user.github_id, 12345)
Пример #14
0
 def testGravatarID(self):
     user = User.objects(id=self.id).first()
     self.assertEquals(user.gravatar_id, 'test gravatar id')
Пример #15
0
 def testGithubToken(self):
     user = User.objects(id=self.id).first()
     self.assertEquals(user.token_github, 'test github token')
Пример #16
0
 def testPersonalWeb(self):
     user = User.objects(id=self.id).first()
     self.assertEquals(user.personal_web, 'Test personal web')