Exemple #1
0
    def test_stats_actions(self):
        """
        Testing statistics functions about LR
        """
        statsdata = getLRLast(UPDATE_STAT, 2)
        self.assertEqual(len(statsdata), 0)
        
        resources =  resourceInfoType_model.objects.all()
        for resource in resources:
            for action in (VIEW_STAT, RETRIEVE_STAT, DOWNLOAD_STAT):
                saveLRStats(resource, action)
                self.assertEqual(len(getLRLast(action, 10)), 0)

        # change the status in published
        client = Client()
        client.login(username='******', password='******')
        resources =  resourceInfoType_model.objects.all()
        for resource in resources:
            resource.storage_object.publication_status = INGESTED
            resource.storage_object.save()
            client.post(ADMINROOT,
            {"action": "publish_action", ACTION_CHECKBOX_NAME: resource.id},
            follow=True)
        
        for i in range(0, 2):
            resource = resourceInfoType_model.objects.get(pk=resources[i].pk)
            for action in (VIEW_STAT, RETRIEVE_STAT, DOWNLOAD_STAT):
                saveLRStats(resource, action)
                self.assertEqual(len(getLRLast(action, 10)), i+1)
Exemple #2
0
    def test_stats_actions(self):
        """
        Testing statistics functions about LR
        """
        statsdata = getLRLast(UPDATE_STAT, 2)
        self.assertEqual(len(statsdata), 0)

        resources = resourceInfoType_model.objects.all()
        for resource in resources:
            for action in (VIEW_STAT, RETRIEVE_STAT, DOWNLOAD_STAT):
                saveLRStats(resource, action)
                self.assertEqual(len(getLRLast(action, 10)), 0)

        # change the status in published
        client = Client()
        client.login(username='******', password='******')
        resources = resourceInfoType_model.objects.all()
        for resource in resources:
            resource.storage_object.publication_status = INGESTED
            resource.storage_object.save()
            client.post(ADMINROOT, {
                "action": "publish_action",
                ACTION_CHECKBOX_NAME: resource.id
            },
                        follow=True)
        for i in range(0, 2):
            resource = resourceInfoType_model.objects.get(pk=resources[i].pk)
            for action in (VIEW_STAT, RETRIEVE_STAT, DOWNLOAD_STAT):
                saveLRStats(resource, action)
                self.assertEqual(len(getLRLast(action, 10)), i + 1)
Exemple #3
0
    def test_my_resources(self):
        client = Client()
        client.login(username='******', password='******')
        resources =  resourceInfoType_model.objects.all()
        for resource in resources:
            resource.storage_object.publication_status = INGESTED
            resource.storage_object.save()
            client.post(ADMINROOT, \
                {"action": "publish_action", ACTION_CHECKBOX_NAME: resource.id}, \
                follow=True)
            url = resource.get_absolute_url()
            response = client.get(url, follow = True)
            self.assertTemplateUsed(response,
                'repository/resource_view/lr_view.html')
        
        statsdata = getLRLast(VIEW_STAT, 10)
        self.assertEqual(2, len(statsdata))

        response = client.get('/{0}stats/top/'.format(DJANGO_BASE))
        self.assertNotContains(response, ">No data found<")
        self.assertContains(response, ">My resources<")
        
        response = client.get('/{0}stats/mystats/'.format(DJANGO_BASE))
        self.assertTemplateUsed(response, 'stats/mystats.html')
        self.assertContains(response, "Resource name")

        
        # make sure delete a resource from storage_object.deleted may delete any part of its statistics:
        # delete the second resource
        resource = resourceInfoType_model.objects.all()[0]
        resource.delete_deep()        
        #resource.storage_object.delete()
        statsdata = getLRLast(VIEW_STAT, 10)
        self.assertEqual(1, len(statsdata))
        
        response = client.get('/{0}stats/usage/'.format(DJANGO_BASE))
        self.assertContains(response, "Metadata usage in 1 resource")

        #delete the first resource
        resource = resourceInfoType_model.objects.all()[0]
        resource.delete_deep()        
        statsdata = getLRLast(VIEW_STAT, 10)
        self.assertEqual(0, len(statsdata))

        response = client.get('/{0}stats/mystats/'.format(DJANGO_BASE))
        self.assertContains(response, ">No data found<")
        response = client.get('/{0}stats/top/'.format(DJANGO_BASE))
        self.assertContains(response, ">No data found<")
