Exemple #1
0
class TestEnsureLogDates(OsfTestCase):

    def setUp(self):
        super(TestEnsureLogDates, self).setUp()
        self.good_log = NodeLogFactory(action=NodeLog.WIKI_DELETED)
        self.bad_log = NodeLogFactory(action=NodeLog.WIKI_DELETED)

        self.mongo = self.good_log._storage[0].db['nodelog']

        self.mongo.update(
            {'_id': self.bad_log._id},
            {'$set': {'date': timezone.now() - datetime.timedelta(weeks=52)}},
        )
        self.bad_log.reload()

    def tearDown(self):
        super(TestEnsureLogDates, self).tearDown()

    def test_find_invalid_logs(self):
        assert_equal(
            1,
            len(list(find_invalid_logs()))
        )

    def test_fix_invalid_log(self):
        fix_invalid_log(self.bad_log)
        assert_true(
            self.good_log.date - self.bad_log.date < datetime.timedelta(seconds=1)
        )
Exemple #2
0
class TestEnsureLogDates(OsfTestCase):
    def setUp(self):
        super(TestEnsureLogDates, self).setUp()
        self.good_log = NodeLogFactory(action=NodeLog.WIKI_DELETED)
        self.bad_log = NodeLogFactory(action=NodeLog.WIKI_DELETED)

        self.mongo = self.good_log._storage[0].db['nodelog']

        self.mongo.update(
            {'_id': self.bad_log._id},
            {
                '$set': {
                    'date':
                    datetime.datetime.utcnow() - datetime.timedelta(weeks=52)
                }
            },
        )
        self.bad_log.reload()

    def tearDown(self):
        super(TestEnsureLogDates, self).tearDown()

    def test_find_invalid_logs(self):
        assert_equal(1, len(list(find_invalid_logs())))

    def test_fix_invalid_log(self):
        fix_invalid_log(self.bad_log)
        assert_true(self.good_log.date -
                    self.bad_log.date < datetime.timedelta(seconds=1))
Exemple #3
0
 def test_fix_node_param_for_embargo_approved_no_user_log(self):
     project = ProjectFactory()
     registration = RegistrationFactory(project=project)
     embargo_approved_log = NodeLogFactory(action=NodeLog.EMBARGO_APPROVED, params={'node': registration._id})
     fix_embargo_approved_logs([embargo_approved_log])
     embargo_approved_log.reload()
     assert_equal(embargo_approved_log.params['node'], project._id)
     assert_equal(embargo_approved_log.params['registration'], registration._id)
