Ejemplo n.º 1
0
    def test_new_entity(self):
        uuid = '3d46cd74-a3af-4afd-af94-512b5cee1ef0'

        product = Product()
        product.id = uuid
        product.name = u'Defender'
        product.category = u'Cars'
        product.price = 40000.00

        state = EntityState(product)

        data = dict(state.data_for_insert())

        assert data['ProductID'] == uuid
        assert data['ProductName'] == 'Defender'
        assert data['Category'] == 'Cars'
        assert data['Price'] == 40000.00

        assert state.dirty == []

        product.name = 'Toyota Carola'
        product.price = 32500.00

        data = dict(state.data_for_update())

        assert data['ProductName'] == 'Toyota Carola'
        assert data['Category'] == 'Cars'
        assert data['Price'] == 32500.00
Ejemplo n.º 2
0
    def test_create_with_primary_key(self):
        # Post call ###########################################################
        def request_callback(request):
            payload = json.loads(request.body)
            self.assertEqual(payload.get('ProductID'),
                             55,
                             msg='Did not receive ProductID')
            resp_body = payload
            headers = {}
            return requests.codes.created, headers, json.dumps(resp_body)

        new_product = Product()
        new_product.id = 55
        new_product.name = u'New Test Product'
        new_product.category = u'Category #1'
        new_product.price = 34.5

        with responses.RequestsMock() as rsps:
            rsps.add_callback(
                rsps.POST,
                Product.__odata_url__(),
                callback=request_callback,
                content_type='application/json',
            )

            Service.save(new_product)

        assert new_product.id is not None, 'Product.id is not set'
Ejemplo n.º 3
0
    def test_call_bound_action_on_instance(self):
        test_product = Product()
        test_product.name = 'TestProduct'
        test_product.id = 1234
        test_product.price = decimal.Decimal('20.0')

        # shortcut for saving the entity
        test_product.__odata__.persisted = True

        with responses.RequestsMock() as rsps:
            rsps.add(
                rsps.POST,
                test_product.__odata__.instance_url + '/ODataTest.DemoAction',
            )
            result = test_product.DemoAction()
        self.assertIsNone(result)