Пример #1
0
    def test_10_count_datasets_in_journal(self):
        dataset = self._create_package_resource(num_journals=13,
                                                resource=False)
        package = helpers.call_action('package_show',
                                      id=dataset[0]['id'],
                                      include_tracking=True)

        org = h.get_org(package['owner_org'])

        assert org['package_count'] == 13, "Should be 13 datasets: {}".format(
            org)
Пример #2
0
    def _test_12_create_email(self):
        dataset, resources = self._create_package_resource(num_resources=8,
                                                           resource=True,
                                                           num_journals=15)

        data = {
            'journal': 'Test Journal Title',
            'datasets': '15',
            'total_views': '57',
            'total_downloads': '20',
            'organization': h.get_org(dataset[0]['owner_org']),
        }

        email = h.create_email(data)
        assert 'Access Summary for Test Journal Title' in email, 'Didn\'t find title in email body'
Пример #3
0
    def _test_15_create_body(self):
        dataset, resources = self._create_package_resource(num_resources=8,
                                                           resource=True,
                                                           num_journals=15)

        data = {
            'journal': 'Test Journal Title',
            'datasets': '15',
            'total_views': '57',
            'total_downloads': '20',
            'organization': h.get_org(dataset[0]['owner_org']),
        }

        body = h.create_email(data)

        assert False, body
Пример #4
0
    def gather_data(self, engine, journal):
        org = h.get_org(journal)
        packages = org['packages']

        views_total = h.total_views_across_journal_datasets(
            packages[0]['owner_org'], engine_check=engine)
        downloads_total = h.total_downloads_journal(packages[0]['owner_org'],
                                                    engine_check=engine)

        views_monthly = h.last_month_views_across_journal_datasets(
            packages[0]['owner_org'], engine_check=engine)
        downloads_monthly = h.total_downloads_journal(packages[0]['owner_org'],
                                                      engine_check=engine,
                                                      monthly=True)

        package_list = []
        for package in packages:
            package_list.append(jc.Dataset(engine, package['id']))
            package_list = sorted(package_list,
                                  key=lambda x: x.views,
                                  reverse=True)

        num_resources = sum([len(p.resources) for p in package_list])

        summary = [['Datasets', 'Resources', 'Total Views', 'Total Downloads'],
                   [
                       len(packages), num_resources, views_total,
                       downloads_total
                   ]]

        data = {
            'prefix': config.get('ckan.site_url'),
            'journal': org['title'],
            'summary': summary,
            'packages_text': self.create_main_text(package_list),
            'packages': self.create_main_table(package_list),
            'package_num': len(packages),
            'package_resources': num_resources,
            'package_view_total': views_total,
            'package_download_total': downloads_total,
            'package_view_monthly': views_monthly,
            'package_download_monthly': downloads_monthly,
        }
        #'organization': h.get_org(packages[0]['owner_org']),
        return data
