コード例 #1
0
ファイル: tests.py プロジェクト: 3atmospheres/treeio
 def test_model_report(self):
     "Test Report Model"
     obj = Report(name='test')
     obj.save()
     self.assertEquals('test', obj.name)
     self.assertNotEquals(obj.id, None)
     obj.delete()
コード例 #2
0
ファイル: tests.py プロジェクト: stefanfoulis/treeio
 def test_model_report(self):
     "Test Report Model"
     obj = Report(name='test')
     obj.save()
     self.assertEquals('test', obj.name)
     self.assertNotEquals(obj.id, None)
     obj.delete()
コード例 #3
0
ファイル: tests.py プロジェクト: 3atmospheres/treeio
 def test_model_chart(self):
     "Test Chart Model"
     report = Report(name='test')
     report.save()
     obj = Chart(name='test', report=report)
     obj.save()
     self.assertEquals('test', obj.name)
     self.assertNotEquals(obj.id, None)
     obj.delete()
コード例 #4
0
ファイル: tests.py プロジェクト: stefanfoulis/treeio
 def test_model_chart(self):
     "Test Chart Model"
     report = Report(name='test')
     report.save()
     obj = Chart(name='test', report=report)
     obj.save()
     self.assertEquals('test', obj.name)
     self.assertNotEquals(obj.id, None)
     obj.delete()
コード例 #5
0
ファイル: views.py プロジェクト: 5n1p/treeio
def report_add(request, response_format='html'):
    "Create new report based on user choice"
    if 'report' in request.POST:
        report_id = request.POST['report']
        return HttpResponseRedirect(reverse('reports_report_edit', args=[report_id]))
    # FIRST TIME AN OBJECT IS CHOSEN
    if 'choice' in request.POST:
        form = None
        object = request.POST['choice']
        object = str(
            object.replace("{'object_type': u'", '').replace("'}", ''))
        full_object = object
        object = object.split('.', 3)

        module_name = object[0] + '.' + object[1] + '.' + object[2]
        import_name = object[3]

        module = __import__(
            module_name, globals(), locals(), [import_name], -1)
        classobj = getattr(module, import_name)

        obj = classobj()
        names = obj.get_field_names()

        fields = []
        for name in names:
            fields.append(Field(name=name, display=True))

        model = Model(full_object, fields)

        report = Report()
        report.name = "Untitled %s Report" % (obj._meta.object_name)
        report.model = dumps(model)
        report.creator = request.user.get_profile()
        report.save()

        return HttpResponseRedirect(reverse('reports_report_edit', args=[report.id]))

    # Initial Object Type Choice
    user_modules = [mod.name for mod in request.user.get_profile().get_perspective().get_modules()]
    modules = [mod.name for mod in Module.objects.all()]
    query = Q(object_type__contains="core")
    for module in modules:
        if module not in user_modules:
            query = query | Q(object_type__contains=module)

    object_types = list(Object.objects.all().exclude(query).values(
        'object_type').distinct().order_by('object_type'))

    object_names = []
    if object_types:
        object_names = ["%s: %s" %
                        (_get_module_name(object_types[i]['object_type']),
                         (Object.objects.filter(object_type=object_types[i]['object_type']).order_by()[0].get_human_type()))
                        for i in range(0, len(object_types))]

    form = ObjChoiceForm(request.user,
                         object_types=object_types,
                         object_names=object_names,
                         )

    return render_to_response('reports/report_add',
                              {'form': form},
                              context_instance=RequestContext(request),
                              response_format=response_format)
