def setUp(self):
        '''
        Commands run before every test
        '''

        # Using hwdoc's test case in order to DRY and setup a proper env for
        # tests
        from hwdoc.tests import EquipmentTestCase
        EquipmentTestCase.dummy = lambda x: True
        self.etc = EquipmentTestCase('dummy')
        self.etc.setUp()

        self.package1 = Package.objects.create(name='testpackage', sourcename='testsource')
        self.package2 = Package.objects.create(name='testpackage2', sourcename='testsource')
        self.host1 = Host.objects.create(name='testservermonHost1', ip='10.10.10.10')
        self.host2 = Host.objects.create(name='testservermonHost2', ip='10.10.10.11')
        self.host3 = Host.objects.create(name='testservermonHost3', ip='10.10.10.12')
        self.fact1 = Fact.objects.create(name='interfaces')
        self.fact2 = Fact.objects.create(name='macaddress_eth0')
        self.fact3 = Fact.objects.create(name='ipaddress_eth0')
        self.fact4 = Fact.objects.create(name='netmask_eth0')
        self.fact5 = Fact.objects.create(name='ipaddress6_eth0')
        self.fact6 = Fact.objects.create(name='serialnumber')
        self.factvalue1 = FactValue.objects.create(
            value='eth0',
            fact_name=self.fact1, host=self.host1)
        self.factvalue2 = FactValue.objects.create(
            value='aa:bb:cc:dd:ee:ff',
            fact_name=self.fact2, host=self.host1)
        self.factvalue3 = FactValue.objects.create(
            value='10.10.10.10',
            fact_name=self.fact3, host=self.host1)
        self.factvalue4 = FactValue.objects.create(
            value='255.255.255.0',
            fact_name=self.fact4, host=self.host1)
        self.factvalue5 = FactValue.objects.create(
            value='dead:beef::1/64',
            fact_name=self.fact5, host=self.host1)
        self.factvalue6 = FactValue.objects.create(
            value='R123457',
            fact_name=self.fact6, host=self.host2)
        self.factvalue7 = FactValue.objects.create(
            value='G123456',
            fact_name=self.fact6, host=self.host3)
        self.update1 = Update.objects.create(
            package=self.package1, host=self.host1,
            installedVersion='1.1', candidateVersion='1.2',
            source='TestSource', origin='Debian')
        self.update2 = Update.objects.create(
            package=self.package2, host=self.host1, is_security=True,
            installedVersion='1.1', candidateVersion='1.2',
            source='TestSource', origin='Ubuntu')
Esempio n. 2
0
    def setUp(self):
        '''
        Commands run before every test
        '''

        # Using hwdoc's test case in order to DRY and setup a proper env for
        # tests
        from hwdoc.tests import EquipmentTestCase
        EquipmentTestCase.dummy = lambda x: True
        self.etc = EquipmentTestCase('dummy')
        self.etc.setUp()

        self.package1 = Package.objects.create(name='testpackage', sourcename='testsource')
        self.package2 = Package.objects.create(name='testpackage2', sourcename='testsource')
        self.host1 = Host.objects.create(name='testservermonHost1', ip='10.10.10.10')
        self.host2 = Host.objects.create(name='testservermonHost2', ip='10.10.10.11')
        self.fact1 = Fact.objects.create(name='interfaces')
        self.fact2 = Fact.objects.create(name='macaddress_eth0')
        self.fact3 = Fact.objects.create(name='ipaddress_eth0')
        self.fact4 = Fact.objects.create(name='netmask_eth0')
        self.fact5 = Fact.objects.create(name='ipaddress6_eth0')
        self.fact6 = Fact.objects.create(name='serialnumber')
        self.factvalue1 = FactValue.objects.create(value='eth0',
                fact_name=self.fact1, host=self.host1)
        self.factvalue2 = FactValue.objects.create(value='aa:bb:cc:dd:ee:ff',
                fact_name=self.fact2, host=self.host1)
        self.factvalue3 = FactValue.objects.create(value='10.10.10.10',
                fact_name=self.fact3, host=self.host1)
        self.factvalue4 = FactValue.objects.create(value='255.255.255.0',
                fact_name=self.fact4, host=self.host1)
        self.factvalue5 = FactValue.objects.create(value='dead:beef::1/64',
                fact_name=self.fact5, host=self.host1)
        self.factvalue6 = FactValue.objects.create(value='R123457',
                fact_name=self.fact6, host=self.host2)
