Beispiel #1
0
 def test_read_pid_bogus_pidfile(self):
     with conftest.open() as s:
         s.write('eighteensixteen\n')
         s.seek(0)
         p = Pidfile('/var/pid')
         with pytest.raises(ValueError):
             p.read_pid()
Beispiel #2
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 conftest.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)
Beispiel #3
0
 def test_read_pid_raises_IOError(self):
     exc = IOError()
     exc.errno = errno.EAGAIN
     with conftest.open(side_effect=exc):
         p = Pidfile('/var/pid')
         with pytest.raises(IOError):
             p.read_pid()
Beispiel #4
0
 def test_read_pid_partially_written(self):
     with conftest.open() as s:
         s.write('1816')
         s.seek(0)
         p = Pidfile('/var/pid')
         with pytest.raises(ValueError):
             p.read_pid()
Beispiel #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'
        self.app.conf.accept_content = ['auth']
        with conftest.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, 'sha256', 'json')
                registry._set_default_serializer.assert_called_with('auth')
Beispiel #6
0
 def test_read_pid_raises_ENOENT(self):
     exc = IOError()
     exc.errno = errno.ENOENT
     with conftest.open(side_effect=exc):
         p = Pidfile('/var/pid')
         assert p.read_pid() is None
Beispiel #7
0
 def test_read_pid(self):
     with conftest.open() as s:
         s.write('1816\n')
         s.seek(0)
         p = Pidfile('/var/pid')
         assert p.read_pid() == 1816