コード例 #1
0
 def test_read(self):
     """
     Test model read behaviour.
     
     .. versionadded:: v00_02_00
     .. versionchanged:: v00_08_00
         Updated find() calls due to addition of order by argument.
     .. versionchanged:: 0.11.0
         Update to use nose asserts statements.
     """
     # step 1: select an existing item
     model_orig = find(self.session, 'MockModel', [['id', 'is', 1]], [], FIND_ONE)
     model_copy = find(self.session, 'MockModel', [['id', 'is', 1]], [], FIND_ONE)
     
     # step 2: apply a change
     model_orig['field_two'] = 'two'
     model_orig.update()
     
     # step 3: verify the change is read back in
     assert_equals(model_copy['field_two'], 2)
     model_copy.read()
     assert_equals(model_copy['field_two'], 'two')
     
     # step 4: try to read a non-existent item
     model_fail = self.model
     model_fail['id'] = 5
     model_fail.read()
     
     for key in model_fail.properties.keys():
         assert_equals(model_fail[key], None)
         
     # step 5: try to read a broken item
     assert_raises(GrenadeModelReadError, self.model.read)
コード例 #2
0
 def test_update(self):
     """
     Test model update behavior.
     
     .. versionadded:: v00_02_00
     .. versionchanged:: v00_08_00
         Updated find() calls due to addition of order by argument.
     .. versionchanged:: 0.9.0
         Verify that read-only fields aren't passed in to shotgun during an update.
     .. versionchanged:: 0.11.0
         Update to use nose asserts statements.
     """
     # step 1: select an existing item
     model = find(self.session, 'MockModel', [['id', 'is', 1]], [], FIND_ONE)
     
     # step 2: apply a change
     model['field_two'] = 'two'
     result = model.update()
     
     assert_equals(len(result), 1)
     assert_true('field_two' in result)
     
     # step 3: try to update a broken item
     assert_raises(GrenadeModelUpdateError, self.model.update)
     
     # step 4: try to update a read-only item
     model = find(self.session, 'MockModel', [['id', 'is', 1]], [], FIND_ONE)
     
     model['field_two'] = 'two'
     model.properties['field_two'].is_read_only = True   # cheat
     
     result = model.update()
     assert_equals(result, [])
コード例 #3
0
    def test_update(self):
        """
        Test model update behavior.
        
        .. versionadded:: v00_02_00
        .. versionchanged:: v00_08_00
            Updated find() calls due to addition of order by argument.
        .. versionchanged:: 0.9.0
            Verify that read-only fields aren't passed in to shotgun during an update.
        .. versionchanged:: 0.11.0
            Update to use nose asserts statements.
        """
        # step 1: select an existing item
        model = find(self.session, 'MockModel', [['id', 'is', 1]], [],
                     FIND_ONE)

        # step 2: apply a change
        model['field_two'] = 'two'
        result = model.update()

        assert_equals(len(result), 1)
        assert_true('field_two' in result)

        # step 3: try to update a broken item
        assert_raises(GrenadeModelUpdateError, self.model.update)

        # step 4: try to update a read-only item
        model = find(self.session, 'MockModel', [['id', 'is', 1]], [],
                     FIND_ONE)

        model['field_two'] = 'two'
        model.properties['field_two'].is_read_only = True  # cheat

        result = model.update()
        assert_equals(result, [])
コード例 #4
0
    def test_read(self):
        """
        Test model read behaviour.
        
        .. versionadded:: v00_02_00
        .. versionchanged:: v00_08_00
            Updated find() calls due to addition of order by argument.
        .. versionchanged:: 0.11.0
            Update to use nose asserts statements.
        """
        # step 1: select an existing item
        model_orig = find(self.session, 'MockModel', [['id', 'is', 1]], [],
                          FIND_ONE)
        model_copy = find(self.session, 'MockModel', [['id', 'is', 1]], [],
                          FIND_ONE)

        # step 2: apply a change
        model_orig['field_two'] = 'two'
        model_orig.update()

        # step 3: verify the change is read back in
        assert_equals(model_copy['field_two'], 2)
        model_copy.read()
        assert_equals(model_copy['field_two'], 'two')

        # step 4: try to read a non-existent item
        model_fail = self.model
        model_fail['id'] = 5
        model_fail.read()

        for key in model_fail.properties.keys():
            assert_equals(model_fail[key], None)

        # step 5: try to read a broken item
        assert_raises(GrenadeModelReadError, self.model.read)
