Ejemplo n.º 1
0
class TestMultiseekSaveForm(RegistryMixin, TestCase):

    def setUp(self):
        RegistryMixin.setUp(self)
        self.msp = MultiseekSaveForm(registry=self.registry)
        self.msp.request = self.request

    def test_save_form_anon_user(self):
        res = self.msp.post(self.request)
        self.assertEquals(res.status_code, 403)

        self.assertEquals(self.msp.post, self.msp.get)

    def test_get_context_data(self):
        self.request.POST = {}
        
        self.request.POST['json'] = None
        self.assertEquals(
            self.msp.get_context_data(), 
            dict(result=unicode(ERR_NO_FORM_DATA)))
        
        self.request.POST['json'] = "wcale, nie, json"
        self.assertEquals(
            self.msp.get_context_data(),
            dict(result=unicode(ERR_PARSING_DATA)))
        
        self.request.POST['json'] = '[{"field": "foo", "bad": "field"}]'
        self.assertEquals(
            self.msp.get_context_data(),
            dict(result=unicode(ERR_LOADING_DATA)))
        
        self.request.POST['json'] = \
            '{"form_data": [{"field": "foo", "operation": "' \
            + unicode(EQUAL) \
            + '", "value": "foo"}]}'
        self.request.POST['name'] = ''
        self.assertEquals(
            self.msp.get_context_data(),
            dict(result=unicode(ERR_FORM_NAME)))

        sf = any_model(SearchForm, name='foo')
        self.request.POST['name'] = 'foo'
        self.assertEquals(
            self.msp.get_context_data(),
            dict(result=OVERWRITE_PROMPT))

        self.request.POST['overwrite'] = 'true'
        self.request.user = any_model(User)
        self.assertEquals(
            self.msp.get_context_data(),
            dict(result=SAVED, pk=1))

        self.assertEquals(SearchForm.objects.all().count(), 1)
        self.assertEquals(SearchForm.objects.all()[0].public, False)

        self.request.POST['public'] = 'true'
        self.msp.get_context_data()
        self.assertEquals(SearchForm.objects.all()[0].public, True)
Ejemplo n.º 2
0
class TestMultiseekSaveForm(RegistryMixin, TestCase):

    def setUp(self):
        RegistryMixin.setUp(self)
        self.msp = MultiseekSaveForm(registry=self.registry)
        self.msp.request = self.request

    def test_save_form_anon_user(self):
        res = self.msp.post(self.request)
        self.assertEquals(res.status_code, 403)

        self.assertEquals(self.msp.post, self.msp.get)

    def test_get_context_data(self):
        self.request.POST = {}
        
        self.request.POST['json'] = None
        self.assertEquals(
            self.msp.get_context_data(), 
            dict(result=unicode(ERR_NO_FORM_DATA)))
        
        self.request.POST['json'] = "wcale, nie, json"
        self.assertEquals(
            self.msp.get_context_data(),
            dict(result=unicode(ERR_PARSING_DATA)))
        
        self.request.POST['json'] = '[{"field": "foo", "bad": "field"}]'
        self.assertEquals(
            self.msp.get_context_data(),
            dict(result=unicode(ERR_LOADING_DATA)))
        
        self.request.POST['json'] = \
            '{"form_data": [{"field": "foo", "operation": "' \
            + unicode(EQUAL) \
            + '", "value": "foo"}]}'
        self.request.POST['name'] = ''
        self.assertEquals(
            self.msp.get_context_data(),
            dict(result=unicode(ERR_FORM_NAME)))

        sf = mommy.make(SearchForm, name='foo')
        self.request.POST['name'] = 'foo'
        self.assertEquals(
            self.msp.get_context_data(),
            dict(result=OVERWRITE_PROMPT))

        self.request.POST['overwrite'] = 'true'
        self.request.user = mommy.make(User)
        self.assertEquals(
            self.msp.get_context_data(),
            dict(result=SAVED, pk=1))

        self.assertEquals(SearchForm.objects.all().count(), 1)
        self.assertEquals(SearchForm.objects.all()[0].public, False)

        self.request.POST['public'] = 'true'
        self.msp.get_context_data()
        self.assertEquals(SearchForm.objects.all()[0].public, True)
Ejemplo n.º 3
0
 def setUp(self):
     RegistryMixin.setUp(self)
     self.msp = MultiseekSaveForm(registry=self.registry)
     self.msp.request = self.request
Ejemplo n.º 4
0
 def setUp(self):
     RegistryMixin.setUp(self)
     self.msp = MultiseekSaveForm(registry=self.registry)
     self.msp.request = self.request