<commit_before># Test
from django.test import TestCase, Client

# App
from base.forms import AddProjectForm

# Utility
from django.core.urlresolvers import reverse

def form_errors(response):
    return response.context['form'].errors

class TestViews(TestCase):

    @classmethod
    def setUpClass(cls):
        cls.client = Client()


    @classmethod
    def get(view_name, *args, **kwargs):
        return self.client.get(reverse(view_name), *args, **kwargs)

    @classmethod
    def post(view_name, *args, **kwargs):
        return self.client.post(reverse(view_name), *args, **kwargs)


    def test_front_page(self):
        response = self.client.get('/', follow=True)
        assert 'base/index.html' in response.template_name


    def test_project_page(self):
        response = self.client.post(reverse('base:add_project'),
            follow=True)
        assert 'base/add_project.html' in response.template_name


    def test_add_project_no_name(self):
        response = self.client.post(reverse('base:add_project'),
            {'description': 'cats cats cats',
             'icon': 'fa-arrows'}, follow=True)
        assert 'This field is required.' in form_errors(response)['name']


    def test_add_project_no_description(self):
        response = self.client.post(reverse('base:add_project'),
            {'name': 'CATS!',
             'icon': 'fa-arrows'}, follow=True)
        assert 'This field is required.' in form_errors(response)['description']


    def test_add_project(self):
        response = self.client.post(reverse('base:add_project'),
            {'name': 'CATS!',
             'description': 'cats cats cats',
             'icon': 'fa-arrows'}, follow=True)
        assert 'base/index.html' in response.template_name
        assert b'CATS!' in response.content


class TestForms(TestCase):

    def test_project_form(self):
        form_data = {
            'name': 'CATS!',
            'description': 'cats cats cats',
            'icon': 'fa-arrows'}
        form = AddProjectForm(data=form_data)
        assert form.is_valid()
<commit_msg>Update unit tests: reverse url names<commit_after># Test
from django.test import TestCase, Client

# App
from base.forms import AddProjectForm

# Utility
from django.core.urlresolvers import reverse

def form_errors(response):
    return response.context['form'].errors

class TestViews(TestCase):

    @classmethod
    def setUpClass(cls):
        cls.client = Client()


    @classmethod
    def get(cls, view_name, *args, **kwargs):
        if 'slugs' in kwargs:
            slugs = kwargs.pop('slugs')
            return cls.client.get(
                reverse(view_name, kwargs=slugs),
                *args, follow=True, **kwargs)
        else:
            return cls.client.get(reverse(view_name),
                *args, follow=True, **kwargs)

    @classmethod
    def post(cls, view_name, *args, **kwargs):
        if 'slugs' in kwargs:
            slugs = kwargs.pop('slugs')
            return cls.client.post(
                reverse(view_name, kwargs=slugs),
                *args, follow=True, **kwargs)
        else:
            return cls.client.post(reverse(view_name),
                *args, follow=True, **kwargs)


    def test_front_page(self):
        response = self.get('base:index')
        assert 'base/index.html' in response.template_name


    def test_project_page(self):
        response = self.post('base:add_project')
        assert 'base/add_project.html' in response.template_name


    def test_add_project_no_name(self):
        response = self.post('base:add_project',
            {'description': 'cats cats cats',
             'icon': 'fa-arrows'})
        assert 'This field is required.' in form_errors(response)['name']


    def test_add_project_no_description(self):
        response = self.post('base:add_project',
            {'name': 'CATS!',
             'icon': 'fa-arrows'})
        assert 'This field is required.' in form_errors(response)['description']


    def test_add_project(self):
        response = self.post('base:add_project',
            {'name': 'CATS!',
             'description': 'cats cats cats',
             'icon': 'fa-arrows'})
        assert 'base/index.html' in response.template_name
        assert b'CATS!' in response.content


    def test_add_project_with_slug(self):
        self.test_add_project()

        response = self.get('base:project',
            slugs=dict(slug="cats"))
        assert 'base/project.html' in response.template_name


class TestForms(TestCase):

    def test_project_form(self):
        form_data = {
            'name': 'CATS!',
            'description': 'cats cats cats',
            'icon': 'fa-arrows'}
        form = AddProjectForm(data=form_data)
        assert form.is_valid()


    def test_project_form_no_name(self):
        form_data = {
            'description': 'cats cats cats',
            'icon': 'fa-arrows'}
        form = AddProjectForm(data=form_data)
        assert form.is_valid() is False
{'fraction_non_alphanumeric': 0.12435025989604158, 'fraction_numerical': 0.0, 'mean_word_length': 2.571020699500357, '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': '4418349', 'n_tokens_mistral': 1505, 'n_tokens_neox': 1451, 'n_words': 329}