<commit_before>from django.test import TransactionTestCase
from django.core.urlresolvers import reverse

from frontend.models import OrgBookmark
from frontend.models import User


class TestBookmarkViews(TransactionTestCase):
    fixtures = ['bookmark_alerts']

    def _get_bookmark_url_for_user(self):
        key = User.objects.get(username='bookmarks-user').profile.key
        return reverse('bookmark-login', kwargs={'key': key})

    def test_list_bookmarks_not_logged_in(self):
        response = self.client.get(reverse('bookmark-list'))
        self.assertContains(response, "You are not subscribed to any alerts")

    def test_list_bookmarks_logged_in(self):
        url = self._get_bookmark_url_for_user()
        response = self.client.get(url, follow=True)
        self.assertContains(
            response, "You are currently subscribed to 3 monthly alerts")

    def test_list_bookmarks_invalid_key(self):
        url = reverse('bookmark-login', kwargs={'key': 'broken'})
        response = self.client.get(url, follow=True)
        self.assertEqual(response.status_code, 403)

    def test_unsubscribe_one_by_one(self):
        # First, log in
        url = self._get_bookmark_url_for_user()
        self.client.get(url, follow=True)
        # There should be 2 bookmarks to get rid of
        for _ in range(3):
            data = {'org_bookmarks': [OrgBookmark.objects.first().pk]}
            response = self.client.post(
                reverse('bookmark-list'), data, follow=True)
            self.assertContains(
                response,
                "Unsubscribed from 1 alert")
        self.assertEqual(OrgBookmark.objects.count(), 1)

    def test_unsubscribe_all_at_once(self):
        # First, log in
        url = self._get_bookmark_url_for_user()
        self.client.get(url, follow=True)
        data = {'unsuball': 1}
        response = self.client.post(
            reverse('bookmark-list'), data, follow=True)
        self.assertContains(
            response,
            "Unsubscribed from 3 alerts")
        # There's one org bookmark which is unapproved, so they don't
        # see it in their list, and it doesn't get deleted.
        self.assertEqual(OrgBookmark.objects.count(), 2)<commit_msg>Remove hardcoded references to number of bookmark fixtures<commit_after>from django.test import TransactionTestCase
from django.core.urlresolvers import reverse

from frontend.models import OrgBookmark
from frontend.models import User


class TestBookmarkViews(TransactionTestCase):
    fixtures = ['bookmark_alerts']

    def _get_bookmark_url_for_user(self):
        key = User.objects.get(username='bookmarks-user').profile.key
        return reverse('bookmark-login', kwargs={'key': key})

    def test_list_bookmarks_not_logged_in(self):
        response = self.client.get(reverse('bookmark-list'))
        self.assertContains(response, "You are not subscribed to any alerts")

    def test_list_bookmarks_logged_in(self):
        url = self._get_bookmark_url_for_user()
        response = self.client.get(url, follow=True)
        self.assertContains(
            response, "You are currently subscribed to 3 monthly alerts")

    def test_list_bookmarks_invalid_key(self):
        url = reverse('bookmark-login', kwargs={'key': 'broken'})
        response = self.client.get(url, follow=True)
        self.assertEqual(response.status_code, 403)

    def test_unsubscribe_one_by_one(self):
        # First, log in
        url = self._get_bookmark_url_for_user()
        bookmark_count = OrgBookmark.objects.count()
        self.client.get(url, follow=True)
        # There should be 2 bookmarks to get rid of
        for _ in range(3):
            data = {'org_bookmarks': [OrgBookmark.objects.first().pk]}
            response = self.client.post(
                reverse('bookmark-list'), data, follow=True)
            self.assertContains(
                response,
                "Unsubscribed from 1 alert")
        self.assertEqual(OrgBookmark.objects.count(), bookmark_count - 3)

    def test_unsubscribe_all_at_once(self):
        # First, log in
        url = self._get_bookmark_url_for_user()
        bookmark_count = OrgBookmark.objects.count()
        self.client.get(url, follow=True)
        data = {'unsuball': 1}
        response = self.client.post(
            reverse('bookmark-list'), data, follow=True)
        self.assertContains(
            response,
            "Unsubscribed from 3 alerts")
        # There's one org bookmark which is unapproved, so they don't
        # see it in their list, and it doesn't get deleted.
        self.assertEqual(OrgBookmark.objects.count(), bookmark_count - 2)
{'fraction_non_alphanumeric': 0.09946409431939979, 'fraction_numerical': 0.004715969989281886, 'mean_word_length': 2.856198347107438, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '2398509', 'n_tokens_mistral': 1386, 'n_tokens_neox': 1328, 'n_words': 312}