Ejemplo n.º 1
0
 def setUp(self):
     super(MobileDrivenResourceTestCase, self).setUp()
     self.factory = RequestFactory()
     self.api = Api()
     self.api.include('test', TestResource)
     self.collection_resource = [
         i._callback for i in self.api.urlpatterns if '.list' in i.name][0]
     self.single_resource = [
         i._callback for i in self.api.urlpatterns if '.detail' in i.name][0]
Ejemplo n.º 2
0
class MobileDrivenResourceTestCase( BaseTestCase ):

    def setUp(self):
        super(MobileDrivenResourceTestCase, self).setUp()
        self.factory = RequestFactory()
        self.api = Api()
        self.api.include('test', TestResource)
        self.collection_resource = [
            i._callback for i in self.api.urlpatterns if '.list' in i.name][0]
        self.single_resource = [
            i._callback for i in self.api.urlpatterns if '.detail' in i.name][0]
        
    def test_list_method(self):
        def get_content():
            request = self.factory.get('/test/')
            response = self.collection_resource(request, **{})
            assert response.status_code == 200, response.status_code
            assert "application/json" in response['Content-Type']
            content = simplejson.loads( response.content )
            assert "Objects" in content
            assert "Meta" in content
            assert "Links" in content
            return content
        
        assert len(get_content()['Links']) == 1
        self.api.include('author', AuthorResource)
        assert len(get_content()['Links']) == 2
        
    def test_detail_method(self):
        def get_content():
            request = self.factory.get('/test/1')
            response = self.single_resource(request, **{'pk':1})
            assert response.status_code == 200
            assert "application/json" in response['Content-Type']
            content = simplejson.loads( response.content )
            assert "Meta" not in content
            return content
        
        content = get_content()
        assert "Links" not in content
        assert "Object" not in content
        self.api.include('author', AuthorResource)
        content = get_content()
        assert "Links" in content
        assert len(content['Links']) == 1
Ejemplo n.º 3
0
Archivo: api.py Proyecto: laginha/yard
    def test_api_include(self):
        api = Api()
        api.include("a", BookResource)
        api.include("b", BookResourceVersions)
        assert len(api.urlpatterns) == 2 * 4

        api = Api()
        api.include("a", BookResource, name="books")
        assert len(api.urlpatterns) == 4
        viewnames = [each.name for each in api.urlpatterns]
        assert "books.detail" in viewnames
        assert "books.list" in viewnames
        assert "books.edit" in viewnames
        assert "books.new" in viewnames

        api = Api()
        api.include("b", BookResourceVersions)
        assert len(api.urlpatterns) == 4
        viewnames = [each.name for each in api.urlpatterns]
        assert "BookResourceVersions.detail" in viewnames
        assert "BookResourceVersions.list" in viewnames
        assert "BookResourceVersions.edit" in viewnames
        assert "BookResourceVersions.new" in viewnames

        api = Api(discover=True)
        api.include("a", BookResource)
        api.include("b", BookResourceVersions)
        # ToDo

        api = Api("path/")
        api.include("a", BookResource)
        api.include("b", BookResourceVersions)
        assert len(api.urlpatterns) == 2 * 4
        for path in api.urlpatterns:
            assert path._regex.startswith("path/")
Ejemplo n.º 4
0
Archivo: urls.py Proyecto: laginha/yard
from django.conf.urls import patterns, include, url
from django.conf import settings
from django.conf.urls.static import static
from yard.api import Api
from .resources import AuthorResource, BookResourceVersions

api = Api(discover=True)
api.include( 'books', BookResourceVersions )
api.include( 'authors', AuthorResource )

urlpatterns = api.urlpatterns
urlpatterns += patterns('',
    url(r'^doc/', include('yard.swagger.urls')),
)

if settings.DEBUG:
    # urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
    urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)