Exemple #4
0
class TestNodeLogAnalytics(OsfTestCase):
    def setUp(self):
        super(TestNodeLogAnalytics, self).setUp()

        self.user_one = UserFactory()
        self.user_two = UserFactory()

        # Two node logs for user one
        self.node_log_node_created = NodeLogFactory(action='node_created',
                                                    user=self.user_one)
        self.node_log_file_added = NodeLogFactory(action='file_added',
                                                  user=self.user_one)

        # Two node logs for user two
        self.node_log_wiki_updated = NodeLogFactory(action='wiki_updated',
                                                    user=self.user_two)
        self.node_log_project_created = NodeLogFactory(
            action='project_created', user=self.user_two)

        self.end_date = datetime.datetime.utcnow() - datetime.timedelta(1)

        for node_log in NodeLog.find():
            node_log.date = self.end_date - datetime.timedelta(0.1)
            node_log.save()

        self.results = NodeLogEvents().get_events(self.end_date.date())

        self.node_log_node_created.reload()
        self.node_log_file_added.reload()
        self.node_log_wiki_updated.reload()
        self.node_log_project_created.reload()

    def tearDown(self):
        super(TestNodeLogAnalytics, self).tearDown()
        Node.remove()
        User.remove()

    def test_results_structure(self):
        expected = [{
            'keen': {
                'timestamp':
                self.node_log_node_created.date.replace(
                    tzinfo=pytz.UTC).isoformat()
            },
            'date':
            self.node_log_node_created.date.replace(
                tzinfo=pytz.UTC).isoformat(),
            'action':
            'node_created',
            'user_id':
            self.user_one._id
        }, {
            'keen': {
                'timestamp':
                self.node_log_file_added.date.replace(
                    tzinfo=pytz.UTC).isoformat()
            },
            'date':
            self.node_log_file_added.date.replace(tzinfo=pytz.UTC).isoformat(),
            'action':
            'file_added',
            'user_id':
            self.user_one._id
        }, {
            'keen': {
                'timestamp':
                self.node_log_wiki_updated.date.replace(
                    tzinfo=pytz.UTC).isoformat()
            },
            'date':
            self.node_log_wiki_updated.date.replace(
                tzinfo=pytz.UTC).isoformat(),
            'action':
            'wiki_updated',
            'user_id':
            self.user_two._id
        }, {
            'keen': {
                'timestamp':
                self.node_log_project_created.date.replace(
                    tzinfo=pytz.UTC).isoformat()
            },
            'date':
            self.node_log_project_created.date.replace(
                tzinfo=pytz.UTC).isoformat(),
            'action':
            'project_created',
            'user_id':
            self.user_two._id
        }]

        assert_items_equal(expected, self.results)
class TestNodeLogAnalytics(OsfTestCase):

    def setUp(self):
        super(TestNodeLogAnalytics, self).setUp()

        self.user_one = UserFactory()
        self.user_two = UserFactory()

        # Two node logs for user one
        self.node_log_node_created = NodeLogFactory(action='node_created', user=self.user_one)
        self.node_log_file_added = NodeLogFactory(action='file_added', user=self.user_one)

        # Two node logs for user two
        self.node_log_wiki_updated = NodeLogFactory(action='wiki_updated', user=self.user_two)
        self.node_log_project_created = NodeLogFactory(action='project_created', user=self.user_two)

        self.end_date = datetime.datetime.utcnow() - datetime.timedelta(1)

        for node_log in NodeLog.find():
            node_log.date = self.end_date - datetime.timedelta(0.1)
            node_log.save()

        self.results = NodeLogEvents().get_events(self.end_date.date())

        self.node_log_node_created.reload()
        self.node_log_file_added.reload()
        self.node_log_wiki_updated.reload()
        self.node_log_project_created.reload()

    def tearDown(self):
        super(TestNodeLogAnalytics, self).tearDown()
        Node.remove()
        User.remove()

    def test_results_structure(self):
        expected = [
            {
                'keen': {'timestamp': self.node_log_node_created.date.replace(tzinfo=pytz.UTC).isoformat()},
                'date': self.node_log_node_created.date.replace(tzinfo=pytz.UTC).isoformat(),
                'action': 'node_created',
                'user_id': self.user_one._id
            },
            {
                'keen': {'timestamp': self.node_log_file_added.date.replace(tzinfo=pytz.UTC).isoformat()},
                'date': self.node_log_file_added.date.replace(tzinfo=pytz.UTC).isoformat(),
                'action': 'file_added',
                'user_id': self.user_one._id
            },
            {
                'keen': {'timestamp': self.node_log_wiki_updated.date.replace(tzinfo=pytz.UTC).isoformat()},
                'date': self.node_log_wiki_updated.date.replace(tzinfo=pytz.UTC).isoformat(),
                'action': 'wiki_updated',
                'user_id': self.user_two._id
            },
            {
                'keen': {'timestamp': self.node_log_project_created.date.replace(tzinfo=pytz.UTC).isoformat()},
                'date': self.node_log_project_created.date.replace(tzinfo=pytz.UTC).isoformat(),
                'action': 'project_created',
                'user_id': self.user_two._id
            }
        ]

        assert_items_equal(expected, self.results)