Exemplo n.º 1
0
    def setUp(self):
        super().setUp()
        set_current_instance(self.instance)
        schema = [
            {
                'name': 'name',
                'type': 'string'
            },
            {
                'name': 'ref',
                'type': 'reference',
                'target': 'self'
            },
            {
                'name': 'user',
                'type': 'reference',
                'target': 'user'
            },
        ]
        self.klass = G(Klass, schema=schema, name='test', description='test')

        DataObject.load_klass(self.klass)
        self.object = G(DataObject, _klass=self.klass, name='a')

        self.user = G(User)
        DataObject.load_klass(self.klass)
        self.object_2 = G(DataObject,
                          _klass=self.klass,
                          name='b',
                          user=self.user.pk,
                          ref=self.object.pk)

        self.hla = G(DataObjectHighLevelApi, klass=self.klass)
        self.endpoint_url = reverse('v2:hla-objects-endpoint',
                                    args=[self.instance.name, self.hla.name])
Exemplo n.º 2
0
 def __init__(self, *args, **kwargs):
     # Skip loading cache during schema generation
     if 'context' in kwargs and kwargs['context'].get(
             'include_dynamic_fields', True):
         user_profile_klass = Klass.get_user_profile()
         DataObject.load_klass(user_profile_klass)
     super().__init__(*args, **kwargs)
def loaded_klass(klass):
    old_klass = getattr(DataObject, 'loaded_klass', None)
    DataObject.load_klass(klass)
    try:
        yield
    finally:
        if old_klass:
            DataObject.load_klass(old_klass)
Exemplo n.º 4
0
    def setUp(self):
        super().setUp()
        set_current_instance(self.instance)
        schema = [
            {
                'name': 'name',
                'type': 'string',
                'order_index': True,
                'filter_index': True
            },
            {
                'name': 'field2',
                'type': 'string',
                'order_index': True,
                'filter_index': True
            },
            {
                'name': 'field3',
                'type': 'string',
                'order_index': True,
                'filter_index': True
            },
            {
                'name': 'ref',
                'type': 'reference',
                'target': 'self'
            },
            {
                'name': 'user',
                'type': 'reference',
                'target': 'user'
            },
        ]
        self.klass = G(Klass, schema=schema, name='test', description='test')

        DataObject.load_klass(self.klass)
        self.object = G(DataObject,
                        _klass=self.klass,
                        name='a',
                        field2='b',
                        field3='c')

        self.user = G(User)
        DataObject.load_klass(self.klass)
        self.object = G(DataObject,
                        _klass=self.klass,
                        name='b',
                        field2='a',
                        field3='d',
                        ref=self.object.pk,
                        user=self.user.pk)

        self.hla = G(DataObjectHighLevelApi, klass=self.klass)
        self.get_url = reverse('v1:hla-objects-get',
                               args=[self.instance.name, self.hla.name])
        self.list_url = reverse('v1:hla-objects-list',
                                args=[self.instance.name])
Exemplo n.º 5
0
    def setUp(self):
        super().setUp()
        self.url = reverse(self.url_name, args=(self.instance.name, ))

        set_current_instance(self.instance)
        user_profile = Klass.get_user_profile()
        user_profile.schema = [{
            'name': 'int',
            'type': 'integer',
            'filter_index': True
        }]
        user_profile.save()

        # Add one random dataobject to make ids not in line with users
        G(DataObject)

        DataObject.load_klass(user_profile)
        self.user1 = User.objects.create(username='******',
                                         password='******',
                                         profile_data={'int': 100})
        self.user2 = User.objects.create(username='******',
                                         password='******',
                                         profile_data={'int': 150})
Exemplo n.º 6
0
    def test_updating_with_profile(self):
        profile_date = '2015-01-01T12:00:00.000000Z'
        data = {
            'username': '******',
            'password': '******',
            'profile': {
                'datetime': profile_date
            }
        }

        response = self.client.put(self.url, data)
        self.assertEqual(response.status_code, status.HTTP_200_OK)

        user = User.objects.first()
        self.assertEqual(user.username, data['username'])
        self.assertTrue(user.check_password(data['password']))

        # Load bogus class to make sure correct one is always reloaded (test for regression)
        DataObject.load_klass(G(Klass))
        response = self.client.get(self.url)
        self.assertEqual(response.data['profile']['datetime'], {
            'type': 'datetime',
            'value': profile_date
        })
Exemplo n.º 7
0
 def initial(self, request, *args, **kwargs):
     initial = super().initial(request, *args, **kwargs)
     self.klass = Klass.get_user_profile()
     DataObject.load_klass(self.klass)
     return initial