<commit_before>import json

from django.core.urlresolvers import reverse

from rest_framework import status

from bluebottle.test.factory_models.categories import CategoryFactory, CategoryContentFactory
from bluebottle.test.utils import BluebottleTestCase


class CategoriesTestCase(BluebottleTestCase):
    """
    Integration tests for the Categories API.
    """

    def setUp(self):
        super(CategoriesTestCase, self).setUp()
        self.init_projects()

    def test_partner_project(self):
        cat = {
            'title': 'Nice things',
            'description': 'Chit chat blah blah'
        }

        CategoryFactory.create(**cat)

        url = reverse('category-list')

        response = self.client.get(url)
        self.assertEquals(response.status_code, status.HTTP_200_OK)
        data = json.loads(response.content)
        self.assertEquals(len(data), 1)
        self.assertEquals(data[0]['title'], cat['title'])

        # Confirm that we can restrieve dutch titles too.
        response = self.client.get(url, {'language': 'nl'})
        self.assertEquals(response.status_code, status.HTTP_200_OK)
        data = json.loads(response.content)
        self.assertEquals(len(data), 1)
        self.assertEquals(data[0]['title'], cat['title'])

    def test_category_content(self):
        category_details = {
            'title': 'Nice things',
            'description': 'Chit chat blah blah'
        }

        category = CategoryFactory.create(**category_details)

        category_content = {
            'title': 'category content title',
            'description': 'category content description',
            'video_url': 'http://vimeo.com',
            'link_text': 'Find out more...',
            'link_url': 'http://link.com',
            'category': category
        }

        CategoryContentFactory.create(**category_content)

        url = reverse('category-detail', kwargs={'slug': category.slug})

        response = self.client.get(url)
        self.assertEquals(response.status_code, status.HTTP_200_OK)
        data = json.loads(response.content)
        self.assertEquals(data['contents'][0]['title'], 'category content title')
        self.assertEquals(data['contents'][0]['description'], 'category content description')
        self.assertEquals(data['contents'][0]['video_url'], 'http://vimeo.com')
        self.assertEquals(data['contents'][0]['link_text'], 'Find out more...')
        self.assertEquals(data['contents'][0]['link_url'], 'http://link.com')
        self.assertTrue(all(field in ('title', 'description', 'image', 'video_url', 'link_text', 'link_url')
                            for field in data['contents'][0].keys()
                            )
                        )<commit_msg>fix tests, add sequence field to api<commit_after>import json

from django.core.urlresolvers import reverse

from rest_framework import status

from bluebottle.test.factory_models.categories import CategoryFactory, CategoryContentFactory
from bluebottle.test.utils import BluebottleTestCase


class CategoriesTestCase(BluebottleTestCase):
    """
    Integration tests for the Categories API.
    """

    def setUp(self):
        super(CategoriesTestCase, self).setUp()
        self.init_projects()

    def test_partner_project(self):
        cat = {
            'title': 'Nice things',
            'description': 'Chit chat blah blah'
        }

        CategoryFactory.create(**cat)

        url = reverse('category-list')

        response = self.client.get(url)
        self.assertEquals(response.status_code, status.HTTP_200_OK)
        data = json.loads(response.content)
        self.assertEquals(len(data), 1)
        self.assertEquals(data[0]['title'], cat['title'])

        # Confirm that we can restrieve dutch titles too.
        response = self.client.get(url, {'language': 'nl'})
        self.assertEquals(response.status_code, status.HTTP_200_OK)
        data = json.loads(response.content)
        self.assertEquals(len(data), 1)
        self.assertEquals(data[0]['title'], cat['title'])

    def test_category_content(self):
        category_details = {
            'title': 'Nice things',
            'description': 'Chit chat blah blah'
        }

        category = CategoryFactory.create(**category_details)

        category_content = {
            'title': 'category content title',
            'description': 'category content description',
            'video_url': 'http://vimeo.com',
            'link_text': 'Find out more...',
            'link_url': 'http://link.com',
            'category': category
        }

        CategoryContentFactory.create(**category_content)

        url = reverse('category-detail', kwargs={'slug': category.slug})

        response = self.client.get(url)
        self.assertEquals(response.status_code, status.HTTP_200_OK)
        data = json.loads(response.content)
        self.assertEquals(data['contents'][0]['title'], 'category content title')
        self.assertEquals(data['contents'][0]['description'], 'category content description')
        self.assertEquals(data['contents'][0]['video_url'], 'http://vimeo.com')
        self.assertEquals(data['contents'][0]['link_text'], 'Find out more...')
        self.assertEquals(data['contents'][0]['link_url'], 'http://link.com')
        self.assertTrue(all(field in ('title', 'description', 'image', 'video_url', 'link_text', 'link_url', 'sequence')
                            for field in data['contents'][0].keys()
                            )
                        )
{'fraction_non_alphanumeric': 0.13499368345064067, 'fraction_numerical': 0.006857967875834687, 'mean_word_length': 2.719463087248322, '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': '3616006', 'n_tokens_mistral': 1523, 'n_tokens_neox': 1491, 'n_words': 301}