Exemple #1
0
    def test_download_update_counter(self, mock_session, project, file_node):
        mock_session.data = {}
        resource = project.guids.first()
        PageCounter.update_counter(resource,
                                   file_node,
                                   version=None,
                                   action='download',
                                   node_info={})

        page_counter = PageCounter.objects.get(resource=resource,
                                               file=file_node,
                                               version=None,
                                               action='download')
        assert page_counter.total == 1
        assert page_counter.unique == 1

        PageCounter.update_counter(resource,
                                   file_node,
                                   version=None,
                                   action='download',
                                   node_info={})

        page_counter.refresh_from_db()
        assert page_counter.total == 2
        assert page_counter.unique == 1
Exemple #2
0
    def test_download_update_counter_contributor(self, mock_session, user, project, file_node):
        mock_session.data = {'auth_user_id': user._id}
        page_counter_id = 'download:{}:{}'.format(project._id, file_node.id)

        PageCounter.update_counter(page_counter_id, {'contributors': project.contributors})
        page_counter = PageCounter.objects.get(_id=page_counter_id)
        assert page_counter.total == 0
        assert page_counter.unique == 0

        PageCounter.update_counter(page_counter_id, {'contributors': project.contributors})

        page_counter.refresh_from_db()
        assert page_counter.total == 0
        assert page_counter.unique == 0
Exemple #3
0
    def test_download_update_counter_contributor(self, mock_session, user, project, file_node):
        mock_session.data = {'auth_user_id': user._id}
        page_counter_id = 'download:{}:{}'.format(project._id, file_node.id)

        PageCounter.update_counter(page_counter_id, {'contributors': project.contributors})
        page_counter = PageCounter.objects.get(_id=page_counter_id)
        assert page_counter.total == 0
        assert page_counter.unique == 0

        PageCounter.update_counter(page_counter_id, {'contributors': project.contributors})

        page_counter.refresh_from_db()
        assert page_counter.total == 0
        assert page_counter.unique == 0
Exemple #4
0
    def test_download_update_counter(self, mock_session, project, file_node):
        mock_session.data = {}
        page_counter_id = 'download:{}:{}'.format(project._id, file_node.id)

        PageCounter.update_counter(page_counter_id, {})

        page_counter = PageCounter.objects.get(_id=page_counter_id)
        assert page_counter.total == 1
        assert page_counter.unique == 1

        PageCounter.update_counter(page_counter_id, {})

        page_counter.refresh_from_db()
        assert page_counter.total == 2
        assert page_counter.unique == 1
Exemple #5
0
    def test_download_update_counter(self, mock_session, project, file_node):
        mock_session.data = {}
        page_counter_id = 'download:{}:{}'.format(project._id, file_node.id)

        PageCounter.update_counter(page_counter_id, {})

        page_counter = PageCounter.objects.get(_id=page_counter_id)
        assert page_counter.total == 1
        assert page_counter.unique == 1

        PageCounter.update_counter(page_counter_id, {})

        page_counter.refresh_from_db()
        assert page_counter.total == 2
        assert page_counter.unique == 1
Exemple #6
0
def update_counter(page, node_info=None):
    """Update counters for page.

    :param str page: Colon-delimited page key in analytics collection
    """
    from osf.models import PageCounter
    return PageCounter.update_counter(page, node_info)
Exemple #7
0
def update_counter(page, node_info=None):
    """Update counters for page.

    :param str page: Colon-delimited page key in analytics collection
    """
    from osf.models import PageCounter
    return PageCounter.update_counter(page, node_info)