Esempio n. 3
0
    def setUp(self):
        '''
        Command run before every test
        '''
        # Using hwdoc's test case in order to DRY and setup a proper env for
        # tests
        from hwdoc.tests import EquipmentTestCase
        EquipmentTestCase.dummy = lambda x: True
        self.etc = EquipmentTestCase('dummy')
        self.etc.setUp()
        from keyvalue.tests import KeyTestCase
        KeyTestCase.dummy = lambda x: True
        self.ktc = KeyTestCase('dummy')
        self.ktc.setUp()

        self.u1 = User.objects.create(username='******', email='*****@*****.**',
                            is_staff=True, is_superuser=True)
        self.u2 = User.objects.create(username='******', email='*****@*****.**',
                            is_staff=True, is_superuser=False)
        self.u3 = User.objects.create(username='******', email='*****@*****.**',
                            is_staff=True, is_superuser=False)
        self.u4 = User.objects.create(username='******', email='*****@*****.**',
                            is_staff=True, is_superuser=False)
        self.p_comment = Permission.objects.get(codename='can_change_comment')
        self.p_c_eq = Permission.objects.get(codename='change_equipment')
        self.u2.user_permissions.add(self.p_comment)
        self.u4.user_permissions.add(self.p_c_eq)
        self.u1.set_password('test')
        self.u2.set_password('test')
        self.u3.set_password('test')
        self.u4.set_password('test')
        self.u1.save()
        self.u2.save()
        self.u3.save()
        self.u4.save()
        self.c1 = Client()
        self.c2 = Client()
        self.c3 = Client()
        self.c4 = Client()
        self.assertTrue(self.c1.login(username='******', password='******'))
        self.assertTrue(self.c2.login(username='******', password='******'))
        self.assertTrue(self.c3.login(username='******', password='******'))
        self.assertTrue(self.c4.login(username='******', password='******'))
