Ejemplo n.º 1
0
    def teardown_method(self, testMethod):
        '''
            teardown_method - Called after every method.

                If self.model is set, will delete all objects relating to that model. To retain objects for debugging, set TestIRField.KEEP_DATA to True.
        '''
        setDefaultIREncoding(self.origIREncoding) # Revert back to utf-8 encoding

        if self.model and self.KEEP_DATA is False:
            self.model.deleter.destroyModel()
Ejemplo n.º 2
0
    def teardown_method(self, testMethod):
        '''
            teardown_method - Called after every method.

                If self.model is set, will delete all objects relating to that model. To retain objects for debugging, set TestIRField.KEEP_DATA to True.
        '''
        if self.model and self.KEEP_DATA is False:
            self.model.deleter.destroyModel()

        # Reset encoding back to original, some tests may change it.
        setDefaultIREncoding(self.defaultIREncoding)
Ejemplo n.º 3
0
    def setup_class(self):

        self.origIREncoding = getDefaultIREncoding()
        setDefaultIREncoding('ascii') # Make sure IRField stuff would normally fail with utf-8 specific codes

        self.prettyPicturesUtf8 = b' \xe2\x9c\x8f \xe2\x9c\x90 \xe2\x9c\x91 \xe2\x9c\x92 \xe2\x9c\x93 \xe2\x9c\x94 \xe2\x9c\x95 \xe2\x9c\x96 \xe2\x9c\x97 \xe2\x9c\x98 \xe2\x9c\x99 \xe2\x9c\x9a \xe2\x9c\x9b \xe2\x9c\x9c \xe2\x9c\x9d \xe2\x9c\x9e \xe2\x9c\x9f \xe2\x9c\xa0 \xe2\x9c\xa1 \xe2\x9c\xa2 \xe2\x9c\xa3 \xe2\x9c\xa4 \xe2\x9c\xa5 \xe2\x9c\xa6 \xe2\x9c\xa7 \xe2\x9c\xa9 \xe2\x9c\xaa \xe2\x9c\xab '

        # Note - just use the bytes value and decode, rather than rely on the syntax parser to do it properly (python2 has issues)

        self.utf16DataBytes = b'\xff\xfe\x01\xd8\x0f\xdc\x01\xd8-\xdc\x01\xd8;\xdc\x01\xd8+\xdc'
        self.utf16Data = self.utf16DataBytes.decode('utf-16')

        self.utf16Data2Bytes = b'\xff\xfe\x01\xd8\x88\xdc\x01\xd8\x9d\xdc\x01\xd8\x91\xdc\x01\xd8\x9b\xdc\x01\xd8\x90\xdc\x01\xd8\x98\xdc\x01\xd8\x95\xdc\x01\xd8\x96\xdc'
        self.utf16Data2 = self.utf16Data2Bytes.decode('utf-16')
Ejemplo n.º 4
0
    def setup_method(self, testMethod):
        '''
            setup_method - Called before every method. Should set "self.model" to the model needed for the test.
  
            @param testMethod - Instance method of test about to be called.
        '''
        self.model = None

        if testMethod == self.test_base64AndUnicode:
            setDefaultIREncoding(
                'ascii'
            )  # Ensure we are using the "encoding" value provided in the field

            class Model_Base64Unicode(IndexedRedisModel):

                FIELDS = [
                    IRField('name'),
                    IRFieldChain('value', [
                        IRUnicodeField(encoding='utf-8'),
                        IRBase64Field(encoding='utf-8')
                    ],
                                 defaultValue=irNull),
                    IRFieldChain('value2', [
                        IRUnicodeField(encoding='utf-8'),
                        IRBase64Field(encoding='utf-8')
                    ],
                                 defaultValue='qqz'),
                ]

                INDEXED_FIELDS = ['name']

                KEY_NAME = 'TestIRFieldChain__ModelBase64Unicode'

            self.model = Model_Base64Unicode
        elif testMethod == self.test_utf16Compression:
            setDefaultIREncoding(
                'ascii'
            )  # Ensure we are using the "encoding" value provided in the field

            class Model_Utf16Compression(IndexedRedisModel):

                FIELDS = [
                    IRField('name'),
                    IRFieldChain('value', [
                        IRUnicodeField(encoding='utf-16'),
                        IRCompressedField()
                    ]),
                ]

                INDEXED_FIELDS = ['name']

                KEY_NAME = 'TestIRFieldChain__Utf16Compression'

            self.model = Model_Utf16Compression

        elif testMethod == self.test_compressPickle:

            class Model_CompressPickle(IndexedRedisModel):

                FIELDS = [
                    IRField('name'),
                    IRFieldChain(
                        'value',
                        [IRPickleField(), IRCompressedField()]),
                    IRFieldChain(
                        'value2',
                        [IRPickleField(), IRCompressedField()],
                        defaultValue=['a', 'b', 'c'])
                ]

                INDEXED_FIELDS = ['name']

                KEY_NAME = 'TestIRFieldChain__ModelCompressPickle'

            self.model = Model_CompressPickle
        elif testMethod == self.test_intBase64:

            class Model_IntBase64(IndexedRedisModel):

                FIELDS = [
                    IRField('name'),
                    IRFieldChain('value',
                                 [IRField(valueType=int), IRBase64Field]),
                    IRFieldChain('value2',
                                 [IRField(valueType=int), IRBase64Field],
                                 defaultValue=-1)
                ]

                INDEXED_FIELDS = ['name']

                KEY_NAME = 'TestIRFieldChain__IntBase64'

            self.model = Model_IntBase64
        elif testMethod == self.test_index:

            class Model_ChainIndex(IndexedRedisModel):

                FIELDS = [
                    IRField('name'),
                    IRFieldChain('value',
                                 [IRField(valueType=str),
                                  IRBase64Field()]),
                ]

                INDEXED_FIELDS = ['name', 'value']

                KEY_NAME = 'TestIRFieldChain__ModelChainIndex'

            self.model = Model_ChainIndex

        # If KEEP_DATA is False (debug flag), then delete all objects before so prior test doesn't interfere
        if self.KEEP_DATA is False and self.model:
            self.model.deleter.destroyModel()
Ejemplo n.º 5
0
 def teardown_class(self):
     
     setDefaultIREncoding(self.origIREncoding)