コード例 #5
0
    def test_find(self):
        """
        Test that the find model module method behaves correctly, in both FIND_ONE and FIND_ALL modes.
        
        .. versionadded:: v00_02_00
        .. versionchanged:: v00_08_00
            Implemented support for the optional sorting argument.
        .. versionchanged:: v00_08_03
            Implement support for the no results error checking functionality when using FIND_ONE mode.
        .. versionchanged:: 0.10.0
            Added tests for the new 'fields' key work argument.
        .. versionchanged:: 0.11.0
            Update to use nose asserts statements.
        .. versionchanged:: 1.0.0
            Update to ensure that unsupported API data types are automatically filtered out.
        """
        results = find(self.session, 'MockModel', [['id', 'is', 1]], [],
                       FIND_ONE)

        assert_not_equals(results, None)
        assert_equals(results['id'],
                      1)  # make sure we received the entity we expected
        assert_true('field_pivot' not in results.properties.keys()
                    )  # make sure unsupported data types are filtered out

        results = find(self.session, 'MockModel', [['field_one', 'is', 1]],
                       [{
                           'field_name': 'id',
                           'direction': 'desc'
                       }], FIND_ALL)

        assert_not_equals(results, [])
        assert_equals(len(results), 2)

        for result in results:
            assert_not_equals(
                result['id'],
                3)  # make sure we only received entities that match

        # verify the results were sorted as expected
        assert_equals(results[0]['id'], 2)
        assert_equals(results[1]['id'], 1)

        # check that an error is thrown when no entities for the given filters could be found
        assert_raises(GrenadeModelCreateError, find, self.session, 'MockModel',
                      [['id', 'is', 0]], [], FIND_ONE)

        results = find(self.session,
                       'MockModel', [['id', 'is', 1]],
                       order=[],
                       mode=FIND_ONE,
                       fields=["field_three"])

        assert_not_equals(results, None)
        assert_equals(results['field_three'], 3)

        assert_raises(KeyError, results.get_property, 'field_one')
コード例 #6
0
    def test_create(self):
        """
        Test model creation behaviour.
        
        .. versionadded:: v00_02_00
        .. versionchanged:: 0.9.0
            Verify that created models have all read-only fields, etc populated with
            values from Shotgun.
        .. versionchanged:: 0.9.1
            Verify that it is possible to set read-only fields on models at creation time.
        .. versionchanged:: 0.11.0
            Update to use nose asserts statements.
        .. versionchanged:: 1.1.0
            Update to confirm that never_editable fields are ignored during creation.
        """
        # step 1: create a non-existant item
        result = self.model.create()
        assert_not_equals(result['id'], None)

        # step 2: attempt to recreate an existing item
        assert_raises(GrenadeModelCreateError, self.model.create)

        # step 3: verify that all fields are populated
        model = find(self.session, 'MockModel', [['id', 'is', 1]], [],
                     FIND_ONE)
        model.properties['id'].value = None  # cheat
        model.properties['field_three'].value = None  # cheat

        model.create()  # populates read-only fields, etc from shotgun

        assert_equals(model['field_three'], 99)

        # step 4: verify that we can set a read-only field at creation time
        model = find(self.session, 'MockModel', [['id', 'is', 1]], [],
                     FIND_ONE)
        model.properties['id'].value = None
        model['field_three'] = 3

        model.create()  # sets read-only fields to specified creation value

        assert_equals(model['field_three'], 3)

        # step 5: verify that never_editable fields are ignored at creation time
        model = Model(self.session, 'Task', None,
                      self.shotgun_schema[1]['Task'])
        model['field_one'] = 1
        model['dependency_violation'] = False
        assert_true(model.properties.has_key('dependency_violation'))

        result = model.create()  # should skip dependency_violation field

        assert_not_equals(result['id'], None)
        assert_equals(result['dependency_violation'],
                      True)  # confirm we got default
コード例 #7
0
 def test_create(self):
     """
     Test model creation behaviour.
     
     .. versionadded:: v00_02_00
     .. versionchanged:: 0.9.0
         Verify that created models have all read-only fields, etc populated with
         values from Shotgun.
     .. versionchanged:: 0.9.1
         Verify that it is possible to set read-only fields on models at creation time.
     .. versionchanged:: 0.11.0
         Update to use nose asserts statements.
     .. versionchanged:: 1.1.0
         Update to confirm that never_editable fields are ignored during creation.
     """
     # step 1: create a non-existant item
     result = self.model.create()
     assert_not_equals(result['id'], None)
     
     # step 2: attempt to recreate an existing item
     assert_raises(GrenadeModelCreateError, self.model.create)
     
     # step 3: verify that all fields are populated
     model = find(self.session, 'MockModel', [['id', 'is', 1]], [], FIND_ONE)
     model.properties['id'].value = None          # cheat
     model.properties['field_three'].value = None # cheat
     
     model.create() # populates read-only fields, etc from shotgun
     
     assert_equals(model['field_three'], 99)
     
     # step 4: verify that we can set a read-only field at creation time
     model = find(self.session, 'MockModel', [['id', 'is', 1]], [], FIND_ONE)
     model.properties['id'].value = None
     model['field_three'] = 3
     
     model.create() # sets read-only fields to specified creation value
     
     assert_equals(model['field_three'], 3)
     
     # step 5: verify that never_editable fields are ignored at creation time
     model = Model(self.session, 'Task', None, self.shotgun_schema[1]['Task'])
     model['field_one'] = 1
     model['dependency_violation'] = False
     assert_true(model.properties.has_key('dependency_violation'))
     
     result = model.create() # should skip dependency_violation field
     
     assert_not_equals(result['id'], None)
     assert_equals(result['dependency_violation'], True) # confirm we got default
