<commit_before>try:
    import unittest2 as unittest # Python2.6
except ImportError:
    import unittest

from tests.functional import test_base

class TestActivities(test_base.TestBase):
    testcase_name = "activity API"

    @unittest.skipIf(test_base.get_test_server_api() == 1,
                     "The activity/list endpoint behaves differenty at v1")
    def test_list(self):
        """
        Upload three photos, and check that three corresponding activities
        are created.
        """
        self._delete_all()
        self._create_test_photos(tag=False)
        photos = self.client.photos.list()

        # Check that each activity is for a valid test photo
        activities = self.client.activities.list()
        self.assertEqual(len(activities), len(photos))
        for activity in activities:
            self.assertIn(activity.data.id, [photo.id for photo in photos])

    def test_list_filter(self):
        """
        Check that the activity list filter parameter works correctly
        """
        self._delete_all()
        self._create_test_photos(tag=False)
        photos = self.client.photos.list()

        # Dummy photo update activity
        photos[0].update(tags=photos[0].tags)

        # Check that the activities can be filtered
        upload_activities = self.client.activities.list(filters={"type": "photo-upload"})
        update_activities = self.client.activities.list(filters={"type": "photo-update"})
        self.assertEqual(len(upload_activities), len(photos))
        self.assertEqual(len(update_activities), 1)

    # The purge endpoint currently reports a 500: Internal Server Error
    @unittest.expectedFailure
    def test_purge(self):
        """ Test that the purge endpoint deletes all activities """
        activities = self.client.activities.list()
        self.assertNotEqual(activities, [])
        self.client.activities.purge()
        self.assertEqual(activities, [])

    def test_view(self):
        """ Test that the view endpoint is working correctly """
        activity = self.client.activities.list()[0]
        fields = activity.get_fields().copy()

        # Check that the view method returns the same data as the list
        activity.view()
        self.assertEqual(fields, activity.get_fields())

        # Check using the Trovebox class
        activity = self.client.activity.view(activity)
        self.assertEqual(fields, activity.get_fields())

        # Check passing the activity ID to the Trovebox class
        activity = self.client.activity.view(activity.id)
        self.assertEqual(fields, activity.get_fields())<commit_msg>Finished activities/purge test, fails due to frontend/#1368<commit_after>try:
    import unittest2 as unittest # Python2.6
except ImportError:
    import unittest

from tests.functional import test_base

class TestActivities(test_base.TestBase):
    testcase_name = "activity API"

    @unittest.skipIf(test_base.get_test_server_api() == 1,
                     "The activity/list endpoint behaves differenty at v1")
    def test_list(self):
        """
        Upload three photos, and check that three corresponding activities
        are created.
        """
        self._delete_all()
        self._create_test_photos(tag=False)
        photos = self.client.photos.list()

        # Check that each activity is for a valid test photo
        activities = self.client.activities.list()
        self.assertEqual(len(activities), len(photos))
        for activity in activities:
            self.assertIn(activity.data.id, [photo.id for photo in photos])

    def test_list_filter(self):
        """
        Check that the activity list filter parameter works correctly
        """
        self._delete_all()
        self._create_test_photos(tag=False)
        photos = self.client.photos.list()

        # Dummy photo update activity
        photos[0].update(tags=photos[0].tags)

        # Check that the activities can be filtered
        upload_activities = self.client.activities.list(filters={"type": "photo-upload"})
        update_activities = self.client.activities.list(filters={"type": "photo-update"})
        self.assertEqual(len(upload_activities), len(photos))
        self.assertEqual(len(update_activities), 1)

    # The purge endpoint currently reports a 500: Internal Server Error
    # PHP Fatal error:
    #   Call to undefined method DatabaseMySql::postActivitiesPurge()
    #   in /var/www/openphoto-master/src/libraries/models/Activity.php
    #   on line 66
    # Tracked in frontend/#1368
    @unittest.expectedFailure
    def test_purge(self):
        """ Test that the purge endpoint deletes all activities """
        activities = self.client.activities.list()
        self.assertNotEqual(activities, [])
        self.client.activities.purge()
        activities = self.client.activities.list()
        self.assertEqual(activities, [])

    def test_view(self):
        """ Test that the view endpoint is working correctly """
        activity = self.client.activities.list()[0]
        fields = activity.get_fields().copy()

        # Check that the view method returns the same data as the list
        activity.view()
        self.assertEqual(fields, activity.get_fields())

        # Check using the Trovebox class
        activity = self.client.activity.view(activity)
        self.assertEqual(fields, activity.get_fields())

        # Check passing the activity ID to the Trovebox class
        activity = self.client.activity.view(activity.id)
        self.assertEqual(fields, activity.get_fields())
{'fraction_non_alphanumeric': 0.09690758719884933, 'fraction_numerical': 0.006112909025530385, 'mean_word_length': 2.8102739726027397, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '803472', 'n_tokens_mistral': 1531, 'n_tokens_neox': 1470, 'n_words': 389}