コード例 #6
0
def report_add(request, response_format='html'):
    "Create new report based on user choice"
    if 'report' in request.POST:
        report_id = request.POST['report']
        return HttpResponseRedirect(
            reverse('reports_report_edit', args=[report_id]))
    # FIRST TIME AN OBJECT IS CHOSEN
    if 'choice' in request.POST:
        form = None
        object = request.POST['choice']
        object = str(
            object.replace("{'object_type': u'", '').replace("'}", ''))
        full_object = object
        object = object.split('.', 3)

        module_name = object[0] + '.' + object[1] + '.' + object[2]
        import_name = object[3]

        module = __import__(module_name, globals(), locals(), [import_name],
                            -1)
        classobj = getattr(module, import_name)

        obj = classobj()
        names = obj.get_field_names()

        fields = []
        for name in names:
            fields.append(Field(name=name, display=True))

        model = Model(full_object, fields)

        report = Report()
        report.name = "Untitled %s Report" % (obj._meta.object_name)
        report.model = dumps(model)
        report.creator = request.user.get_profile()
        report.save()

        return HttpResponseRedirect(
            reverse('reports_report_edit', args=[report.id]))

    # Initial Object Type Choice
    user_modules = [
        mod.name
        for mod in request.user.get_profile().get_perspective().get_modules()
    ]
    modules = [mod.name for mod in Module.objects.all()]
    query = Q(object_type__contains="core")
    for module in modules:
        if module not in user_modules:
            query = query | Q(object_type__contains=module)

    object_types = list(Object.objects.all().exclude(query).values(
        'object_type').distinct().order_by('object_type'))

    object_names = []
    if object_types:
        object_names = [
            "%s: %s" %
            (_get_module_name(object_types[i]['object_type']),
             (Object.objects.filter(object_type=object_types[i]['object_type']
                                    ).order_by()[0].get_human_type()))
            for i in range(0, len(object_types))
        ]

    form = ObjChoiceForm(
        request.user,
        object_types=object_types,
        object_names=object_names,
    )

    return render_to_response('reports/report_add', {'form': form},
                              context_instance=RequestContext(request),
                              response_format=response_format)
コード例 #7
0
ファイル: tests.py プロジェクト: 3atmospheres/treeio
class ReportsViewsTest(TestCase):
    "Reports functional tests for views"

    username = "******"
    password = "******"
    prepared = False
    
    def setUp(self):
        "Initial Setup"
        
        if not self.prepared:
            self.group, created = Group.objects.get_or_create(name='test')
            duser, created = DjangoUser.objects.get_or_create(username=self.username)
            duser.set_password(self.password)
            duser.save()
            self.user, created = User.objects.get_or_create(user=duser)
            self.user.save()
            perspective, created = Perspective.objects.get_or_create(name='default')
            perspective.set_default_user()
            perspective.save()
            ModuleSetting.set('default_perspective', perspective.id) 
            
            self.report = Report(name='test')
            self.report.set_default_user()
            self.report.save()
            
            self.chart = Chart(name='test_chart', report=self.report)
            self.chart.set_default_user()
            self.chart.save()
                
            self.client = Client()
            
            self.prepared = True
    
    
    ######################################
    # Testing views when user is logged in
    ######################################   
    
    def test_reports_login(self):
        "Testing /reports/"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password })
        self.assertRedirects(response, '/')
        response = self.client.get(reverse('reports'))
        self.assertEquals(response.status_code, 200)
        
    def test_index_login(self):
        "Testing /reports/index/"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password })
        self.assertRedirects(response, '/')
        response = self.client.get(reverse('reports_index'))
        self.assertEquals(response.status_code, 200)
        
    def test_index_owned(self):
        "Testing /reports/owned/"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password })
        self.assertRedirects(response, '/')
        response = self.client.get(reverse('reports_index'))
        self.assertEquals(response.status_code, 200)
        
     
        
    # Charts
    
    def test_chart_add(self):
        "Testing /reports/chart/add/"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password })
        self.assertRedirects(response, '/')
        response = self.client.get(reverse('reports_chart_add'))
        self.assertEquals(response.status_code, 200)
        
    def test_chart_delete_login(self):
        "Testing /reports/chart/delete/<chart_id>"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password })
        self.assertRedirects(response, '/')
        response = self.client.get(reverse('reports_chart_delete', args=[self.chart.id]))
        self.assertEquals(response.status_code, 200)
        
        
        
    # Reports
    
    def test_report_add(self):
        "Testing /reports/report/add/"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password })
        self.assertRedirects(response, '/')
        response = self.client.get(reverse('reports_report_add'))
        self.assertEquals(response.status_code, 200)
        
    def test_report_delete_login(self):
        "Testing /reports/report/delete/<report_id>"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password })
        self.assertRedirects(response, '/')
        response = self.client.get(reverse('reports_report_delete', args=[self.report.id]))
        self.assertEquals(response.status_code, 200)
        


    ######################################
    # Testing views when user is not logged in
    ######################################   
    
    def test_reports_out(self):
        "Testing /reports/"
        response = self.client.get(reverse('reports'))
        self.assertRedirects(response, reverse('user_login'))
        
    def test_index_out(self):
        "Testing /reports/index/"
        response = self.client.get(reverse('reports_index'))
        self.assertRedirects(response, reverse('user_login'))
        
    def test_index_owned_out(self):
        "Testing /reports/owned/"
        response = self.client.get(reverse('reports_index'))
        self.assertRedirects(response, reverse('user_login'))
     
        
    # Charts
    
    def test_chart_add_out(self):
        "Testing /reports/chart/add/"
        response = self.client.get(reverse('reports_chart_add'))
        self.assertRedirects(response, reverse('user_login'))
        
    def test_chart_add_typed_out(self):
        "Testing /reports/chart/add/<report_id>"
        response = self.client.get(reverse('reports_chart_add', args=[self.report.id]))
        self.assertRedirects(response, reverse('user_login'))

    def test_chart_edit_out(self):
        "Testing /reports/chart/edit/<chart_id>"
        response = self.client.get(reverse('reports_chart_edit', args=[self.chart.id]))
        self.assertRedirects(response, reverse('user_login'))
        
    def test_chart_delete_out(self):
        "Testing /reports/chart/delete/<chart_id>"
        response = self.client.get(reverse('reports_chart_delete', args=[self.chart.id]))
        self.assertRedirects(response, reverse('user_login'))
        
        
    # Reports
    
    def test_report_add_out(self):
        "Testing /reports/report/add/"
        response = self.client.get(reverse('reports_report_add'))
        self.assertRedirects(response, reverse('user_login'))

    def test_report_view_out(self):
        "Testing /reports/report/view/<report_id>"
        response = self.client.get(reverse('reports_report_view', args=[self.report.id]))
        self.assertRedirects(response, reverse('user_login'))
        
    def test_report_edit_out(self):
        "Testing /reports/report/edit/<report_id>"
        response = self.client.get(reverse('reports_report_edit', args=[self.report.id]))
        self.assertRedirects(response, reverse('user_login'))
        
    def test_report_delete_out(self):
        "Testing /reports/report/delete/<report_id>"
        response = self.client.get(reverse('reports_report_delete', args=[self.report.id]))
        self.assertRedirects(response, reverse('user_login'))
