示例#1
0
    def test_reverse_items_relationship(self):
        order_resource = OrderResource()

        data = {
            'name': 'order1',
            'items': [
                {
                    'name': 'car',
                },
                {
                    'name': 'yacht',
                }
            ]
        }

        request = MockRequest()
        request.GET = {'format': 'json'}
        request.method = 'POST'

        request.path = reverse('api_dispatch_list',
                               kwargs={'resource_name': order_resource._meta.resource_name,
                                       'api_name': order_resource._meta.api_name})
        request.set_body(json.dumps(data))
        resp = order_resource.post_list(request)
        self.assertEqual(resp.status_code, 201)
        self.assertEqual(Order.objects.count(), 1)
        self.assertEqual(OrderItem.objects.count(), 2)
示例#2
0
    def test_reverse_items_relationship(self):
        order_resource = OrderResource()

        data = {
            'name': 'order1',
            'items': [{
                'name': 'car',
            }, {
                'name': 'yacht',
            }]
        }

        request = MockRequest()
        request.GET = {'format': 'json'}
        request.method = 'POST'

        request.path = reverse('api_dispatch_list',
                               kwargs={
                                   'resource_name':
                                   order_resource._meta.resource_name,
                                   'api_name': order_resource._meta.api_name
                               })
        request.set_body(json.dumps(data))
        resp = order_resource.post_list(request)
        self.assertEqual(resp.status_code, 201)
        self.assertEqual(Order.objects.count(), 1)
        self.assertEqual(OrderItem.objects.count(), 2)
示例#3
0
    def test_reverse_items_relationship(self):
        order_resource = OrderResource()

        data = {"name": "order1", "items": [{"name": "car"}, {"name": "yacht"}]}

        request = MockRequest()
        request.GET = {"format": "json"}
        request.method = "POST"

        request.path = reverse(
            "api_dispatch_list",
            kwargs={"resource_name": order_resource._meta.resource_name, "api_name": order_resource._meta.api_name},
        )
        request.set_body(json.dumps(data))
        resp = order_resource.post_list(request)
        self.assertEqual(resp.status_code, 201)
        self.assertEqual(Order.objects.count(), 1)
        self.assertEqual(OrderItem.objects.count(), 2)
    NoteWithUpdatableUserResource, ContactResource, ContactGroupResource


api = Api(api_name='v1')
api.register(NoteResource(), canonical=True)
api.register(NoteWithUpdatableUserResource(), canonical=True)
api.register(UserResource(), canonical=True)
api.register(CategoryResource(), canonical=True)
api.register(TagResource(), canonical=True)
api.register(TaggableResource(), canonical=True)
api.register(TaggableTagResource(), canonical=True)
api.register(ExtraDataResource(), canonical=True)
api.register(FreshNoteResource(), canonical=True)
api.register(FreshMediaBitResource(), canonical=True)
api.register(ForumResource(), canonical=True)
api.register(CompanyResource(), canonical=True)
api.register(ProductResource(), canonical=True)
api.register(AddressResource(), canonical=True)
api.register(PersonResource(), canonical=True)
api.register(DogResource(), canonical=True)
api.register(DogHouseResource(), canonical=True)
api.register(BoneResource(), canonical=True)
api.register(PostResource(), canonical=True)
api.register(LabelResource(), canonical=True)
api.register(OrderResource(), canonical=True)
api.register(OrderItemResource(), canonical=True)
api.register(ContactResource(), canonical=True)
api.register(ContactGroupResource(), canonical=True)

urlpatterns = api.urls