Exemple #4
0
    def test_usage(self):
        # checking if there are the usage statistics
        client = Client()
        response = client.get('/{0}stats/top/'.format(DJANGO_BASE))
        self.assertTemplateUsed(response, 'stats/topstats.html')
        self.assertContains(response, "META-SHARE node visits statistics")
        self.assertNotContains(response, "identificationInfo")
        
        client.login(username='******', password='******')
        resources =  resourceInfoType_model.objects.all()
        for resource in resources:
            resource.storage_object.publication_status = INGESTED
            resource.storage_object.save()
            client.post(ADMINROOT,
            {"action": "publish_action", ACTION_CHECKBOX_NAME: resource.id},
            follow=True)
        
        statsdata = getLRLast(UPDATE_STAT, 2)
        self.assertEqual(len(statsdata), 2)
        response = client.get('/{0}stats/usage/'.format(DJANGO_BASE))
        self.assertContains(response, "Metadata usage in 2 resources")

        response = client.post('/{0}stats/usage/'.format(DJANGO_BASE), {'model': 'identificationInfoType_model',
                'class': 'identificationInfoType_model', 'field': 'resourceName'})
        self.assertContains(response, "div id=fieldvalues")
        
        # remove all usage stats and check if there is the updating automatically
        UsageStats.objects.all().delete()
        # the usage stats are build from scratch calling update_usage_stats
        # UsageThread threads does not work, it eraised a "database is locked" exception
        for resource in resources:
            if not UsageStats.objects.filter(lrid=resource.storage_object.identifier).exists():
                update_usage_stats(resource.storage_object.identifier, resource.export_to_elementtree())
        response = client.get('/{0}stats/usage/'.format(DJANGO_BASE))
        self.assertContains(response, "Metadata usage in 2 resources")
Exemple #5
0
    def test_my_resources(self):
        client = Client()
        client.login(username='******', password='******')
        resources = resourceInfoType_model.objects.all()
        for resource in resources:
            resource.storage_object.publication_status = INGESTED
            resource.storage_object.save()
            client.post(ADMINROOT, \
                {"action": "publish_action", ACTION_CHECKBOX_NAME: resource.id}, \
                follow=True)
            url = resource.get_absolute_url()
            response = client.get(url, follow=True)
            self.assertTemplateUsed(response,
                                    'repository/resource_view/lr_view.html')

        statsdata = getLRLast(VIEW_STAT, 10)
        self.assertEqual(2, len(statsdata))

        response = client.get('/{0}stats/top/'.format(DJANGO_BASE))
        self.assertNotContains(response, ">No data found<")
        self.assertContains(response, ">My resources<")

        response = client.get('/{0}stats/mystats/'.format(DJANGO_BASE))
        self.assertTemplateUsed(response, 'stats/mystats.html')
        self.assertContains(response, "Resource name")

        # make sure delete a resource from storage_object.deleted may delete any part of its statistics:
        # delete the second resource
        resource = resourceInfoType_model.objects.all()[0]
        resource.delete_deep()
        #resource.storage_object.delete()
        statsdata = getLRLast(VIEW_STAT, 10)
        self.assertEqual(1, len(statsdata))

        response = client.get('/{0}stats/usage/'.format(DJANGO_BASE))
        self.assertContains(response, "Metadata usage in 1 resource")

        #delete the first resource
        resource = resourceInfoType_model.objects.all()[0]
        resource.delete_deep()
        statsdata = getLRLast(VIEW_STAT, 10)
        self.assertEqual(0, len(statsdata))

        response = client.get('/{0}stats/mystats/'.format(DJANGO_BASE))
        self.assertContains(response, ">No data found<")
        response = client.get('/{0}stats/top/'.format(DJANGO_BASE))
        self.assertContains(response, ">No data found<")