コード例 #8
0
ファイル: tests.py プロジェクト: stefanfoulis/treeio
class ReportsViewsTest(TestCase):
    "Reports functional tests for views"

    username = "******"
    password = "******"
    prepared = False
    
    def setUp(self):
        "Initial Setup"
        
        if not self.prepared:
            Object.objects.all().delete()
            
            # Create objects
            
            try:
                self.group = Group.objects.get(name='test')
            except Group.DoesNotExist:
                Group.objects.all().delete()
                self.group = Group(name='test')
                self.group.save()
            
            try:
                self.user = DjangoUser.objects.get(username=self.username)
                self.user.set_password(self.password)
                try:
                    self.profile = self.user.get_profile()
                except Exception:
                    User.objects.all().delete()
                    self.user = DjangoUser(username=self.username, password='')
                    self.user.set_password(self.password)
                    self.user.save()
            except DjangoUser.DoesNotExist:
                User.objects.all().delete()
                self.user = DjangoUser(username=self.username, password='')
                self.user.set_password(self.password)
                self.user.save()
                
            try:
                perspective = Perspective.objects.get(name='default')
            except Perspective.DoesNotExist:
                Perspective.objects.all().delete()
                perspective = Perspective(name='default')
                perspective.set_default_user()
                perspective.save()
                
            ModuleSetting.set('default_perspective', perspective.id)
            
            self.report = Report(name='test')
            self.report.set_default_user()
            self.report.save()
            
            self.chart = Chart(name='test_chart', report=self.report)
            self.chart.set_default_user()
            self.chart.save()
                
            self.client = Client()
            
            self.prepared = True
    
    
    ######################################
    # Testing views when user is logged in
    ######################################   
    
    def test_reports_login(self):
        "Testing /reports/"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password })
        self.assertRedirects(response, '/')
        response = self.client.get(reverse('reports'))
        self.assertEquals(response.status_code, 200)
        
    def test_index_login(self):
        "Testing /reports/index/"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password })
        self.assertRedirects(response, '/')
        response = self.client.get(reverse('reports_index'))
        self.assertEquals(response.status_code, 200)
        
    def test_index_owned(self):
        "Testing /reports/owned/"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password })
        self.assertRedirects(response, '/')
        response = self.client.get(reverse('reports_index'))
        self.assertEquals(response.status_code, 200)
        
     
        
    # Charts
    
    def test_chart_add(self):
        "Testing /reports/chart/add/"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password })
        self.assertRedirects(response, '/')
        response = self.client.get(reverse('reports_chart_add'))
        self.assertEquals(response.status_code, 200)
        
    def test_chart_delete_login(self):
        "Testing /reports/chart/delete/<chart_id>"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password })
        self.assertRedirects(response, '/')
        response = self.client.get(reverse('reports_chart_delete', args=[self.chart.id]))
        self.assertEquals(response.status_code, 200)
        
        
        
    # Reports
    
    def test_report_add(self):
        "Testing /reports/report/add/"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password })
        self.assertRedirects(response, '/')
        response = self.client.get(reverse('reports_report_add'))
        self.assertEquals(response.status_code, 200)
        
    def test_report_delete_login(self):
        "Testing /reports/report/delete/<report_id>"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password })
        self.assertRedirects(response, '/')
        response = self.client.get(reverse('reports_report_delete', args=[self.report.id]))
        self.assertEquals(response.status_code, 200)
        


    ######################################
    # Testing views when user is not logged in
    ######################################   
    
    def test_reports_out(self):
        "Testing /reports/"
        response = self.client.get(reverse('reports'))
        self.assertRedirects(response, reverse('user_login'))
        
    def test_index_out(self):
        "Testing /reports/index/"
        response = self.client.get(reverse('reports_index'))
        self.assertRedirects(response, reverse('user_login'))
        
    def test_index_owned_out(self):
        "Testing /reports/owned/"
        response = self.client.get(reverse('reports_index'))
        self.assertRedirects(response, reverse('user_login'))
     
        
    # Charts
    
    def test_chart_add_out(self):
        "Testing /reports/chart/add/"
        response = self.client.get(reverse('reports_chart_add'))
        self.assertRedirects(response, reverse('user_login'))
        
    def test_chart_add_typed_out(self):
        "Testing /reports/chart/add/<report_id>"
        response = self.client.get(reverse('reports_chart_add', args=[self.report.id]))
        self.assertRedirects(response, reverse('user_login'))

    def test_chart_edit_out(self):
        "Testing /reports/chart/edit/<chart_id>"
        response = self.client.get(reverse('reports_chart_edit', args=[self.chart.id]))
        self.assertRedirects(response, reverse('user_login'))
        
    def test_chart_delete_out(self):
        "Testing /reports/chart/delete/<chart_id>"
        response = self.client.get(reverse('reports_chart_delete', args=[self.chart.id]))
        self.assertRedirects(response, reverse('user_login'))
        
        
    # Reports
    
    def test_report_add_out(self):
        "Testing /reports/report/add/"
        response = self.client.get(reverse('reports_report_add'))
        self.assertRedirects(response, reverse('user_login'))

    def test_report_view_out(self):
        "Testing /reports/report/view/<report_id>"
        response = self.client.get(reverse('reports_report_view', args=[self.report.id]))
        self.assertRedirects(response, reverse('user_login'))
        
    def test_report_edit_out(self):
        "Testing /reports/report/edit/<report_id>"
        response = self.client.get(reverse('reports_report_edit', args=[self.report.id]))
        self.assertRedirects(response, reverse('user_login'))
        
    def test_report_delete_out(self):
        "Testing /reports/report/delete/<report_id>"
        response = self.client.get(reverse('reports_report_delete', args=[self.report.id]))
        self.assertRedirects(response, reverse('user_login'))