Пример #5
0
    def _test_13_create_email_template_full(self):
        count = 0
        dataset = self._create_package_resource(resource=False, num_journals=5)
        org = h.get_org(dataset[0]['owner_org'])
        packages = org['packages']

        # package 1 resources
        factories.Resource(package_id=packages[0]['id'],
                           url='http://package1/1')
        factories.Resource(package_id=packages[0]['id'],
                           url='http://package1/2')
        factories.Resource(package_id=packages[0]['id'],
                           url='http://package1/3')
        factories.Resource(package_id=packages[0]['id'],
                           url='http://package1/4')
        factories.Resource(package_id=packages[0]['id'],
                           url='http://package1/5')
        factories.Resource(package_id=packages[0]['id'],
                           url='http://package1/5',
                           format='')

        # package 2 resources
        factories.Resource(package_id=packages[1]['id'],
                           url='http://package2/1')
        factories.Resource(package_id=packages[1]['id'],
                           url='http://package2/2')
        factories.Resource(package_id=packages[1]['id'],
                           url='http://package2/3')

        # package 3 resources
        factories.Resource(package_id=packages[2]['id'],
                           url='http://package3/1')

        # package 4 resources
        factories.Resource(package_id=packages[3]['id'],
                           url='http://package4/1')
        factories.Resource(package_id=packages[3]['id'],
                           url='http://package4/2')

        # package 5 resources
        factories.Resource(package_id=packages[4]['id'],
                           url='http://package5/1')
        factories.Resource(package_id=packages[4]['id'],
                           url='http://package5/2')
        factories.Resource(package_id=packages[4]['id'],
                           url='http://package5/3')

        package1 = helpers.call_action('package_show',
                                       id=packages[0]['id'],
                                       include_tracking=True)
        package2 = helpers.call_action('package_show',
                                       id=packages[1]['id'],
                                       include_tracking=True)
        package3 = helpers.call_action('package_show',
                                       id=packages[2]['id'],
                                       include_tracking=True)
        package4 = helpers.call_action('package_show',
                                       id=packages[3]['id'],
                                       include_tracking=True)
        package5 = helpers.call_action('package_show',
                                       id=packages[4]['id'],
                                       include_tracking=True)

        # package/dataset views
        url1 = url_for(controller='package',
                       action='read',
                       id=package1['name'])
        url2 = url_for(controller='package',
                       action='read',
                       id=package2['name'])
        url3 = url_for(controller='package',
                       action='read',
                       id=package3['name'])
        url4 = url_for(controller='package',
                       action='read',
                       id=package4['name'])
        url5 = url_for(controller='package',
                       action='read',
                       id=package5['name'])

        for ip in ['44', '55', '66', '77', '88', '99']:
            self._post_to_tracking(url1, ip='111.222.333.{}'.format(ip))
            self._post_to_tracking(url2, ip='111.222.333.{}'.format(ip))
            self._post_to_tracking(url3, ip='111.222.333.{}'.format(ip))

        self._post_to_tracking(url4, ip='111.222.333.{}'.format(66))
        self._post_to_tracking(url4, ip='111.222.333.{}'.format(77))
        self._post_to_tracking(url4, ip='111.222.333.{}'.format(89))

        self._post_to_tracking(url5, ip='111.222.333.{}'.format(99))

        # access package1
        resources = helpers.call_action('package_show',
                                        id=package1['id'],
                                        include_tracking=True)['resources']
        url1 = resources[0]['url']
        url2 = resources[1]['url']
        url3 = resources[2]['url']
        url4 = resources[3]['url']
        url5 = resources[4]['url']

        for ip in ['44', '55', '66', '77', '88']:
            self._post_to_tracking(url1,
                                   ip='111.222.333.{}'.format(ip),
                                   type_='resource')
            self._post_to_tracking(url2,
                                   ip='111.222.333.{}'.format(ip),
                                   type_='resource')
            self._post_to_tracking(url3,
                                   ip='111.222.333.{}'.format(ip),
                                   type_='resource')
        self._post_to_tracking(url4,
                               ip='111.222.333.{}'.format(99),
                               type_='resource')
        self._post_to_tracking(url5,
                               ip='111.222.333.{}'.format(98),
                               type_='resource')

        # package2
        resources = resources = helpers.call_action(
            'package_show', id=package2['id'],
            include_tracking=True)['resources']
        url1 = resources[0]['url']
        url2 = resources[1]['url']
        url3 = resources[2]['url']

        for ip in ['44', '55', '66']:
            self._post_to_tracking(url1,
                                   ip='111.222.333.{}'.format(ip),
                                   type_='resource')
            self._post_to_tracking(url2,
                                   ip='111.222.333.{}'.format(ip),
                                   type_='resource')
            self._post_to_tracking(url3,
                                   ip='111.222.333.{}'.format(ip),
                                   type_='resource')

        # package3
        resources = helpers.call_action('package_show',
                                        id=package3['id'],
                                        include_tracking=True)['resources']
        url1 = resources[0]['url']
        self._post_to_tracking(url1,
                               ip='111.222.333.{}'.format(99),
                               type_='resource')

        # package 4
        resources = helpers.call_action('package_show',
                                        id=package4['id'],
                                        include_tracking=True)['resources']
        url1 = resources[0]['url']
        url2 = resources[1]['url']
        self._post_to_tracking(url1,
                               ip='111.222.333.{}'.format(99),
                               type_='resource')
        self._post_to_tracking(url1,
                               ip='111.222.333.{}'.format(55),
                               type_='resource')
        self._post_to_tracking(url2,
                               ip='111.222.333.{}'.format(99),
                               type_='resource')

        # package 5
        resources = helpers.call_action('package_show',
                                        id=package5['id'],
                                        include_tracking=True)['resources']
        url1 = resources[0]['url']
        url2 = resources[1]['url']
        url3 = resources[2]['url']

        for ip in ['44', '55', '66']:
            self._post_to_tracking(url1,
                                   ip='111.222.333.{}'.format(ip),
                                   type_='resource')
            self._post_to_tracking(url2,
                                   ip='111.222.333.{}'.format(ip),
                                   type_='resource')
            self._post_to_tracking(url3,
                                   ip='111.222.333.{}'.format(ip),
                                   type_='resource')
        self._post_to_tracking(url2,
                               ip='111.222.333.{}'.format(88),
                               type_='resource')
        self._post_to_tracking(url2,
                               ip='111.222.333.{}'.format(99),
                               type_='resource')

        self._update_tracking_summary()

        views = h.total_views_across_journal_datasets(package1['owner_org'])
        downloads = h.total_downloads_journal(package1['owner_org'])

        data = {
            'journal': org['title'],
            'datasets': len(packages),
            'total_views': views,
            'total_downloads': downloads,
            'organization': h.get_org(dataset[0]['owner_org']),
        }

        email = h.create_email(data)

        assert data[
            'journal'] == 'Test Organization', 'Wrong title: {}'.format(
                data['journal'])

        assert int(data['datasets']) == 5, 'Should be 5, {}'.format(
            data['datasets'])
        assert int(data['total_views']) == 22, 'Should be 22, {}'.format(
            data['total_views'])
        assert int(data['total_downloads']) == 41, 'Should be 41, {}'.format(
            data['total_downloads'])

        assert "<a href='/dataset/test_dataset_0'><span class=\"label label-published\">" in email
        assert "<a href='/dataset/test_dataset_1'><span class=\"label label-important\">" in email

        assert False, email