Exemple #8
0
    def test_download_update_counter_contributor(self, mock_session, user,
                                                 project, file_node):
        mock_session.data = {'auth_user_id': user._id}
        resource = project.guids.first()

        PageCounter.update_counter(
            resource,
            file_node,
            version=None,
            action='download',
            node_info={'contributors': project.contributors})

        page_counter = PageCounter.objects.get(resource=resource,
                                               file=file_node,
                                               version=None,
                                               action='download')
        assert page_counter.total == 0
        assert page_counter.unique == 0

        PageCounter.update_counter(
            resource,
            file_node,
            version=None,
            action='download',
            node_info={'contributors': project.contributors})

        page_counter.refresh_from_db()
        assert page_counter.total == 0
        assert page_counter.unique == 0

        platform_group = OSFGroup.objects.create(creator=user, name='Platform')
        group_member = UserFactory()
        project.add_osf_group(platform_group)

        mock_session.data = {'auth_user_id': group_member._id}
        PageCounter.update_counter(
            resource,
            file_node,
            version=None,
            action='download',
            node_info={'contributors': project.contributors_and_group_members})
        page_counter.refresh_from_db()
        assert page_counter.total == 1
        assert page_counter.unique == 1

        platform_group.make_member(group_member)
        PageCounter.update_counter(
            resource,
            file_node,
            version=None,
            action='download',
            node_info={'contributors': project.contributors_and_group_members})
        assert page_counter.total == 1
        assert page_counter.unique == 1
    def get_events(self, date):
        super(DownloadCountSummary, self).get_events(date)

        timestamp_datetime = datetime(date.year, date.month, date.day).replace(tzinfo=pytz.UTC)
        return [{
                'keen': {
                    'timestamp': timestamp_datetime.isoformat()
                },
                'files': {
                    'total': int(PageCounter.get_all_downloads_on_date(timestamp_datetime) or 0)
                },
        }]
Exemple #10
0
    def test_get_all_downloads_on_date(self, page_counter, page_counter2):
        """
        This method tests that multiple pagecounter objects have their download totals summed properly.

        :param page_counter: represents a page_counter for a file node being downloaded
        :param page_counter2: represents a page_counter for another file node being downloaded
        """

        date = datetime(2018, 2, 4)

        total_downloads = PageCounter.get_all_downloads_on_date(date)

        assert total_downloads == 45
Exemple #11
0
    def test_get_all_downloads_on_date_exclude_versions(self, page_counter, page_counter2, page_counter_for_individual_version):
        """
        This method tests that individual version counts for file node's aren't "double counted" in the totals
        for a page counter. We don't add the file node's total to the versions total.

        :param page_counter: represents a page_counter for a file node being downloaded
        :param page_counter2: represents a page_counter for another file node being downloaded
        """
        date = datetime(2018, 2, 4)

        total_downloads = PageCounter.get_all_downloads_on_date(date)

        assert total_downloads == 45
Exemple #12
0
    def test_get_all_downloads_on_date(self, page_counter, page_counter2):
        """
        This method tests that multiple pagecounter objects have their download totals summed properly.

        :param page_counter: represents a page_counter for a file node being downloaded
        :param page_counter2: represents a page_counter for another file node being downloaded
        """

        date = datetime(2018, 2, 4)

        total_downloads = PageCounter.get_all_downloads_on_date(date)

        assert total_downloads == 45
Exemple #13
0
    def test_get_all_downloads_on_date_exclude_versions(self, page_counter, page_counter2, page_counter_for_individual_version):
        """
        This method tests that individual version counts for file node's aren't "double counted" in the totals
        for a page counter. We don't add the file node's total to the versions total.

        :param page_counter: represents a page_counter for a file node being downloaded
        :param page_counter2: represents a page_counter for another file node being downloaded
        """
        date = datetime(2018, 2, 4)

        total_downloads = PageCounter.get_all_downloads_on_date(date)

        assert total_downloads == 45
def update_counter(resource, file, version, action, node_info=None):
    """Update counters for resource.

    :param obj resource
    :param obj file
    :param int version
    :param str action, ex. 'download'
    """
    from osf.models import PageCounter
    return PageCounter.update_counter(resource,
                                      file,
                                      version=version,
                                      action=action,
                                      node_info=node_info)
    def get_events(self, date):
        super(DownloadCountSummary, self).get_events(date)

        timestamp_datetime = datetime(date.year, date.month,
                                      date.day).replace(tzinfo=pytz.UTC)
        return [{
            'keen': {
                'timestamp': timestamp_datetime.isoformat()
            },
            'files': {
                'total':
                int(
                    PageCounter.get_all_downloads_on_date(timestamp_datetime)
                    or 0)
            },
        }]
Exemple #16
0
def get_basic_counters(page):
    from osf.models import PageCounter
    return PageCounter.get_basic_counters(page)
Exemple #17
0
def get_basic_counters(page):
    from osf.models import PageCounter
    return PageCounter.get_basic_counters(page)
def get_basic_counters(resource, file, version, action):
    from osf.models import PageCounter
    return PageCounter.get_basic_counters(resource,
                                          file,
                                          version=version,
                                          action=action)