コード例 #1
0
    def test_base_api_url_allows_trailing_slash(self):
        actual_api_url = settings.API_URL
        # set API_URL and then reload the client to generate
        # a new REQUEST_TOKEN_URL
        settings.API_URL = actual_api_url + "/"
        reload(api_client)

        username = "******"

        # mock the response, return token
        expected_token = generate_tokens()
        expected_user_data = {"pk": 1, "first_name": "My First Name", "last_name": "My last name"}

        responses.add(
            responses.POST,
            urljoin(actual_api_url, "oauth2/token/"),
            body=json.dumps(expected_token),
            status=200,
            content_type="application/json",
        )

        responses.add(
            responses.GET,
            urljoin(actual_api_url, "users/", username),
            body=json.dumps(expected_user_data),
            status=200,
            content_type="application/json",
        )

        # authenticate, should complete without error
        api_client.authenticate(username, "my-password")

        # revert changes
        settings.API_URL = actual_api_url
        reload(api_client)
コード例 #2
0
    def test_success(self):
        username = "******"

        # mock the response, return token
        expected_token = generate_tokens()
        expected_user_data = {"pk": 1, "first_name": "My First Name", "last_name": "My last name"}

        responses.add(
            responses.POST,
            urljoin(settings.API_URL, "oauth2/token"),
            body=json.dumps(expected_token),
            status=200,
            content_type="application/json",
        )

        responses.add(
            responses.GET,
            urljoin(settings.API_URL, "users/", username),
            body=json.dumps(expected_user_data),
            status=200,
            content_type="application/json",
        )

        # authenticate, should return authentication data
        data = api_client.authenticate(username, "my-password")

        self.assertEqual(data["pk"], expected_user_data.get("pk"))
        self.assertDictEqual(data["token"], expected_token)
        self.assertDictEqual(data["user_data"], expected_user_data)
    def test_success(self):
        username = '******'

        # mock the response, return token
        expected_token = generate_tokens()
        expected_user_data = {
            'pk': 1,
            'first_name': 'My First Name',
            'last_name': 'My last name',
        }

        responses.add(
            responses.POST,
            urljoin(settings.API_URL, 'oauth2/token'),
            body=json.dumps(expected_token),
            status=200,
            content_type='application/json'
        )

        responses.add(
            responses.GET,
            urljoin(settings.API_URL, 'users/', username),
            body=json.dumps(expected_user_data),
            status=200,
            content_type='application/json'
        )

        # authenticate, should return authentication data
        data = api_client.authenticate(username, 'my-password')

        self.assertEqual(data['pk'], expected_user_data.get('pk'))
        self.assertDictEqual(data['token'], expected_token)
        self.assertDictEqual(data['user_data'], expected_user_data)
    def test_base_api_url_allows_trailing_slash(self):
        actual_api_url = settings.API_URL
        # set API_URL and then reload the client to generate
        # a new REQUEST_TOKEN_URL
        settings.API_URL = actual_api_url + '/'
        reload(api_client)

        username = '******'

        # mock the response, return token
        expected_token = generate_tokens()
        expected_user_data = {
            'pk': 1,
            'first_name': 'My First Name',
            'last_name': 'My last name',
        }

        responses.add(
            responses.POST,
            urljoin(actual_api_url, 'oauth2/token/'),
            body=json.dumps(expected_token),
            status=200,
            content_type='application/json'
        )

        responses.add(
            responses.GET,
            urljoin(actual_api_url, 'users/', username),
            body=json.dumps(expected_user_data),
            status=200,
            content_type='application/json'
        )

        # authenticate, should complete without error
        api_client.authenticate(username, 'my-password')

        # revert changes
        settings.API_URL = actual_api_url
        reload(api_client)