def setUp(self):
        mocker = requests_mock.Mocker()
        mocker.post(
            "https://login.mailchimp.com/oauth2/token",
            json={"access_token": "mailchimp", "expires_in": 0, "scope": None},
        )
        mocker.start()
        self.addCleanup(mocker.stop)

        mailchimp = OAuth2Session("someclientid", redirect_uri="https://i.b")
        self.session = mailchimp_compliance_fix(mailchimp)
    def setUp(self):
        mocker = requests_mock.Mocker()
        mocker.post(
            "https://login.mailchimp.com/oauth2/token",
            json={"access_token": "mailchimp", "expires_in": 0, "scope": None},
        )
        mocker.start()
        self.addCleanup(mocker.stop)

        mailchimp = OAuth2Session("someclientid", redirect_uri="https://i.b")
        self.session = mailchimp_compliance_fix(mailchimp)
    def test_fetch_access_token(self):
        mailchimp = OAuth2Session("foo", redirect_uri="https://i.b")
        mailchimp = mailchimp_compliance_fix(mailchimp)

        mailchimp.post = mock.MagicMock()
        response = requests.Response()
        response.status_code = 200
        response.request = mock.MagicMock()
        response._content = '{"access_token":"mailchimp", "expires_in":0, "scope":null}'.encode("UTF-8")
        mailchimp.post.return_value = response

        token = mailchimp.fetch_token(
            "https://mocked.out", client_secret="bar", authorization_response="https://i.b/?code=hello"
        )
        # Times should be close
        approx_expires_at = time.time() + 3600
        actual_expires_at = token.pop("expires_at")
        self.assertAlmostEqual(actual_expires_at, approx_expires_at, places=2)

        # Other token values exact
        self.assertEqual(token, {"access_token": "mailchimp", "expires_in": 3600})

        # And no scope at all
        self.assertFalse("scope" in token)