Beispiel #1
0
def test_stringify():
    assert stringify([DemoModel,
                      DemoModelNone]) == 'demoproject.demoapp.models.DemoModel,' \
                                         'demoproject.demoapp.models.DemoModelNone'
    assert stringify(['demoproject.demoapp.models.DemoModel',
                      DemoModelNone]) == 'demoproject.demoapp.models.DemoModel,' \
                                         'demoproject.demoapp.models.DemoModelNone'
def test_stringify():
    assert stringify([DemoModel,
                      DemoModelNone]) == 'demoproject.demoapp.models.DemoModel,' \
                                         'demoproject.demoapp.models.DemoModelNone'
    assert stringify(['demoproject.demoapp.models.DemoModel',
                      DemoModelNone]) == 'demoproject.demoapp.models.DemoModel,' \
                                         'demoproject.demoapp.models.DemoModelNone'
Beispiel #3
0
def test_post_multiple(webapp):
    url = reverse('multiple')

    res = webapp.post(url, {'sender': fqn(Sender1)})
    assert res.json['sender'] == fqn(Sender1)
    assert DemoMultipleModel.objects.get(pk=res.json['id']).sender == [Sender1]

    res = webapp.post(url, {'sender': stringify([Sender1, Sender2])})
    assert res.json['sender'] == stringify([Sender1, Sender2])
    assert DemoMultipleModel.objects.get(pk=res.json['id']).sender == [Sender1, Sender2]
Beispiel #4
0
 def get_prep_value(self, value):
     if value is None:
         return None
     elif isinstance(value, (list, tuple)):
         return stringify(value)
     elif isinstance(value, six.string_types):
         return value
 def get_prep_value(self, value):
     if value is None:
         return None
     elif isinstance(value, (list, tuple)):
         return stringify(value)
     elif isinstance(value, six.string_types):
         return value
Beispiel #6
0
 def prepare_value(self, value):
     ret = value
     if isinstance(value, str):
         ret = [value]
     if isinstance(value, (list, tuple)):
         ret = stringify(value)
     if ret:
         return ret.split(',')
 def prepare_value(self, value):
     ret = value
     if isinstance(value, six.string_types):
         ret = [value]
     if isinstance(value, (list, tuple)):
         ret = stringify(value)
     if ret:
         return ret.split(',')
Beispiel #8
0
def test_get_multiple(webapp):
    x = G(DemoMultipleModel, sender=[Sender1, Sender2])
    res = webapp.get('/api/m/' + str(x.id) + '/')
    assert res.json['sender'] == stringify(x.sender)

    x = G(DemoMultipleModel, sender=[])
    res = webapp.get('/api/m/' + str(x.id) + '/')
    assert res.json['sender'] == ''

    x = G(DemoMultipleModel, sender=None)
Beispiel #9
0
 def get_prep_lookup(self):
     value = super(StrategyFieldLookupMixin, self).get_prep_lookup()
     if value is None:
         return None
     if isinstance(value, six.string_types):
         pass
     elif isinstance(value, (list, tuple)):
         value = stringify(value)
     elif isinstance(value, self.lhs.output_field.registry.klass):
         value = fqn(value)
     elif isclass(value) or isinstance(value, object):
         value = fqn(value)
     return value
 def get_prep_lookup(self):
     value = super(StrategyFieldLookupMixin, self).get_prep_lookup()
     if value is None:
         return None
     if isinstance(value, six.string_types):
         pass
     elif isinstance(value, (list, tuple)):
         value = stringify(value)
     elif isinstance(value, self.lhs.output_field.registry.klass):
         value = fqn(value)
     elif isclass(value) or isinstance(value, object):
         value = fqn(value)
     return value
Beispiel #11
0
 def to_representation(self, value):
     return stringify(value)