Exemple #1
0
    def testPreserveThree(self):
        n = ircdb.IrcNetwork()
        n.addStsPolicy('foo', 123, 'sts1')
        self.networks.setNetwork('foonet', n)

        n = ircdb.IrcNetwork()
        n.addStsPolicy('bar', 456, 'sts2')
        self.networks.setNetwork('barnet', n)

        n = ircdb.IrcNetwork()
        n.addStsPolicy('baz', 789, 'sts3')
        self.networks.setNetwork('baznet', n)

        fd = io.StringIO()
        fd.close = lambda: None
        self.networks.filename = 'blah'
        original_Atomicfile = utils.file.AtomicFile
        with unittest.mock.patch('supybot.utils.file.AtomicFile',
                                 return_value=fd):
            self.networks.flush()

        fd.seek(0)
        self.assertEqual(
            fd.getvalue(), 'network barnet\n'
            '  stsPolicy bar 456 sts2\n'
            '\n'
            'network baznet\n'
            '  stsPolicy baz 789 sts3\n'
            '\n'
            'network foonet\n'
            '  stsPolicy foo 123 sts1\n'
            '\n')
Exemple #2
0
    def testPreserveOne(self):
        n = ircdb.IrcNetwork()
        n.addStsPolicy('foo', 123, 'sts1')
        n.addStsPolicy('bar', 456, 'sts2')
        n.addDisconnection('foo')
        n.addDisconnection('baz')
        disconnect_time_foo = n.lastDisconnectTimes['foo']
        disconnect_time_baz = n.lastDisconnectTimes['baz']
        self.networks.setNetwork('foonet', n)

        fd = io.StringIO()
        fd.close = lambda: None
        self.networks.filename = 'blah'
        original_Atomicfile = utils.file.AtomicFile
        with unittest.mock.patch('supybot.utils.file.AtomicFile',
                                 return_value=fd):
            self.networks.flush()

        lines = fd.getvalue().split('\n')
        self.assertEqual(lines.pop(0), 'network foonet')
        self.assertCountEqual(lines, [
            '  stsPolicy foo 123 sts1',
            '  stsPolicy bar 456 sts2',
            '  lastDisconnectTime foo %d' % disconnect_time_foo,
            '  lastDisconnectTime baz %d' % disconnect_time_baz,
            '',
            '',
        ])
Exemple #3
0
 def testStsPolicy(self):
     n = ircdb.IrcNetwork()
     n.addStsPolicy('foo', 123, 'bar')
     n.addStsPolicy('baz', 456, 'qux')
     self.assertEqual(n.stsPolicies, {
         'foo': (123, 'bar'),
         'baz': (456, 'qux'),
     })
Exemple #4
0
 def testStsPolicy(self):
     n = ircdb.IrcNetwork()
     n.addStsPolicy('foo', 'bar')
     n.addStsPolicy('baz', 'qux')
     self.assertEqual(n.stsPolicies, {
         'foo': 'bar',
         'baz': 'qux',
     })
Exemple #5
0
 def testPreserve(self):
     n = ircdb.IrcNetwork()
     n.addStsPolicy('foo', 123, 'sts1')
     n.addStsPolicy('bar', 456, 'sts2')
     n.addDisconnection('foo')
     n.addDisconnection('baz')
     disconnect_time_foo = n.lastDisconnectTimes['foo']
     disconnect_time_baz = n.lastDisconnectTimes['baz']
     fd = io.StringIO()
     n.preserve(fd, indent='    ')
     fd.seek(0)
     self.assertCountEqual(fd.read().split('\n'), [
         '    stsPolicy foo 123 sts1',
         '    stsPolicy bar 456 sts2',
         '    lastDisconnectTime foo %d' % disconnect_time_foo,
         '    lastDisconnectTime baz %d' % disconnect_time_baz,
         '',
         '',
     ])
Exemple #6
0
    def testGetSetNetwork(self):
        self.assertEqual(self.networks.getNetwork('foo').stsPolicies, {})

        n = ircdb.IrcNetwork()
        self.networks.setNetwork('foo', n)
        self.assertEqual(self.networks.getNetwork('foo').stsPolicies, {})
Exemple #7
0
 def testAddDisconnection(self):
     n = ircdb.IrcNetwork()
     min_ = int(time.time())
     n.addDisconnection('foo')
     max_ = int(time.time())
     self.assertTrue(min_ <= n.lastDisconnectTimes['foo'] <= max_)
Exemple #8
0
 def testDefaults(self):
     n = ircdb.IrcNetwork()
     self.assertEqual(n.stsPolicies, {})
     self.assertEqual(n.lastDisconnectTimes, {})