Exemplo n.º 1
0
    def test_build_entity(self, mock_super_build_entity):
        rb = GraphQLCustomStreamingResponseBuilder(None, None, None)
        rb._customized_entity = MagicMock()
        result = rb._build_entity('any entity')
        mock_super_build_entity.assert_called_with('any entity')
        rb._customized_entity.assert_not_called()
        self.assertEqual(result, mock_super_build_entity.return_value)

        request = {'condens': 'any condens'}
        rb = GraphQLCustomStreamingResponseBuilder(None,
                                                   None,
                                                   None,
                                                   request_args=request)
        rb._customized_entity = MagicMock()
        result = rb._build_entity('any entity')
        rb._customized_entity.assert_called_with(
            mock_super_build_entity.return_value)
        self.assertEqual(result, rb._customized_entity.return_value)

        request = {'flatten': 'true'}
        rb = GraphQLCustomStreamingResponseBuilder(None,
                                                   None,
                                                   None,
                                                   request_args=request)
        rb._customized_entity = MagicMock()
        rb._build_entity('any entity')
        rb._customized_entity.assert_called()
Exemplo n.º 2
0
    def test_flatten(self):
        entity = {
            "identificatie": "10281154",
            "status": {
                "code": 1,
                "omschrijving": "Actueel"
            }
        }
        request = {'flatten': 'true'}
        rb = GraphQLCustomStreamingResponseBuilder(None,
                                                   None,
                                                   None,
                                                   request_args=request)
        self.assertTrue(rb.has_options)
        result = rb._customized_entity(entity)
        expect = {
            'identificatie': '10281154',
            'statusCode': 1,
            'statusOmschrijving': 'Actueel'
        }
        self.assertEqual(result, expect)

        # lowercase overrides capitalisation that is used in flatten
        request = {'flatten': 'true', 'lowercase': 'true'}
        rb = GraphQLCustomStreamingResponseBuilder(None,
                                                   None,
                                                   None,
                                                   request_args=request)
        result = rb._customized_entity(entity)
        expect = {
            'identificatie': '10281154',
            'statuscode': 1,
            'statusomschrijving': 'Actueel'
        }
        self.assertEqual(result, expect)
Exemplo n.º 3
0
 def test_condens(self):
     entity = {
         'identificatie': '10281154',
         "ligtInBouwblok": {
             "edges": [{
                 "node": {
                     "identificatie": "03630012101200",
                     "volgnummer": 1
                 }
             }]
         }
     }
     request = {'condens': 'edges,node'}
     rb = GraphQLCustomStreamingResponseBuilder(None,
                                                None,
                                                None,
                                                request_args=request)
     self.assertTrue(rb.has_options)
     result = rb._customized_entity(entity)
     expect = {
         'identificatie': '10281154',
         'ligtInBouwblok': {
             'identificatie': '03630012101200',
             'volgnummer': 1
         }
     }
     self.assertEqual(result, expect)
Exemplo n.º 4
0
 def test_geojson(self):
     entity = {
         "identificatie": "10281154",
         "geometrie1": "POINT(119411.7 487201.6)",
         "geometrie2": "POINT(119411.7 487201.6)",
         "geometrie3": "POINT(119411.7 487201.6)",
         "geometrie4": None,
     }
     request = {'geojson': 'geometrie1,geometrie3,geometrie4'}
     rb = GraphQLCustomStreamingResponseBuilder(None,
                                                None,
                                                None,
                                                request_args=request)
     self.assertTrue(rb.has_options)
     result = rb._customized_entity(entity)
     expect = {
         'identificatie': '10281154',
         'geometrie1': {
             "type": "Point",
             "coordinates": [119411.7, 487201.6]
         },
         'geometrie2': 'POINT(119411.7 487201.6)',
         'geometrie3': {
             "type": "Point",
             "coordinates": [119411.7, 487201.6]
         },
         'geometrie4': None,
     }
     self.assertEqual(result, expect)