Пример #1
0
    def __init__(self,
                 oauth_domain,
                 username=None,
                 password=None,
                 access_token=None):
        self.domain = oauth_domain
        self.lastresponse = None
        token_url = 'https://%s/rest/login' % oauth_domain
        refresh_url = 'https://%s/rest/login/refresh' % oauth_domain

        if access_token:
            token = {'access_token': access_token, 'token_type': 'Bearer'}
        else:
            token = None

        session = OAuth2Session(client=LegacyApplicationClient('plenty-rest'),
                                auto_refresh_url=refresh_url,
                                token=token,
                                token_updater=self.token_saver)
        self.session = plentymarkets_compliance_fix(session)
        self.token = token

        if not access_token:
            self.token = self.session.fetch_token(token_url=token_url,
                                                  username=username,
                                                  password=password)
    def setUp(self):
        mocker = requests_mock.Mocker()
        mocker.post("https://shop.plentymarkets-cloud02.com",
                    json={
                        "accessToken":
                        "ecUN1r8KhJewMCdLAmpHOdZ4O0ofXKB9zf6CXK61",
                        "tokenType": "Bearer",
                        "expiresIn": 86400,
                        "refreshToken":
                        "iG2kBGIjcXaRE4xmTVUnv7xwxX7XMcWCHqJmFaSX"
                    },
                    headers={"Content-Type": "application/json"})
        mocker.start()
        self.addCleanup(mocker.stop)

        plentymarkets = OAuth2Session('foo', redirect_uri='https://i.b')
        self.session = plentymarkets_compliance_fix(plentymarkets)
    def setUp(self):
        mocker = requests_mock.Mocker()
        mocker.post(
            "https://shop.plentymarkets-cloud02.com",
            json={
                "accessToken": "ecUN1r8KhJewMCdLAmpHOdZ4O0ofXKB9zf6CXK61",
                "tokenType": "Bearer",
                "expiresIn": 86400,
                "refreshToken": "iG2kBGIjcXaRE4xmTVUnv7xwxX7XMcWCHqJmFaSX",
            },
            headers={"Content-Type": "application/json"},
        )
        mocker.start()
        self.addCleanup(mocker.stop)

        plentymarkets = OAuth2Session("someclientid", redirect_uri="https://i.b")
        self.session = plentymarkets_compliance_fix(plentymarkets)