コード例 #8
0
 def test_delete(self):
     """
     Test model delete behavior.
     
     .. versionadded:: v00_02_00
     .. versionchanged:: v00_08_00
         Updated find() calls due to addition of order by argument.
     .. versionchanged:: 0.11.0
         Update to use nose asserts statements.
     """
     # step 1: select an existing item
     model = find(self.session, 'MockModel', [['id', 'is', 1]], [], FIND_ONE)
     
     # step 2: delete it
     result = model.delete()
     
     assert_equals(result, True)
     for key in model.properties.keys():
         assert_equals(model[key], None)
         
     # step 3: try to delete a non-existent item
     model_fail = self.model
     model_fail['id'] = 5
     result = model_fail.delete()
     
     assert_equals(result, False)
         
     # step 4: try to delete a broken item
     self.model['id'] = None
     assert_raises(GrenadeModelDeleteError, self.model.delete)
コード例 #9
0
    def test_delete(self):
        """
        Test model delete behavior.
        
        .. versionadded:: v00_02_00
        .. versionchanged:: v00_08_00
            Updated find() calls due to addition of order by argument.
        .. versionchanged:: 0.11.0
            Update to use nose asserts statements.
        """
        # step 1: select an existing item
        model = find(self.session, 'MockModel', [['id', 'is', 1]], [],
                     FIND_ONE)

        # step 2: delete it
        result = model.delete()

        assert_equals(result, True)
        for key in model.properties.keys():
            assert_equals(model[key], None)

        # step 3: try to delete a non-existent item
        model_fail = self.model
        model_fail['id'] = 5
        result = model_fail.delete()

        assert_equals(result, False)

        # step 4: try to delete a broken item
        self.model['id'] = None
        assert_raises(GrenadeModelDeleteError, self.model.delete)
コード例 #10
0
 def test_find(self):
     """
     Test that the find model module method behaves correctly, in both FIND_ONE and FIND_ALL modes.
     
     .. versionadded:: v00_02_00
     .. versionchanged:: v00_08_00
         Implemented support for the optional sorting argument.
     .. versionchanged:: v00_08_03
         Implement support for the no results error checking functionality when using FIND_ONE mode.
     .. versionchanged:: 0.10.0
         Added tests for the new 'fields' key work argument.
     .. versionchanged:: 0.11.0
         Update to use nose asserts statements.
     .. versionchanged:: 1.0.0
         Update to ensure that unsupported API data types are automatically filtered out.
     """
     results = find(self.session, 'MockModel', [['id', 'is', 1]], [], FIND_ONE)
     
     assert_not_equals(results, None)
     assert_equals(results['id'], 1)                             # make sure we received the entity we expected
     assert_true('field_pivot' not in results.properties.keys()) # make sure unsupported data types are filtered out
     
     results = find(self.session, 'MockModel', [['field_one', 'is', 1]], [{'field_name': 'id', 'direction': 'desc'}], FIND_ALL)
     
     assert_not_equals(results, [])
     assert_equals(len(results), 2)
     
     for result in results:
         assert_not_equals(result['id'], 3)    # make sure we only received entities that match
         
     # verify the results were sorted as expected
     assert_equals(results[0]['id'], 2)
     assert_equals(results[1]['id'], 1)
     
     # check that an error is thrown when no entities for the given filters could be found
     assert_raises(GrenadeModelCreateError, find, self.session, 'MockModel', [['id', 'is', 0]], [], FIND_ONE)
     
     results = find(self.session, 'MockModel', [['id', 'is', 1]], order=[], mode=FIND_ONE, fields=["field_three"])
     
     assert_not_equals(results, None)
     assert_equals(results['field_three'], 3)
     
     assert_raises(KeyError, results.get_property, 'field_one')
