def setUp(self):
        request = RequestFactory().get('/')
        handler = init_handler(ModelHandler(), request)
        handler.model = User
        self.handler = handler

        mommy.make(User, 10)
Exemple #2
0
    def setUp(self):
        request = RequestFactory().delete('/')
        handler = init_handler(ModelHandler(), request)
        handler.model = LogEntry
        self.handler = handler

        self.logentries = mommy.make(LogEntry, 10)
Exemple #3
0
    def setUp(self):
        request = RequestFactory().delete('/')
        handler = init_handler(ModelHandler(), request)
        handler.model = User
        self.handler = handler

        self.user = mommy.make(User)
Exemple #4
0
    def setUp(self):
        request = RequestFactory().delete('/')
        handler = init_handler(ModelHandler(), request)
        handler.model = User
        handler.http_methods = ('PLURAL_DELETE', )
        self.handler = handler

        mommy.make(User, 10)
 def setUp(self):
     request = RequestFactory().get('/')
     handler = init_handler(ModelHandler(), request)
     handler.model = User
     handler.items_per_page = 10
     self.handler = handler
     
     mommy.make(User, 100)
    def setUp(self):
        request = RequestFactory().get('whateverpath/')

        handler = init_handler(ModelHandler(), request)
        handler.model = User
        self.handler = handler

        # Create some model instances
        users = mommy.make(User, 10)
    def setUp(self):
        request = RequestFactory().get('/')
        handler = init_handler(ModelHandler(), request)
        handler.http_methods = (
            'GET',
            'POST',
        )

        self.handler = handler
    def setUp(self):
        request = RequestFactory().put('/')
        handler = init_handler(ModelHandler(), request)
        handler.model = User
        self.handler = handler

        self.user = mommy.make(User)
        self.user.username = '******'
        self.handler.request.data = self.user
    def test_no_ordering(self):
        request = RequestFactory().get('/')
        handler = init_handler(ModelHandler(), request)
        handler.model = User

        data = User.objects.all()
        self.assertEqual(
            handler.order(data),
            data,
        )
    def setUp(self):
        request = RequestFactory().put('/')
        handler = init_handler(ModelHandler(), request)
        handler.model = User
        self.handler = handler

        self.users = mommy.make(User, 10)
        for user in self.users:
            user.username = '******' % user.id

        self.handler.request.data = self.users
    def test_modelhandler_package(self):
        settings.DEBUG = False  # No debug message will appear on response
        request = RequestFactory().get('whatever/')
        handler = ModelHandler()

        data = 'datastring'
        pagination = {}
        res = handler.package(data, pagination)
        self.assertItemsEqual(res.keys(), ('data', 'count'))
        self.assertEqual(res['data'], data)
        self.assertEqual(res['count'], 1)

        data = 125.6
        pagination = {}
        res = handler.package(data, pagination)
        self.assertItemsEqual(res.keys(), ('data', 'count'))
        self.assertEqual(res['data'], data)
        self.assertEqual(res['count'], 1)

        data = [1, 2, 3, 4, 5]
        pagination = None
        res = handler.package(data, pagination)
        self.assertItemsEqual(res.keys(), ('data', 'count'))
        self.assertEqual(res['data'], data)
        self.assertEqual(res['count'], 5)

        data = {1, 2, 3, 4, 5}
        pagination = {'key': 'value'}
        res = handler.package(data, pagination)
        self.assertItemsEqual(res.keys(), ('data', 'pagination', 'count'))
        self.assertEqual(res['data'], data)
        self.assertEqual(res['pagination'], pagination)
        self.assertEqual(res['count'], 5)

        data = {'key1': 'value1', 'key2': 'value2'}
        pagination = {}
        res = handler.package(data, pagination)
        self.assertItemsEqual(res.keys(), ('data', 'count'))
        self.assertEqual(res['data'], data)
        self.assertEqual(res['count'], 2)

        data = mommy.make(User, 10)
        pagination = {'key': 'value'}
        res = handler.package(data, pagination)
        self.assertItemsEqual(res.keys(), ('data', 'pagination', 'count'))
        self.assertEqual(res['data'], data)
        self.assertEqual(res['pagination'], pagination)
        self.assertEqual(res['count'], 10)
    def test_modelhandler_package(self):
        settings.DEBUG = False # No debug message will appear on response
        request = RequestFactory().get('whatever/')
        handler = ModelHandler()

        data = 'datastring'
        pagination = {}
        res = handler.package(data, pagination)
        self.assertItemsEqual(res.keys(), ('data', 'count'))
        self.assertEqual(res['data'], data)
        self.assertEqual(res['count'], 1)

        data = 125.6
        pagination = {}
        res = handler.package(data, pagination)
        self.assertItemsEqual(res.keys(), ('data', 'count'))
        self.assertEqual(res['data'], data)
        self.assertEqual(res['count'], 1)

        data = [1, 2, 3, 4, 5]
        pagination = None
        res = handler.package(data, pagination)
        self.assertItemsEqual(res.keys(), ('data', 'count'))
        self.assertEqual(res['data'], data)
        self.assertEqual(res['count'], 5)

        data = {1, 2, 3, 4, 5}
        pagination = {'key': 'value'}
        res = handler.package(data, pagination)
        self.assertItemsEqual(res.keys(), ('data', 'pagination', 'count'))
        self.assertEqual(res['data'], data)
        self.assertEqual(res['pagination'], pagination)
        self.assertEqual(res['count'], 5)
        
        data = {'key1': 'value1', 'key2': 'value2'}
        pagination = {}
        res = handler.package(data, pagination)
        self.assertItemsEqual(res.keys(), ('data', 'count'))
        self.assertEqual(res['data'], data)
        self.assertEqual(res['count'], 2)

        data = mommy.make(User, 10)
        pagination = {'key': 'value'}
        res = handler.package(data, pagination)
        self.assertItemsEqual(res.keys(), ('data', 'pagination', 'count'))
        self.assertEqual(res['data'], data)
        self.assertEqual(res['pagination'], pagination)
        self.assertEqual(res['count'], 10)
    def setUp(self):
        # Initialize data
        self.users = mommy.make(User, 100)
        for user in User.objects.all():
            user.first_name = ''.join(
                [random.choice(string.ascii_uppercase) for i in range(5)])
            user.email = ''.join(
                [random.choice(string.ascii_uppercase) for i in range(10)])
            user.save()

        # Initialize handler
        request = RequestFactory().get('/')
        handler = init_handler(ModelHandler(), request)
        handler.model = User
        handler.filters = (
            'filter_id',
            'filter_name',
            'filter_email',
        )

        def filter_id(data):
            ids = handler.request.GET.getlist('id')
            if ids:
                data = data.filter(id__in=ids)
            return data

        handler.filter_id = filter_id

        def filter_name(data):
            names = handler.request.GET.getlist('name')
            if names:
                data = data.filter(first_name__in=names)
            return data

        handler.filter_name = filter_name

        def filter_email(data):
            emails = handler.request.GET.getlist('email')
            if emails:
                data = data.filter(email__in=emails)
            return data

        handler.filter_email = filter_email

        self.handler = handler
    def test_order_descending(self):
        def order_data(data, order):
            " Descending order"
            if order == 'id':
                return data.order_by('-id')
            return data

        request = RequestFactory().get('/?order=id')
        handler = init_handler(ModelHandler(), request)
        handler.model = User
        handler.order_data = order_data

        data = User.objects.all()
        ordered_data = handler.order(data)

        # Check if indeed the order of ``ordered_data`` is descending.
        self.assertEqual(ordered_data[0], User.objects.get(id=100))
        self.assertEqual(ordered_data[99], User.objects.get(id=1))
    def setUp(self):
        # Create some persistent records
        # ``ContentType``
        contenttypes = mommy.make(ContentType, 10)
        # ``LogEntry``, and assign one ContentType to each (along with the LogEntry
        # records, User records were created)
        logentries = mommy.make(LogEntry, 10)
        for logentry in logentries:
            logentry.content_type = ContentType.objects.get(id=randrange(1, 11))
            logentry.save()

        # Initialize a Model Handler
        request = RequestFactory().get('/')
        handler = init_handler(ModelHandler(), request) 
        handler.model = User

        handler.content_type_template = {
            'fields': ['id', ],
            'flat': False,
        }            
        handler.logentry_template = {
            'fields': ['action_flag', 'content_type'],     
            'related': {
                'content_type': handler.content_type_template,
            }
        }
        handler.template = {
            'fields': ['id', 'username', 'first_name', 'last_name',
                       'logentry_set', 'email', 'last_login'], 
            'related': {
                'logentry_set': handler.logentry_template,
            }, 
            'exclude': ['password', 'date_joined',],
            'allow_missing': True,
        }            

        self.handler = handler
Exemple #16
0
 def setUp(self):
     request = RequestFactory().post('/')
     handler = init_handler(ModelHandler(), request)
     handler.model = User
     self.handler = handler