Exemple #6
0
 def testStatActions(self):
     """
     Testing statistics functions about LR
     """
     lrid = "00000000"
     for action in (UPDATE_STAT, VIEW_STAT, RETRIEVE_STAT, DOWNLOAD_STAT):
         saveLRStats("anonymous", lrid, "", action)
         self.assertEqual(len(getLRLast(action, 10)), 1)
Exemple #7
0
 def testStatActions(self):
     """
     Testing statistics functions about LR
     """
     client = self.client_with_user_logged_in(StatsTest.editor_login)
     xmlfile = open(TESTFIXTURES_ZIP, 'rb')
     response = client.post(ADMINROOT+'upload_xml/', {'description': xmlfile, 'uploadTerms':'on' }, follow=True)
     # And verify that we have more than zero resources on the page where we
     # are being redirected:
     self.assertContains(response, "Editable Resources")
     self.assertNotContains(response, '0 Resources')
     
     statsdata = getLRLast(UPDATE_STAT, 2)
     self.assertEqual(len(statsdata), 2)
     
     for action in (VIEW_STAT, RETRIEVE_STAT, DOWNLOAD_STAT):
         for item in statsdata:
             resource =  resourceInfoType_model.objects.get(storage_object__identifier=item['lrid'])
             saveLRStats(resource, "anonymous", "", action)
         self.assertEqual(len(getLRLast(action, 10)), 2)
Exemple #8
0
 def test_my_resources(self):
     client = Client()
     client.login(username='******', password='******')
     resources =  resourceInfoType_model.objects.all()
     for resource in resources:
         resource.storage_object.publication_status = INGESTED
         resource.storage_object.save()
         client.post(ADMINROOT,
         {"action": "publish_action", ACTION_CHECKBOX_NAME: resource.id},
         follow=True)
         url = resource.get_absolute_url()
         response = client.get(url, follow = True)
         self.assertTemplateUsed(response, 'repository/lr_view.html')
     
     statsdata = getLRLast(VIEW_STAT, 10)
     self.assertEqual(2, len(statsdata))
     
     #delete the second resource
     resource = resourceInfoType_model.objects.get(pk=1)
     resource.delete_deep()        
     statsdata = getLRLast(VIEW_STAT, 10)
     self.assertEqual(1, len(statsdata))
Exemple #9
0
    def test_usage(self):
        # checking if there are the usage statistics
        client = Client()
        # only admins can access statistics
        client.login(username='******', password='******')
        response = client.get('/{0}stats/top/'.format(DJANGO_BASE))
        self.assertTemplateUsed(response, 'stats/topstats.html')
        #self.assertContains(response, "ELRC-SHARE visits statistics")
        self.assertContains(response, "ELRI visits statistics")
        self.assertNotContains(response, "identificationInfo")

        client.login(username='******', password='******')
        resources = resourceInfoType_model.objects.all()
        for resource in resources:
            resource.storage_object.publication_status = INGESTED
            resource.storage_object.save()
            client.post(ADMINROOT, {
                "action": "publish_action",
                ACTION_CHECKBOX_NAME: resource.id
            },
                        follow=True)

        statsdata = getLRLast(UPDATE_STAT, 2)
        self.assertEqual(len(statsdata), 2)
        response = client.get('/{0}stats/usage/'.format(DJANGO_BASE))
        self.assertContains(response, "Metadata usage in 2 resources")

        response = client.post(
            '/{0}stats/usage/'.format(DJANGO_BASE), {
                'model': 'identificationInfoType_model',
                'class': 'identificationInfoType_model',
                'field': 'resourceName'
            })
        self.assertContains(response, "div id=fieldvalues")

        # remove all usage stats and check if there is the updating automatically
        UsageStats.objects.all().delete()
        # the usage stats are build from scratch calling update_usage_stats
        # UsageThread threads does not work, it eraised a "database is locked" exception
        for resource in resources:
            if not UsageStats.objects.filter(
                    lrid=resource.storage_object.identifier).exists():
                update_usage_stats(resource.storage_object.identifier,
                                   resource.export_to_elementtree())
        response = client.get('/{0}stats/usage/'.format(DJANGO_BASE))
        self.assertContains(response, "Metadata usage in 2 resources")