コード例 #11
0
    def test_set_property(self):
        """
        Test that the correct value is applied when setting a property. Explicit calls to set_property()
        as well as the __setitem__ mode are included.
        
        .. versionadded:: v00_02_00
        .. versionchanged:: v00_07_00
            Use the new property class accessors for the is_dirty field.
        .. versionchanged:: 0.9.0
            Verify that it is not possible to set the value of a read-only field.
        .. versionchanged:: 0.9.1
            Verify that it is possible to set the value of a read-only field on an uncreated model.
        .. versionchanged:: 0.11.0
            Update to use nose asserts statements.
        .. versionchanged:: 0.11.0
            Update broken identifier (use MockModel instead of Note).
        """
        # make sure we store the correct (translated) value where relevant
        self.model.set_property('field_one', 'one')
        self.model.set_property('field_three', 'three')

        assert_equals(self.model.properties['field_one'].value, 'one')
        assert_equals(self.model.properties['field_one'].get_is_dirty(), True)
        assert_equals(self.model.properties['field_three'].value, 'three')
        assert_equals(self.model.properties['field_three'].get_is_dirty(),
                      True)

        # make sure that __setitem__ mode works in the same way
        self.model['field_one'] = 1
        self.model['field_three'] = 3

        assert_equals(self.model.properties['field_one'].value, '1')
        assert_equals(self.model.properties['field_one'].get_is_dirty(), True)
        assert_equals(self.model.properties['field_three'].value, 3)
        assert_equals(self.model.properties['field_three'].get_is_dirty(),
                      True)

        # make sure we can't assign a value to a read-only property
        model = find(self.session, 'MockModel', [['id', 'is', 1]], [],
                     FIND_ONE)

        assert_raises(GrenadeModelPropertyReadOnlyError, model.set_property,
                      'field_three', 'three')

        # make sure we can force assign a value to a read-only property
        model.set_property('field_three', 'three', force=True)
        assert_equals(model.properties['field_three'].value, 'three')

        # make sure we can assign a value to a read-only property in an uncreated model
        model = ModelBuilder()(self.session, 'MockModel', None)
        model.set_property('field_three', 'three')
        assert_equals(model.properties['field_three'].value, 'three')
コード例 #12
0
 def test_set_property(self):
     """
     Test that the correct value is applied when setting a property. Explicit calls to set_property()
     as well as the __setitem__ mode are included.
     
     .. versionadded:: v00_02_00
     .. versionchanged:: v00_07_00
         Use the new property class accessors for the is_dirty field.
     .. versionchanged:: 0.9.0
         Verify that it is not possible to set the value of a read-only field.
     .. versionchanged:: 0.9.1
         Verify that it is possible to set the value of a read-only field on an uncreated model.
     .. versionchanged:: 0.11.0
         Update to use nose asserts statements.
     .. versionchanged:: 0.11.0
         Update broken identifier (use MockModel instead of Note).
     """
     # make sure we store the correct (translated) value where relevant
     self.model.set_property('field_one', 'one')
     self.model.set_property('field_three', 'three')
     
     assert_equals(self.model.properties['field_one'].value, 'one')
     assert_equals(self.model.properties['field_one'].get_is_dirty(), True)
     assert_equals(self.model.properties['field_three'].value, 'three')
     assert_equals(self.model.properties['field_three'].get_is_dirty(), True)
     
     # make sure that __setitem__ mode works in the same way
     self.model['field_one'] = 1
     self.model['field_three'] = 3
     
     assert_equals(self.model.properties['field_one'].value, '1')
     assert_equals(self.model.properties['field_one'].get_is_dirty(), True)
     assert_equals(self.model.properties['field_three'].value, 3)
     assert_equals(self.model.properties['field_three'].get_is_dirty(), True)
     
     # make sure we can't assign a value to a read-only property
     model = find(self.session, 'MockModel', [['id', 'is', 1]], [], FIND_ONE)
     
     assert_raises(GrenadeModelPropertyReadOnlyError, model.set_property, 'field_three', 'three')
     
     # make sure we can force assign a value to a read-only property
     model.set_property('field_three', 'three', force=True)
     assert_equals(model.properties['field_three'].value, 'three')
     
     # make sure we can assign a value to a read-only property in an uncreated model
     model = ModelBuilder()(self.session, 'MockModel', None)
     model.set_property('field_three', 'three')
     assert_equals(model.properties['field_three'].value,'three')
コード例 #13
0
            instance = ModelBuilder()(session, entity, translator(session),
                                      **eval(params)).create()
            print instance['id']
        except Exception, e:
            log.error(str(e))

    if command == 'read':
        try:
            log.info('Reading %s where %s\n' % (entity, params))

            arguments = eval(params)
            if not arguments.has_key('order'):
                arguments['order'] = []

            for instance in find(session, entity, arguments['filters'],
                                 arguments['order']):
                print instance
        except Exception, e:
            log.error(str(e))

    if command == 'update':
        try:
            changes = eval(params)
            id = changes.pop('id')

            log.info('Updating %s using %s\n' % (entity, params))

            instance = find(session, entity, [['id', 'is', id]], mode=FIND_ONE)
            instance.translator = translator(session)

            for key in changes.keys():