Exemplo n.º 1
0
class TestSerlializer(unittest.TestCase):
    def setUp(self):
        self.wrapper = SerializerClient()

    def test_passing_serializer_on_instatiation(self):
        wrapper = TesterClient(serializer_class=SimpleSerializer)
        serializer = wrapper._api.serializer
        self.assertTrue(isinstance(serializer, BaseSerializer))

    def test_serializer_client_adapter_has_serializer(self):
        serializer = self.wrapper._api.serializer
        self.assertTrue(isinstance(serializer, BaseSerializer))

    @responses.activate
    def test_executor_dir_returns_serializer_methods(self):
        responses.add(responses.GET,
                      self.wrapper.test().data,
                      body='{"date": "2014-11-13T14:53:18.694072+00:00"}',
                      status=200,
                      content_type='application/json')

        response = self.wrapper.test().get()

        e_dir = dir(response())

        self.assertIn('to_datetime', e_dir)
        self.assertIn('to_decimal', e_dir)
Exemplo n.º 2
0
    def test_data_serialization(self):
        wrapper = SerializerClient()

        responses.add(responses.POST,
                      self.wrapper.test().data,
                      body='{}',
                      status=200,
                      content_type='application/json')

        string_date = '2014-11-13T14:53:18.694072+00:00'
        string_decimal = '1.45'

        data = {
            'date': arrow.get(string_date).datetime,
            'decimal': Decimal(string_decimal),
        }

        wrapper.test().post(data=data)

        request_body = responses.calls[0].request.body

        self.assertEqual(json.loads(request_body), {
            'date': string_date,
            'decimal': string_decimal
        })
class TestSerlializer(unittest.TestCase):

    def setUp(self):
        self.wrapper = SerializerClient()

    def test_passing_serializer_on_instatiation(self):
        wrapper = TesterClient(serializer_class=SimpleSerializer)
        serializer = wrapper._api.serializer
        self.assertTrue(isinstance(serializer, BaseSerializer))

    def test_serializer_client_adapter_has_serializer(self):
        serializer = self.wrapper._api.serializer
        self.assertTrue(isinstance(serializer, BaseSerializer))

    @responses.activate
    def test_executor_dir_returns_serializer_methods(self):
        responses.add(responses.GET, self.wrapper.test().data,
                      body='{"date": "2014-11-13T14:53:18.694072+00:00"}',
                      status=200,
                      content_type='application/json')

        response = self.wrapper.test().get()

        e_dir = dir(response())

        self.assertIn('to_datetime', e_dir)
        self.assertIn('to_decimal', e_dir)
class TestSerlializer(unittest.TestCase):
    def setUp(self):
        self.wrapper = SerializerClient()

    def test_passing_serializer_on_instatiation(self):
        wrapper = TesterClient(serializer_class=SimpleSerializer)
        serializer = wrapper._api.serializer
        self.assertTrue(isinstance(serializer, BaseSerializer))

    def test_serializer_client_adapter_has_serializer(self):
        serializer = self.wrapper._api.serializer
        self.assertTrue(isinstance(serializer, BaseSerializer))

    @responses.activate
    def test_executor_dir_returns_serializer_methods(self):
        responses.add(
            responses.GET,
            self.wrapper.test().data,
            body='{"date": "2014-11-13T14:53:18.694072+00:00"}',
            status=200,
            content_type="application/json",
        )

        response = self.wrapper.test().get()

        e_dir = dir(response())

        self.assertIn("to_datetime", e_dir)
        self.assertIn("to_decimal", e_dir)

    @responses.activate
    def test_request_with_data_serialization(self):
        responses.add(responses.POST, self.wrapper.test().data, body="{}", status=200, content_type="application/json")

        string_date = "2014-11-13T14:53:18.694072+00:00"
        string_decimal = "1.45"

        data = {"date": arrow.get(string_date).datetime, "decimal": Decimal(string_decimal)}

        self.wrapper.test().post(data=data)

        request_body = responses.calls[0].request.body

        self.assertEqual(json.loads(request_body), {"date": string_date, "decimal": string_decimal})
Exemplo n.º 5
0
    def test_data_serialization(self):
        wrapper = SerializerClient()

        responses.add(responses.POST, self.wrapper.test().data,
                      body='{}', status=200, content_type='application/json')

        string_date = '2014-11-13T14:53:18.694072+00:00'
        string_decimal = '1.45'

        data = {
            'date': arrow.get(string_date).datetime,
            'decimal': Decimal(string_decimal),
        }

        wrapper.test().post(data=data)

        request_body = responses.calls[0].request.body

        self.assertEqual(
            json.loads(request_body),
            {'date': string_date, 'decimal': string_decimal})
