Exemplo n.º 1
0
    def test_get_lookup_value_returns_tuple_for_objects_single_pk(self):
        instance = HyperlinkedRelatedField(view_name='user-detail')
        session = SESSION()

        user = session.query(self.TestHyperlinkedRelatedFieldUserModel) \
                      .filter_by(name='admin').first()
        self.assertEqual(instance.get_lookup_value(user), (user.id, ))

        session.close()
Exemplo n.º 2
0
    def test_is_saved_in_database_returs_true(self):
        instance = HyperlinkedRelatedField(view_name='user-detail')
        session = SESSION()

        user = session.query(self.TestHyperlinkedRelatedFieldUserModel) \
                      .filter_by(name='admin').first()
        self.assertTrue(instance.is_saved_in_database(user))

        session.close()
Exemplo n.º 3
0
    def test_is_saved_in_database_returs_false_for_pending_object(self):
        instance = HyperlinkedRelatedField(view_name='user-detail')
        session = SESSION()

        user = self.TestHyperlinkedRelatedFieldUserModel(name='test_admin')
        session.add(user)
        self.assertFalse(instance.is_saved_in_database(user))

        session.close()
Exemplo n.º 4
0
    def test_get_lookup_value_returns_tuple_for_objects_composite_pk(self):
        instance = HyperlinkedRelatedField(view_name='user-detail')
        session = SESSION()

        user = session\
            .query(self.TestHyperlinkedRelatedFieldCompositePkModel) \
            .filter_by(id=1, name='test_user').first()
        self.assertEqual(set(instance.get_lookup_value(user)),
                         {user.id, user.name})

        session.close()
Exemplo n.º 5
0
    def test_get_object_returns_object_from_database(self):
        session = SESSION()
        queryset = session.query(self.TestHyperlinkedRelatedFieldUserModel)
        instance = HyperlinkedRelatedField(view_name='user-detail',
                                           queryset=queryset)

        user = session.query(self.TestHyperlinkedRelatedFieldUserModel) \
            .filter_by(name='admin').first()

        obj = instance.get_object('user-detail', [], {'id': user.id})
        self.assertIsInstance(obj, self.TestHyperlinkedRelatedFieldUserModel)
        self.assertEqual(obj.id, user.id)

        session.close()
Exemplo n.º 6
0
    def test_get_object_raises_improperly_configured_exception(self):
        session = SESSION()
        queryset = session.query(self.TestHyperlinkedRelatedFieldUserModel)
        instance = HyperlinkedRelatedField(view_name='user-detail',
                                           queryset=queryset)

        self.assertRaises(ImproperlyConfigured, instance.get_object,
                          'user-detail', [], {})

        session.close()
Exemplo n.º 7
0
    def test_get_object_raises_validation_error_for_object_not_found(self):
        session = SESSION()
        queryset = session.query(self.TestHyperlinkedRelatedFieldUserModel)
        instance = HyperlinkedRelatedField(view_name='user-detail',
                                           queryset=queryset)

        self.assertRaises(ValidationError, instance.get_object, 'user-detail',
                          [], {'id': -1})

        session.close()
Exemplo n.º 8
0
    def test_is_saved_in_database_returs_false_for_transient_object(self):
        instance = HyperlinkedRelatedField(view_name='user-detail')

        user = self.TestHyperlinkedRelatedFieldUserModel(name='test_admin')
        self.assertFalse(instance.is_saved_in_database(user))
Exemplo n.º 9
0
 def test_use_pk_only_optimization_returns_true(self):
     instance = HyperlinkedRelatedField(view_name='user-detail')
     self.assertTrue(instance.use_pk_only_optimization())