Esempio n. 4
0
class ViewsTestCase(unittest.TestCase):
    '''
    Testing views class
    '''
    def setUp(self):
        '''
        Commands run before every test
        '''

        # Using hwdoc's test case in order to DRY and setup a proper env for
        # tests
        from hwdoc.tests import EquipmentTestCase
        EquipmentTestCase.dummy = lambda x: True
        self.etc = EquipmentTestCase('dummy')
        self.etc.setUp()

        self.package1 = Package.objects.create(name='testpackage', sourcename='testsource')
        self.package2 = Package.objects.create(name='testpackage2', sourcename='testsource')
        self.host1 = Host.objects.create(name='testservermonHost1', ip='10.10.10.10')
        self.host2 = Host.objects.create(name='testservermonHost2', ip='10.10.10.11')
        self.fact1 = Fact.objects.create(name='interfaces')
        self.fact2 = Fact.objects.create(name='macaddress_eth0')
        self.fact3 = Fact.objects.create(name='ipaddress_eth0')
        self.fact4 = Fact.objects.create(name='netmask_eth0')
        self.fact5 = Fact.objects.create(name='ipaddress6_eth0')
        self.fact6 = Fact.objects.create(name='serialnumber')
        self.factvalue1 = FactValue.objects.create(value='eth0',
                fact_name=self.fact1, host=self.host1)
        self.factvalue2 = FactValue.objects.create(value='aa:bb:cc:dd:ee:ff',
                fact_name=self.fact2, host=self.host1)
        self.factvalue3 = FactValue.objects.create(value='10.10.10.10',
                fact_name=self.fact3, host=self.host1)
        self.factvalue4 = FactValue.objects.create(value='255.255.255.0',
                fact_name=self.fact4, host=self.host1)
        self.factvalue5 = FactValue.objects.create(value='dead:beef::1/64',
                fact_name=self.fact5, host=self.host1)
        self.factvalue6 = FactValue.objects.create(value='R123457',
                fact_name=self.fact6, host=self.host2)

    def tearDown(self):
        '''
        Commands run after every test
        '''
        Package.objects.all().delete()
        Host.objects.all().delete()
        Fact.objects.all().delete()
        FactValue.objects.all().delete()
        self.etc.tearDown()

    def test_hostlist(self):
        c = Client()
        response = c.get('/hosts/')
        self.assertEqual(response.status_code, 200)

    def test_packagelist(self):
        c = Client()
        response = c.get('/packages/')
        self.assertEqual(response.status_code, 200)

    def test_empty_package(self):
        c = Client()
        data = ['']
        for d in data:
            response = c.get('/packages/%s' % d)
            # This is not an error since empty package means, due to
            # urls.py that we fallback to packagelist
            self.assertEqual(response.status_code, 200)

    def test_nonexistent_package(self):
        c = Client()
        data = ['nosuchpackage']
        for d in data:
            response = c.get('/packages/%s' % d)
            self.assertEqual(response.status_code, 404)

    def test_existent_package(self):
        c = Client()
        data = [self.package1.name, self.package2.name]
        for d in data:
            response = c.get('/packages/%s' % d)
            self.assertEqual(response.status_code, 200)

    def test_existent_package_plaintext(self):
        c = Client()
        data = [self.package1.name, self.package2.name]
        for d in data:
            response = c.get('/packages/%s' % d, {'plain': 'yes'})
            self.assertEqual(response.status_code, 200)

    def test_empty_host(self):
        c = Client()
        response = c.get('/hosts/%s' % '')
        # This should work because of urls fallback to hostlist
        self.assertEqual(response.status_code, 200)

    def test_nonexistent_host(self):
        c = Client()
        response = c.get('/hosts/%s' % 'nosuchhost' )
        self.assertEqual(response.status_code, 404)

    def test_existent_host(self):
        c = Client()
        data = [self.host1.name]
        for d in data:
            response = c.get('/hosts/%s' % d)
            self.assertEqual(response.status_code, 200)

    def test_existent_host_without_interfaces(self):
        c = Client()
        data = [self.host2.name]
        for d in data:
            response = c.get('/hosts/%s' % d)
            self.assertEqual(response.status_code, 200)
