예제 #1
0
    def test_bytes(self):
        if six.PY3:
            item = bytes(10)
        else:
            item = bytearray(10)

        utils.clean(item)
예제 #2
0
    def test_clean(self):
        simple = {
            'decimal': Decimal('0.142857'),
            'unicode': six.u('woo'),
            'date': datetime.now(),
            'long': 200000000,
            'integer': 1,
            'float': 2.0,
            'bool': True,
            'str': 'woo',
            'none': None
        }

        complicated = {
            'exception': Exception('This should show up'),
            'timedelta': timedelta(microseconds=20),
            'list': [1, 2, 3]
        }

        combined = dict(simple.items())
        combined.update(complicated.items())

        pre_clean_keys = combined.keys()

        utils.clean(combined)
        self.assertEqual(combined.keys(), pre_clean_keys)
예제 #3
0
    def test_bytes(self):
        if six.PY3:
            item = bytes(10)
        else:
            item = bytearray(10)

        utils.clean(item)
예제 #4
0
    def test_clean(self):
        simple = {
            'decimal': Decimal('0.142857'),
            'unicode': six.u('woo'),
            'date': datetime.now(),
            'long': 200000000,
            'integer': 1,
            'float': 2.0,
            'bool': True,
            'str': 'woo',
            'none': None
        }

        complicated = {
            'exception': Exception('This should show up'),
            'timedelta': timedelta(microseconds=20),
            'list': [1, 2, 3]
        }

        combined = dict(simple.items())
        combined.update(complicated.items())

        pre_clean_keys = combined.keys()

        utils.clean(combined)
        self.assertEqual(combined.keys(), pre_clean_keys)
예제 #5
0
    def _enqueue(self, msg):
        """Push a new `msg` onto the queue, return `(success, msg)`"""
        timestamp = datetime.utcnow().replace(tzinfo=tzutc())

        require('type', msg['method'], string_types)
        require('timestamp', timestamp, datetime)

        # add common
        timestamp = guess_timezone(timestamp)
        #msg['timestamp'] = timestamp.isoformat()

        msg = clean(msg)
        self.log.debug('queueing: %s', msg)

        if self.queue.full():
            self.log.warn('salesmachine-python queue is full')
            return False, msg

        self.queue.put(msg)
        self.log.debug('enqueued ' + msg['method'] + '.')
        return True, msg
예제 #6
0
 def test_clean_fn(self):
     cleaned = utils.clean({'fn': lambda x: x, 'number': 4})
     self.assertEqual(cleaned['number'], 4)
     # TODO: fixme, different behavior on python 2 and 3
     if 'fn' in cleaned:
         self.assertEqual(cleaned['fn'], None)
예제 #7
0
 def test_clean_fn(self):
     cleaned = utils.clean({ 'fn': lambda x: x, 'number': 4 })
     self.assertEqual(cleaned['number'], 4)
     # TODO: fixme, different behavior on python 2 and 3
     if 'fn' in cleaned:
         self.assertEqual(cleaned['fn'], None)