# Path: brasilcomvc/projects/forms.py
# class ProjectSearchForm(forms.Form):
#     lat = forms.FloatField(widget=forms.HiddenInput())
#     lng = forms.FloatField(widget=forms.HiddenInput())
#     q = forms.CharField(label='')
#     radius = forms.IntegerField(required=False,
#             widget=forms.HiddenInput())
# 
#     def clean_radius(self):
#         cleaned_data = self.cleaned_data
# 
#         if 'radius' not in cleaned_data or not cleaned_data['radius']:
#             return 30
# 
#         return cleaned_data['radius']


from django.test import TestCase
from ..forms import ProjectSearchForm


class ProjectSearchFormTest(TestCase):

    def test_required(self):
        f = ProjectSearchForm({})
        self.assertFalse(f.is_valid())
        self.assertIn('q', f.errors)
        self.assertIn('lat', f.errors)
        self.assertIn('lng', f.errors)
        self.assertNotIn('radius', f.errors)

    def test_valid(self):
        f = ProjectSearchForm({
            'q': 'some place',
            'lat': '1.0',
            'lng': '1.0',
        })
        self.assertTrue(f.is_valid())

    def test_clean_radius_return_default_when_omitted(self):
        f = ProjectSearchForm({
            'q': 'some place',
            'lat': '1.0',
            'lng': '1.0',
        })
        self.assertTrue(f.is_valid())
        self.assertEquals(f.cleaned_data['radius'], 30)

    def test_clean_radius_return_received_value(self):

# Path: brasilcomvc/projects/forms.py
# class ProjectSearchForm(forms.Form):
#     lat = forms.FloatField(widget=forms.HiddenInput())
#     lng = forms.FloatField(widget=forms.HiddenInput())
#     q = forms.CharField(label='')
#     radius = forms.IntegerField(required=False,
#             widget=forms.HiddenInput())
# 
#     def clean_radius(self):
#         cleaned_data = self.cleaned_data
# 
#         if 'radius' not in cleaned_data or not cleaned_data['radius']:
#             return 30
# 
#         return cleaned_data['radius']


# Path: brasilcomvc/projects/tests/test_forms.py
from django.test import TestCase
from ..forms import ProjectSearchForm



class ProjectSearchFormTest(TestCase):

    def test_required(self):
        f = ProjectSearchForm({})
        self.assertFalse(f.is_valid())
        self.assertIn('q', f.errors)
        self.assertIn('lat', f.errors)
        self.assertIn('lng', f.errors)
        self.assertNotIn('radius', f.errors)

    def test_valid(self):
        f = ProjectSearchForm({
            'q': 'some place',
            'lat': '1.0',
            'lng': '1.0',
        })
        self.assertTrue(f.is_valid())

    def test_clean_radius_return_default_when_omitted(self):
        f = ProjectSearchForm({
            'q': 'some place',
            'lat': '1.0',
            'lng': '1.0',
        })
        self.assertTrue(f.is_valid())
        self.assertEquals(f.cleaned_data['radius'], 30)

    def test_clean_radius_return_received_value(self):

        f = ProjectSearchForm({