Exemplo n.º 6
0
class TestDeserialization(unittest.TestCase):
    def setUp(self):
        self.wrapper = SerializerClient()

    @responses.activate
    def test_convert_to_decimal(self):
        responses.add(responses.GET,
                      self.wrapper.test().data,
                      body='{"decimal_value": "10.51"}',
                      status=200,
                      content_type='application/json')

        response = self.wrapper.test().get()
        self.assertEqual(response.decimal_value().to_decimal(),
                         Decimal('10.51'))

    @responses.activate
    def test_convert_to_datetime(self):
        responses.add(responses.GET,
                      self.wrapper.test().data,
                      body='{"date": "2014-11-13T14:53:18.694072+00:00"}',
                      status=200,
                      content_type='application/json')

        response = self.wrapper.test().get()
        date = response.date().to_datetime()
        self.assertEqual(date.year, 2014)
        self.assertEqual(date.month, 11)
        self.assertEqual(date.day, 13)
        self.assertEqual(date.hour, 14)
        self.assertEqual(date.minute, 53)
        self.assertEqual(date.second, 18)

    @responses.activate
    def test_call_non_existent_conversion(self):
        responses.add(responses.GET,
                      self.wrapper.test().data,
                      body='{"any_data": "%#ˆ$&"}',
                      status=200,
                      content_type='application/json')

        response = self.wrapper.test().get()
        with self.assertRaises(NotImplementedError):
            response.any_data().to_blablabla()

    @responses.activate
    def test_call_conversion_with_no_serializer(self):
        wrapper = TesterClient()
        responses.add(responses.GET,
                      wrapper.test().data,
                      body='{"any_data": "%#ˆ$&"}',
                      status=200,
                      content_type='application/json')

        response = wrapper.test().get()
        with self.assertRaises(NotImplementedError):
            response.any_data().to_datetime()
class TestDeserialization(unittest.TestCase):

    def setUp(self):
        self.wrapper = SerializerClient()

    @responses.activate
    def test_convert_to_decimal(self):
        responses.add(responses.GET, self.wrapper.test().data,
                      body='{"decimal_value": "10.51"}',
                      status=200,
                      content_type='application/json')

        response = self.wrapper.test().get()
        self.assertEqual(response.decimal_value().to_decimal(),
            Decimal('10.51'))

    @responses.activate
    def test_convert_to_datetime(self):
        responses.add(responses.GET, self.wrapper.test().data,
                      body='{"date": "2014-11-13T14:53:18.694072+00:00"}',
                      status=200,
                      content_type='application/json')

        response = self.wrapper.test().get()
        date = response.date().to_datetime()
        self.assertEqual(date.year, 2014)
        self.assertEqual(date.month, 11)
        self.assertEqual(date.day, 13)
        self.assertEqual(date.hour, 14)
        self.assertEqual(date.minute, 53)
        self.assertEqual(date.second, 18)

    @responses.activate
    def test_call_non_existent_conversion(self):
        responses.add(responses.GET, self.wrapper.test().data,
                      body='{"any_data": "%#ˆ$&"}',
                      status=200,
                      content_type='application/json')

        response = self.wrapper.test().get()
        with self.assertRaises(NotImplementedError):
            response.any_data().to_blablabla()

    @responses.activate
    def test_call_conversion_with_no_serializer(self):
        wrapper = TesterClient()
        responses.add(responses.GET, wrapper.test().data,
                      body='{"any_data": "%#ˆ$&"}',
                      status=200,
                      content_type='application/json')

        response = wrapper.test().get()
        with self.assertRaises(NotImplementedError):
            response.any_data().to_datetime()
Exemplo n.º 8
0
 def setUp(self):
     self.wrapper = SerializerClient()
 def setUp(self):
     self.wrapper = SerializerClient()
class TestSerlializer(unittest.TestCase):
    def setUp(self):
        self.wrapper = SerializerClient()

    def test_passing_serializer_on_instatiation(self):
        wrapper = TesterClient(serializer_class=SimpleSerializer)
        serializer = wrapper._api.serializer
        self.assertTrue(isinstance(serializer, BaseSerializer))

    @responses.activate
    def test_external_serializer_is_passed_along_clients(self):
        serializer_wrapper = TesterClient(serializer_class=SimpleSerializer)

        responses.add(responses.GET,
                      serializer_wrapper.test().data,
                      body='{"date": "2014-11-13T14:53:18.694072+00:00"}',
                      status=200,
                      content_type='application/json')

        response = serializer_wrapper.test().get()

        self.assertTrue(response._api.serializer.__class__, SimpleSerializer)

    def test_serializer_client_adapter_has_serializer(self):
        serializer = self.wrapper._api.serializer
        self.assertTrue(isinstance(serializer, BaseSerializer))

    @responses.activate
    def test_executor_dir_returns_serializer_methods(self):
        responses.add(responses.GET,
                      self.wrapper.test().data,
                      body='{"date": "2014-11-13T14:53:18.694072+00:00"}',
                      status=200,
                      content_type='application/json')

        response = self.wrapper.test().get()

        e_dir = dir(response())

        self.assertIn('to_datetime', e_dir)
        self.assertIn('to_decimal', e_dir)

    @responses.activate
    def test_request_with_data_serialization(self):
        responses.add(responses.POST,
                      self.wrapper.test().data,
                      body='{}',
                      status=200,
                      content_type='application/json')

        string_date = '2014-11-13T14:53:18.694072+00:00'
        string_decimal = '1.45'

        data = {
            'date': arrow.get(string_date).datetime,
            'decimal': Decimal(string_decimal),
        }

        self.wrapper.test().post(data=data)

        request_body = responses.calls[0].request.body

        self.assertEqual(json.loads(request_body), {
            'date': string_date,
            'decimal': string_decimal
        })