<commit_before>import stripe
from stripe.test.helper import StripeApiTestCase


class ListObjectTests(StripeApiTestCase):

    def setUp(self):
        super(ListObjectTests, self).setUp()

        self.lo = stripe.resource.ListObject.construct_from({
            'id': 'me',
            'url': '/my/path',
            'data': ['foo'],
        }, 'mykey')

        self.mock_response([{
            'object': 'charge',
            'foo': 'bar',
        }])

    def assertResponse(self, res):
        self.assertTrue(isinstance(res[0], stripe.Charge))
        self.assertEqual('bar', res[0].foo)

    def test_for_loop(self):
        seen = []

        for item in self.lo:
            seen.append(item)

        self.assertEqual(['foo'], seen)

    def test_all(self):
        res = self.lo.all(myparam='you')

        self.requestor_mock.request.assert_called_with(
            'get', '/my/path', {'myparam': 'you'}, None)

        self.assertResponse(res)

    def test_create(self):
        res = self.lo.create(myparam='eter')

        self.requestor_mock.request.assert_called_with(
            'post', '/my/path', {'myparam': 'eter'}, None)

        self.assertResponse(res)

    def test_retrieve(self):
        res = self.lo.retrieve('myid', myparam='cow')

        self.requestor_mock.request.assert_called_with(
            'get', '/my/path/myid', {'myparam': 'cow'}, None)

        self.assertResponse(res)


class AutoPagingTests(StripeApiTestCase):

    def test_iter_one_page(self):
        lo = stripe.resource.ListObject.construct_from({
            'object': 'list',
            'url': '/my/path',
            'data': [{'id': 'foo'}],
        }, 'mykey')

        self.requestor_mock.request.assert_not_called()

        seen = [item['id'] for item in lo.paging_iter()]

        self.assertEqual(['foo'], seen)

    def test_iter_two_pages(self):
        lo = stripe.resource.ListObject.construct_from({
            'object': 'list',
            'url': '/my/path',
            'has_more': True,
            'data': [{'id': 'foo'}],
        }, 'mykey')

        self.mock_response({
            'object': 'list',
            'data': [{'id': 'bar'}],
            'url': '/my/path',
            'has_more': False,
        })

        seen = [item['id'] for item in lo.paging_iter()]

        self.requestor_mock.request.assert_called_with(
            'get', '/my/path', {'starting_after': 'foo'}, None)

        self.assertEqual(['foo', 'bar'], seen)<commit_msg>Add tests for class methods<commit_after>import stripe
from stripe.test.helper import StripeApiTestCase


class ListObjectTests(StripeApiTestCase):

    def setUp(self):
        super(ListObjectTests, self).setUp()

        self.lo = stripe.resource.ListObject.construct_from({
            'id': 'me',
            'url': '/my/path',
            'data': ['foo'],
        }, 'mykey')

        self.mock_response([{
            'object': 'charge',
            'foo': 'bar',
        }])

    def assertResponse(self, res):
        self.assertTrue(isinstance(res[0], stripe.Charge))
        self.assertEqual('bar', res[0].foo)

    def test_for_loop(self):
        seen = []

        for item in self.lo:
            seen.append(item)

        self.assertEqual(['foo'], seen)

    def test_all(self):
        res = self.lo.all(myparam='you')

        self.requestor_mock.request.assert_called_with(
            'get', '/my/path', {'myparam': 'you'}, None)

        self.assertResponse(res)

    def test_create(self):
        res = self.lo.create(myparam='eter')

        self.requestor_mock.request.assert_called_with(
            'post', '/my/path', {'myparam': 'eter'}, None)

        self.assertResponse(res)

    def test_retrieve(self):
        res = self.lo.retrieve('myid', myparam='cow')

        self.requestor_mock.request.assert_called_with(
            'get', '/my/path/myid', {'myparam': 'cow'}, None)

        self.assertResponse(res)


class AutoPagingTests(StripeApiTestCase):

    def test_iter_one_page(self):
        lo = stripe.resource.ListObject.construct_from({
            'object': 'list',
            'url': '/my/path',
            'data': [{'id': 'foo'}],
        }, 'mykey')

        self.requestor_mock.request.assert_not_called()

        seen = [item['id'] for item in lo.paging_iter()]

        self.assertEqual(['foo'], seen)

    def test_iter_two_pages(self):
        lo = stripe.resource.ListObject.construct_from({
            'object': 'list',
            'url': '/my/path',
            'has_more': True,
            'data': [{'id': 'foo'}],
        }, 'mykey')

        self.mock_response({
            'object': 'list',
            'data': [{'id': 'bar'}],
            'url': '/my/path',
            'has_more': False,
        })

        seen = [item['id'] for item in lo.paging_iter()]

        self.requestor_mock.request.assert_called_with(
            'get', '/my/path', {'starting_after': 'foo'}, None)

        self.assertEqual(['foo', 'bar'], seen)

    def test_class_method_two_pages(self):
        self.mock_response({
            'object': 'list',
            'data': [{'id': 'bar'}],
            'url': '/v1/charges',
            'has_more': False,
        })

        seen = [item['id'] for item in stripe.Charge.paging_iter(limit=25)]

        self.requestor_mock.request.assert_called_with(
            'get', '/v1/charges', {'limit': 25})

        self.assertEqual(['bar'], seen)
{'fraction_non_alphanumeric': 0.16580406654343807, 'fraction_numerical': 0.0018484288354898336, 'mean_word_length': 2.1587857559836543, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '240037', 'n_tokens_mistral': 1733, 'n_tokens_neox': 1663, 'n_words': 306}