Esempio n. 5
0
class AdminViewsTestCase(unittest.TestCase):
    '''
    Testing admin views class
    '''

    def setUp(self):
        '''
        Command run before every test
        '''
        # Using hwdoc's test case in order to DRY and setup a proper env for
        # tests
        from hwdoc.tests import EquipmentTestCase
        EquipmentTestCase.dummy = lambda x: True
        self.etc = EquipmentTestCase('dummy')
        self.etc.setUp()
        from keyvalue.tests import KeyTestCase
        KeyTestCase.dummy = lambda x: True
        self.ktc = KeyTestCase('dummy')
        self.ktc.setUp()

        self.u1 = User.objects.create(username='******', email='*****@*****.**',
                            is_staff=True, is_superuser=True)
        self.u2 = User.objects.create(username='******', email='*****@*****.**',
                            is_staff=True, is_superuser=False)
        self.u3 = User.objects.create(username='******', email='*****@*****.**',
                            is_staff=True, is_superuser=False)
        self.u4 = User.objects.create(username='******', email='*****@*****.**',
                            is_staff=True, is_superuser=False)
        self.p_comment = Permission.objects.get(codename='can_change_comment')
        self.p_c_eq = Permission.objects.get(codename='change_equipment')
        self.u2.user_permissions.add(self.p_comment)
        self.u4.user_permissions.add(self.p_c_eq)
        self.u1.set_password('test')
        self.u2.set_password('test')
        self.u3.set_password('test')
        self.u4.set_password('test')
        self.u1.save()
        self.u2.save()
        self.u3.save()
        self.u4.save()
        self.c1 = Client()
        self.c2 = Client()
        self.c3 = Client()
        self.c4 = Client()
        self.assertTrue(self.c1.login(username='******', password='******'))
        self.assertTrue(self.c2.login(username='******', password='******'))
        self.assertTrue(self.c3.login(username='******', password='******'))
        self.assertTrue(self.c4.login(username='******', password='******'))

    def tearDown(self):
        '''
        Command run after every test
        '''
        self.c1.logout()
        self.c2.logout()
        self.c3.logout()
        self.c4.logout()
        self.etc.tearDown()
        self.ktc.tearDown()
        User.objects.all().delete()

    def test_admin_datacenter(self):
        response = self.c1.get('/admin/hwdoc/datacenter/')
        self.assertEqual(response.status_code, 200)
        response = self.c3.get('/admin/hwdoc/datacenter/')
        self.assertEqual(response.status_code, 403)

    def test_admin_email(self):
        response = self.c1.get('/admin/hwdoc/email/')
        self.assertEqual(response.status_code, 200)

    def test_admin_equipmentmodel(self):
        response = self.c1.get('/admin/hwdoc/equipmentmodel/')
        self.assertEqual(response.status_code, 200)

    def test_admin_equipment(self):
        response = self.c1.get('/admin/hwdoc/equipment/')
        self.assertEqual(response.status_code, 200)
        response = self.c2.get('/admin/hwdoc/equipment/')
        self.assertEqual(response.status_code, 200)
        response = self.c3.get('/admin/hwdoc/equipment/')
        self.assertEqual(response.status_code, 403)
        response = self.c4.get('/admin/hwdoc/equipment/')
        self.assertEqual(response.status_code, 200)

    def test_admin_equipment1(self):
        response = self.c1.get('/admin/hwdoc/equipment/1/')
        self.assertEqual(response.status_code, 200)
        response = self.c2.get('/admin/hwdoc/equipment/1/')
        self.assertEqual(response.status_code, 200)
        response = self.c3.get('/admin/hwdoc/equipment/1/')
        self.assertEqual(response.status_code, 403)
        response = self.c4.get('/admin/hwdoc/equipment/1/')
        self.assertEqual(response.status_code, 200)

    def test_admin_person(self):
        response = self.c1.get('/admin/hwdoc/person/')
        self.assertEqual(response.status_code, 200)

    def test_admin_phone(self):
        response = self.c1.get('/admin/hwdoc/phone/')
        self.assertEqual(response.status_code, 200)

    def test_admin_project(self):
        response = self.c1.get('/admin/hwdoc/project/')
        self.assertEqual(response.status_code, 200)

    def test_admin_rackmodel(self):
        response = self.c1.get('/admin/hwdoc/rackmodel/')
        self.assertEqual(response.status_code, 200)

    def test_admin_rackrow(self):
        response = self.c1.get('/admin/hwdoc/rackrow/')
        self.assertEqual(response.status_code, 200)

    def test_admin_rack(self):
        response = self.c1.get('/admin/hwdoc/rack/')
        self.assertEqual(response.status_code, 200)

    def test_admin_ticket(self):
        response = self.c1.get('/admin/hwdoc/ticket/')
        self.assertEqual(response.status_code, 200)

    def test_admin_vendor(self):
        response = self.c1.get('/admin/hwdoc/vendor/')
        self.assertEqual(response.status_code, 200)

    def test_admin_keyvalue(self):
        response = self.c1.get('/admin/keyvalue/key/')
        self.assertEqual(response.status_code, 200)

    def test_admin_keyvalue1(self):
        response = self.c1.get('/admin/keyvalue/key/1/')
        self.assertEqual(response.status_code, 200)
