Exemplo n.º 1
0
 def test_rrd_source(self):
     self.assertEquals( Graph( self.eth0, 'if_packets', None).rrd_source(),
             [ ('', 'if_packets', get_fixture('rrd1/host2/interface-eth0/if_packets.rrd') ) ]
     )
Exemplo n.º 2
0
 def test_rrd_single_instance(self):
     self.assertEquals( Graph( self.irqs, 'irq', '3').rrd_source(),
             [ ('', 'irq-3', get_fixture('rrd1/host1/irq/irq-3.rrd')) ]
             )
Exemplo n.º 3
0
 def test_rrd_source_multi_instance(self):
     self.assertEquals( Graph( self.memory, 'memory', [ 'free', 'used'] ).rrd_source(), [
             ( '', 'used', get_fixture('rrd1/host2/memory/memory-used.rrd')),
             ( '', 'free', get_fixture('rrd1/host2/memory/memory-free.rrd')),
             ])
Exemplo n.º 4
0
import datetime
from lxml import html
from piratebay import exceptions
from piratebay.parser import SearchPageParser, UserPageParser, TorrentInfoParser
from test import get_fixture

class DateMixIn(object):
    def assertDate(self, d1, d2):
        self.assertEqual( (d1.year, d1.month, d1.day),\
                            (d2.year, d2.month, d2.day) )
        self.assertEqual( (d1.hour, d1.minute, d1.second),\
                            (d2.hour, d2.minute, d2.second) )
# Keep a dictionary with all lxml documents, so as not to re-read and re-parse
# them all each unittest.
html_docs = dict(
    real_site = html.parse(get_fixture("real_site.html")).getroot(),
    site_p6 = html.parse(get_fixture("site_p6.html")).getroot(),
    torrent_info_url = html.parse(get_fixture("torrent_info_url.html")).getroot()
)

class TestFailingCases(unittest.TestCase):
    def _create_parsers(self, document):
        return SearchPageParser(document), UserPageParser(document)
    def generate_document(self, code):
        return html.document_fromstring(code)
    def test_find_table(self):
        fragment = self.generate_document("""
        <html><body>
        <div id='content'><div id='main-content'>
        </div></div></body></html>""")
        p1, p2 = self._create_parsers(fragment)
Exemplo n.º 5
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import unittest

from test import get_fixture

from collectdweb.collectd_adapter import Collectd
from collectdweb import models
from collectdweb.models import Host, Plugin, Graph

models.collectd = Collectd([
    get_fixture('rrd1'),
    get_fixture('rrd2'),
    ])

class TestHost(unittest.TestCase):
    def test_equality(self):
        self.assertTrue( Host( 'host1') == Host('host1'))
        self.assertFalse( Host( 'host1') == Host('host2'))
    def test_not_equality(self):
        self.assertTrue( Host( 'host1') != Host('host2'))
        self.assertFalse( Host( 'host1') != Host('host1'))

class TestHosts( unittest.TestCase):
    def test_all_hosts(self):
       self.assertTrue( all( isinstance(x, Host) for x in Host.objects.all()))

    def test_once_all( self):
        self.assertTrue( isinstance( Host.objects.all(), list ))
        self.assertEquals( len( Host.objects.all()), 3)
Exemplo n.º 6
0
 def setUp(self):
     self.adapter = Collectd.from_config_file( get_fixture('collection.conf'))
Exemplo n.º 7
0
 def test_get_file(self):
     filepath = self.adapter.get_file( 'host1/irq/irq-3.rrd')
     self.assertEquals( filepath, get_fixture('rrd1/host1/irq/irq-3.rrd'))
     filepath = self.adapter.get_file( 'host2/interface-eth1/if_packets.rrd')
     self.assertEquals( filepath, get_fixture('rrd2/host2/interface-eth1/if_packets.rrd'))
Exemplo n.º 8
0
 def setUp(self):
     self.adapter = Collectd([
         get_fixture('rrd1'),
         get_fixture('rrd2'),
         ])
Exemplo n.º 9
0
 def test_libdirs(self):
     self.adapter = Collectd.from_config_file( get_fixture('collection-wrong.conf'))
     self.assertEquals( self.adapter.libdirs, set())
Exemplo n.º 10
0
 def setUp(self):
     self.doc = html.parse(open(get_fixture("real_site.html"))).getroot()
     self.doc2 = html.parse(open(get_fixture("site_p6.html"))).getroot()
     self.p1 = SearchPage(self.doc)
     self.p2 = SearchPage(self.doc2)