Exemple #10
0
 def testUsage(self):
     # checking if there are the usage statistics
     
     client = self.client_with_user_logged_in(StatsTest.editor_login)
     xmlfile = open(TESTFIXTURES_ZIP, 'rb')
     response = client.post(ADMINROOT+'upload_xml/', {'description': xmlfile, 'uploadTerms':'on' }, follow=True)
     
     statsdata = getLRLast(UPDATE_STAT, 2)
     self.assertEqual(len(statsdata), 2)
     
     for item in statsdata:
         resource =  resourceInfoType_model.objects.get(storage_object__identifier=item['lrid'])
         _update_usage_stats(resource.id, resource.export_to_elementtree())
         
     response = client.get('/{0}stats/usage'.format(DJANGO_BASE))
     if response.status_code != 200:
         print Exception, 'could not get usage stats: {}'.format(response)
     else:
         self.assertContains(response, "identificationInfo")
Exemple #11
0
 def test_usage(self):
     # checking if there are the usage statistics
     client = Client()
     response = client.get('/{0}stats/top/'.format(DJANGO_BASE))
     self.assertTemplateUsed(response, 'stats/topstats.html')
     self.assertContains(response, "META-SHARE node visits statistics")
     self.assertNotContains(response, "identificationInfo")
     
     client.login(username='******', password='******')
     resources =  resourceInfoType_model.objects.all()
     for resource in resources:
         resource.storage_object.publication_status = INGESTED
         resource.storage_object.save()
         client.post(ADMINROOT,
         {"action": "publish_action", ACTION_CHECKBOX_NAME: resource.id},
         follow=True)
     
     statsdata = getLRLast(UPDATE_STAT, 2)
     self.assertEqual(len(statsdata), 2)
                     
     response = client.get('/{0}stats/usage/'.format(DJANGO_BASE))
     self.assertContains(response, "identificationInfo")
Exemple #12
0
def topstats (request):
    """ viewing statistics about the top LR and latest queries. """
    topdata = []
    view = request.GET.get('view', 'topviewed')
    if view == "topviewed":
        data = getLRTop(VIEW_STAT, 10)
        for item in data:
            try:
                res_info =  resourceInfoType_model.objects.get(storage_object__identifier=item['lrid'])
                topdata.append([res_info.id, res_info.get_absolute_url, item['sum_count'], res_info])
            except: 
                LOGGER.debug("Warning! The object "+item['lrid']+ " has not been found.")
                
    if (view == "latestupdated"):
        data = getLRLast(UPDATE_STAT, 10)
        for item in data:
            try:
                res_info =  resourceInfoType_model.objects.get(storage_object__identifier=item['lrid'])
                topdata.append([res_info.id,  res_info.get_absolute_url, pretty_timeago(item['lasttime']), res_info])
            except: 
                LOGGER.debug("Warning! The object "+item['lrid']+ " has not been found.")
    if (view == "topdownloaded"):
        data = getLRTop(DOWNLOAD_STAT, 10)
        for item in data:
            try:
                res_info =  resourceInfoType_model.objects.get(storage_object__identifier=item['lrid'])
                topdata.append([res_info.id, res_info.get_absolute_url, item['sum_count'], res_info])
            except: 
                LOGGER.debug("Warning! The object "+item['lrid']+ " has not been found.")

    if view == "latestqueries":
        data = getLastQuery(10)
        for item in data:
            query = urllib.unquote(item['query'])
            topdata.append([query, pretty_timeago(item['lasttime']), item['found']])       
             
    return render_to_response('stats/topstats.html',
        {'user': request.user, 'topdata': topdata[:10], 'view': view},
        context_instance=RequestContext(request))