Example #1
0
 def setUp(self):
     self.client = Client()
     self.user = User.objects.create_user('user', '[email protected]',
                                          'userpassword')
     self.client.login(username='user', password='userpassword')
     
     self.host = Host(name='Host', description='Description',
                      ipv4='1.2.3.4', ipv6='', user=self.user)
     self.host.save()
     
     self.network = Network(name='Network', description='Description',
                            user=self.user)
     self.network.save()
     
     self.net_host = NetworkHost(network=self.network, host=self.host)
     self.net_host.save()
Example #2
0
class ReportMetaTest(TestCase):
    """Tests for reports meta"""
    
    def setUp(self):
        self.client = Client()
        self.user = User.objects.create_user('user', '[email protected]',
                                             'userpassword')
        self.client.login(username='user', password='userpassword')
        
        self.host = Host(name='Host', description='Description',
                         ipv4='1.2.3.4', ipv6='', user=self.user)
        self.host.save()
        
        self.network = Network(name='Network', description='Description',
                               user=self.user)
        self.network.save()
        
        self.net_host = NetworkHost(network=self.network, host=self.host)
        self.net_host.save()
        
    def test_reportmeta_host_list(self):
        for i in xrange(10):
            report_meta = ReportMeta(name='report %i' % i, description='description',
                                     period=1,
                                     object_type=ContentType.objects.get_for_model(Host),
                                     object_id=self.host.pk, user=self.user)
            report_meta.save()
        response = self.client.get('/report/list/host/')
        self.assertEqual(response.status_code, 200)
        
    def test_reportmeta_network_list(self):
        for i in xrange(10):
            report_meta = ReportMeta(name='report %i' % i, description='description',
                                     period=1,
                                     object_type=ContentType.objects.get_for_model(Network),
                                     object_id=self.network.pk, user=self.user)
            report_meta.save()
        response = self.client.get('/report/list/network/')
        self.assertEqual(response.status_code, 200)
    
    def test_reportmeta_detail(self):
        report_meta = ReportMeta(name='host report', description='description',
                                 period=1,
                                 object_type=ContentType.objects.get_for_model(Host),
                                 object_id=self.host.pk, user=self.user)
        report_meta.save()
        response = self.client.get('/report/%i/' % report_meta.pk)
        self.assertEqual(response.status_code, 200)
        
        report_meta = ReportMeta(name='network report', description='description',
                                 period=1,
                                 object_type=ContentType.objects.get_for_model(Network),
                                 object_id=self.network.pk, user=self.user)
        report_meta.save()
        response = self.client.get('/report/%i/' % report_meta.pk)
        self.assertEqual(response.status_code, 200)
    
    def test_reportmeta_create(self):
        reportmeta_host_data = {
            'name': 'New host report',
            'description': 'New host report description',
            'period': 1,
            'send_hour': 12,
            'send_day_week': 1,
            'send_day_month': 20,
            'object_type': ContentType.objects.get_for_model(Host).pk,
            'object_id': self.host.pk,
            'user': self.user.pk
        }
        
        reportmeta_network_data = {
            'name': 'New network report',
            'description': 'New network report description',
            'period': 1,
            'send_hour': 12,
            'send_day_week': 1,
            'send_day_month': 20,
            'object_type': ContentType.objects.get_for_model(Network).pk,
            'object_id': self.network.pk,
            'user': self.user.pk
        }
        
        response = self.client.post('/report/new/host/', reportmeta_host_data)
        self.assertEqual(response.status_code, 302)
        
        response = self.client.post('/report/new/network/', reportmeta_network_data)
        self.assertEqual(response.status_code, 302)
    
    def test_reportmeta_update(self):
        reportmeta_host = ReportMeta(name='host report', description='description',
                                     period=1,
                                 object_type=ContentType.objects.get_for_model(Host),
                                 object_id=self.host.pk, user=self.user)
        reportmeta_host.save()
        
        reportmeta_net = ReportMeta(name='network report', description='description',
                            period=1,
                            object_type=ContentType.objects.get_for_model(Network),
                            object_id=self.network.pk, user=self.user)
        reportmeta_net.save()
        
        reportmeta_host_data = {
            'name': 'Updated host report',
            'description': 'Updated host report description',
            'period': 1,
            'send_hour': 12,
            'send_day_week': 1,
            'send_day_month': 20,
            'object_type': ContentType.objects.get_for_model(Host).pk,
            'object_id': self.host.pk,
            'user': self.user.pk
        }
        
        reportmeta_network_data = {
            'name': 'Updated network report',
            'description': 'Updated network report description',
            'period': 1,
            'send_hour': 12,
            'send_day_week': 1,
            'send_day_month': 20,
            'object_type': ContentType.objects.get_for_model(Network).pk,
            'object_id': self.network.pk,
            'user': self.user.pk
        }
        
        response = self.client.post('/report/edit/%i/' % reportmeta_host.pk, reportmeta_host_data)
        self.assertEqual(response.status_code, 302)
        response = self.client.post('/report/edit/%i/' % reportmeta_net.pk, reportmeta_network_data)
        self.assertEqual(response.status_code, 302)
    
    def test_reportmeta_delete(self):
        ct_host = ContentType.objects.get_for_model(Host)
        ct_network = ContentType.objects.get_for_model(Network)
        reportmeta_host = ReportMeta(name='host report', description='description',
                                     period=1, object_type=ct_host,
                                     object_id=self.host.pk, user=self.user)
        reportmeta_host.save()
        reportmeta_host_pk = reportmeta_host.pk
        
        reportmeta_net = ReportMeta(name='network report', description='description',
                                    period=1, object_type=ct_network,
                                    object_id=self.network.pk, user=self.user)
        reportmeta_net.save()
        reportmeta_net_pk = reportmeta_net.pk
        
        response = self.client.post('/report/delete/%i/' % reportmeta_host.pk)
        self.assertEqual(response.status_code, 302)
        self.assertRaises(ReportMeta.DoesNotExist, ReportMeta.objects.get,
                          **{'object_id': reportmeta_host_pk,
                             'object_type': ct_host})

        response = self.client.post('/report/delete/%i/' % reportmeta_net.pk)
        self.assertEqual(response.status_code, 302)
        self.assertRaises(ReportMeta.DoesNotExist, ReportMeta.objects.get,
                          **{'object_id': reportmeta_net_pk,
                             'object_type': ct_network})