class ViewsTestCase(unittest.TestCase):
    '''
    Testing views class
    '''
    def setUp(self):
        '''
        Commands run before every test
        '''

        # Using hwdoc's test case in order to DRY and setup a proper env for
        # tests
        from hwdoc.tests import EquipmentTestCase
        EquipmentTestCase.dummy = lambda x: True
        self.etc = EquipmentTestCase('dummy')
        self.etc.setUp()

        self.package1 = Package.objects.create(name='testpackage', sourcename='testsource')
        self.package2 = Package.objects.create(name='testpackage2', sourcename='testsource')
        self.host1 = Host.objects.create(name='testservermonHost1', ip='10.10.10.10')
        self.host2 = Host.objects.create(name='testservermonHost2', ip='10.10.10.11')
        self.host3 = Host.objects.create(name='testservermonHost3', ip='10.10.10.12')
        self.fact1 = Fact.objects.create(name='interfaces')
        self.fact2 = Fact.objects.create(name='macaddress_eth0')
        self.fact3 = Fact.objects.create(name='ipaddress_eth0')
        self.fact4 = Fact.objects.create(name='netmask_eth0')
        self.fact5 = Fact.objects.create(name='ipaddress6_eth0')
        self.fact6 = Fact.objects.create(name='serialnumber')
        self.factvalue1 = FactValue.objects.create(
            value='eth0',
            fact_name=self.fact1, host=self.host1)
        self.factvalue2 = FactValue.objects.create(
            value='aa:bb:cc:dd:ee:ff',
            fact_name=self.fact2, host=self.host1)
        self.factvalue3 = FactValue.objects.create(
            value='10.10.10.10',
            fact_name=self.fact3, host=self.host1)
        self.factvalue4 = FactValue.objects.create(
            value='255.255.255.0',
            fact_name=self.fact4, host=self.host1)
        self.factvalue5 = FactValue.objects.create(
            value='dead:beef::1/64',
            fact_name=self.fact5, host=self.host1)
        self.factvalue6 = FactValue.objects.create(
            value='R123457',
            fact_name=self.fact6, host=self.host2)
        self.factvalue7 = FactValue.objects.create(
            value='G123456',
            fact_name=self.fact6, host=self.host3)
        self.update1 = Update.objects.create(
            package=self.package1, host=self.host1,
            installedVersion='1.1', candidateVersion='1.2',
            source='TestSource', origin='Debian')
        self.update2 = Update.objects.create(
            package=self.package2, host=self.host1, is_security=True,
            installedVersion='1.1', candidateVersion='1.2',
            source='TestSource', origin='Ubuntu')

    def tearDown(self):
        '''
        Commands run after every test
        '''
        Package.objects.all().delete()
        Update.objects.all().delete()
        Host.objects.all().delete()
        Fact.objects.all().delete()
        FactValue.objects.all().delete()
        self.etc.tearDown()

    def test_hostlist(self):
        c = Client()
        response = c.get('/hosts/')
        self.assertEqual(response.status_code, 200)

    def test_packagelist(self):
        c = Client()
        response = c.get('/packages/')
        self.assertEqual(response.status_code, 200)

    def test_empty_package(self):
        c = Client()
        data = ['']
        for d in data:
            response = c.get('/packages/%s' % d)
            # This is not an error since empty package means, due to
            # urls.py that we fallback to packagelist
            self.assertEqual(response.status_code, 200)

    def test_nonexistent_package(self):
        c = Client()
        data = ['nosuchpackage']
        for d in data:
            response = c.get('/packages/%s' % d)
            self.assertEqual(response.status_code, 404)

    def test_existent_package(self):
        c = Client()
        data = [self.package1.name, self.package2.name]
        for d in data:
            response = c.get('/packages/%s' % d)
            self.assertEqual(response.status_code, 200)

    def test_existent_package_plaintext(self):
        c = Client()
        data = [self.package1.name, self.package2.name]
        for d in data:
            response = c.get('/packages/%s' % d, {'plain': 'yes'})
            self.assertEqual(response.status_code, 200)

    def test_empty_host(self):
        c = Client()
        response = c.get('/hosts/%s' % '')
        # This should work because of urls fallback to hostlist
        self.assertEqual(response.status_code, 200)

    def test_nonexistent_host(self):
        c = Client()
        response = c.get('/hosts/%s' % 'nosuchhost')
        self.assertEqual(response.status_code, 404)

    def test_existent_host(self):
        c = Client()
        data = [self.host1.name, self.host2.name, self.host3.name]
        for d in data:
            response = c.get('/hosts/%s' % d)
            self.assertEqual(response.status_code, 200)

    def test_existent_host_without_interfaces(self):
        c = Client()
        data = [self.host2.name]
        for d in data:
            response = c.get('/hosts/%s' % d)
            self.assertEqual(response.status_code, 200)