Пример #1
0
    def test_safe_save_to_database_single(self):
        uuid = str(uuid4())
        user = User(uuid=uuid, email='*****@*****.**')
        assert safe_save_to_database(user)

        user = User.get(uuid)
        assert user.email == '*****@*****.**'
    def test_disconnect_with_partial_pipeline(self):
        self.strategy.set_settings({
            'SOCIAL_AUTH_DISCONNECT_PIPELINE':
            ('social.pipeline.partial.save_status_to_session',
             'tests.pipeline.ask_for_password', 'tests.pipeline.set_password',
             'social.pipeline.disconnect.allowed_to_disconnect',
             'social.pipeline.disconnect.get_entries',
             'social.pipeline.disconnect.revoke_tokens',
             'social.pipeline.disconnect.disconnect')
        })
        self.do_login()
        user = User.get(self.expected_username)
        redirect = do_disconnect(self.strategy, user)

        url = self.strategy.build_absolute_uri('/password')
        expect(redirect.url).to.equal(url)
        HTTPretty.register_uri(HTTPretty.GET,
                               redirect.url,
                               status=200,
                               body='foobar')
        HTTPretty.register_uri(HTTPretty.POST, redirect.url, status=200)

        password = '******'
        requests.get(url)
        requests.post(url, data={'password': password})
        data = parse_qs(HTTPretty.last_request.body)
        expect(data['password']).to.equal(password)
        self.strategy.session_set('password', data['password'])

        redirect = do_disconnect(self.strategy, user)
        expect(len(user.social)).to.equal(0)
Пример #3
0
    def test_disconnect_with_partial_pipeline(self):
        self.strategy.set_settings({
            'SOCIAL_AUTH_DISCONNECT_PIPELINE': (
                'social.pipeline.partial.save_status_to_session',
                'tests.pipeline.ask_for_password',
                'tests.pipeline.set_password',
                'social.pipeline.disconnect.allowed_to_disconnect',
                'social.pipeline.disconnect.get_entries',
                'social.pipeline.disconnect.revoke_tokens',
                'social.pipeline.disconnect.disconnect'
            )
        })
        self.do_login()
        user = User.get(self.expected_username)
        redirect = do_disconnect(self.strategy, user)

        url = self.strategy.build_absolute_uri('/password')
        expect(redirect.url).to.equal(url)
        HTTPretty.register_uri(HTTPretty.GET, redirect.url, status=200,
                               body='foobar')
        HTTPretty.register_uri(HTTPretty.POST, redirect.url, status=200)

        password = '******'
        requests.get(url)
        requests.post(url, data={'password': password})
        data = parse_qs(HTTPretty.last_request.body)
        expect(data['password']).to.equal(password)
        self.strategy.session_set('password', data['password'])

        redirect = do_disconnect(self.strategy, user)
        expect(len(user.social)).to.equal(0)
Пример #4
0
    def test_safe_save_to_database_multi(self):
        uuid = str(uuid4())
        user = User(uuid=uuid, email='*****@*****.**')
        t2 = Table2(id=1, user_uuid=uuid)
        assert safe_save_to_database([user, t2])

        user = User.get(uuid)
        assert user.email == '*****@*****.**'
        t2 = Table2.get(1)
        assert t2.user_uuid == uuid
Пример #5
0
 def test_revoke_token(self):
     self.strategy.set_settings(
         {'SOCIAL_AUTH_GOOGLE_OAUTH2_REVOKE_TOKENS_ON_DISCONNECT': True})
     self.do_login()
     user = User.get(self.expected_username)
     user.password = '******'
     backend = self.backend
     HTTPretty.register_uri(self._method(backend.REVOKE_TOKEN_METHOD),
                            backend.REVOKE_TOKEN_URL,
                            status=200)
     do_disconnect(self.strategy, user)
Пример #6
0
    def test_replace_insert(self):
        uuid = str(uuid4())
        user = User(uuid=uuid, email='*****@*****.**')
        save_to_database(user)

        user = {'uuid': uuid, 'email': '*****@*****.**'}
        session = Session()
        session.execute(User.__table__.insert(mysql_replace_insert=True), user)
        session.commit()
        user = User.get(uuid)
        assert user.email == '*****@*****.**'
Пример #7
0
 def test_revoke_token(self):
     self.strategy.set_settings({
         'SOCIAL_AUTH_REVOKE_TOKENS_ON_DISCONNECT': True
     })
     self.do_login()
     user = User.get(self.expected_username)
     user.password = '******'
     backend = self.backend
     HTTPretty.register_uri(self._method(backend.REVOKE_TOKEN_METHOD),
                            backend.REVOKE_TOKEN_URL,
                            status=200)
     do_disconnect(self.strategy, user)
Пример #8
0
 def test_disconnect(self):
     self.do_login()
     user = User.get(self.expected_username)
     user.password = '******'
     do_disconnect(self.strategy, user)
     expect(len(user.social)).to.equal(0)
Пример #9
0
 def test_not_allowed_to_disconnect(self):
     self.do_login()
     user = User.get(self.expected_username)
     do_disconnect.when.called_with(self.strategy, user).should.throw(
         NotAllowedToDisconnect
     )