示例#1
0
 def test_read_pid_bogus_pidfile(self):
     with mock.open() as s:
         s.write('eighteensixteen\n')
         s.seek(0)
         p = Pidfile('/var/pid')
         with pytest.raises(ValueError):
             p.read_pid()
示例#2
0
 def test_read_pid_raises_IOError(self):
     exc = IOError()
     exc.errno = errno.EAGAIN
     with mock.open(side_effect=exc):
         p = Pidfile('/var/pid')
         with pytest.raises(IOError):
             p.read_pid()
示例#3
0
 def test_read_pid_partially_written(self):
     with mock.open() as s:
         s.write('1816')
         s.seek(0)
         p = Pidfile('/var/pid')
         with pytest.raises(ValueError):
             p.read_pid()
示例#4
0
    def test_init(self, Certificate, glob, isdir):
        cert = Certificate.return_value = Mock()
        cert.has_expired.return_value = False
        isdir.return_value = True
        glob.return_value = ['foo.cert']
        with mock.open():
            cert.get_id.return_value = 1

            path = os.path.join('var', 'certs')
            x = FSCertStore(path)
            assert 1 in x._certs
            glob.assert_called_with(os.path.join(path, '*'))

            # they both end up with the same id
            glob.return_value = ['foo.cert', 'bar.cert']
            with pytest.raises(SecurityError):
                x = FSCertStore(path)
            glob.return_value = ['foo.cert']

            cert.has_expired.return_value = True
            with pytest.raises(SecurityError):
                x = FSCertStore(path)

            isdir.return_value = False
            with pytest.raises(SecurityError):
                x = FSCertStore(path)
示例#5
0
    def test_setup_registry_complete(self, dis, reg, key='KEY', cert='CERT'):
        calls = [0]

        def effect(*args):
            try:
                m = Mock()
                m.read.return_value = 'B' if calls[0] else 'A'
                return m
            finally:
                calls[0] += 1

        self.app.conf.task_serializer = 'auth'
        with mock.open(side_effect=effect):
            with patch('celery.security.registry') as registry:
                store = Mock()
                self.app.setup_security(['json'], key, cert, store)
                dis.assert_called_with(['json'])
                reg.assert_called_with('A', 'B', store, 'sha1', 'json')
                registry._set_default_serializer.assert_called_with('auth')
示例#6
0
 def test_read_pid_raises_ENOENT(self):
     exc = IOError()
     exc.errno = errno.ENOENT
     with mock.open(side_effect=exc):
         p = Pidfile('/var/pid')
         assert p.read_pid() is None
示例#7
0
 def test_read_pid(self):
     with mock.open() as s:
         s.write('1816\n')
         s.seek(0)
         p = Pidfile('/var/pid')
         assert p.read_pid() == 1816