Beispiel #1
0
    def test_user_edit_view_no_matchdict(self):
        """
        user edit view -- matchdict test & redirect

        if matchdict is invalid, expect redirect
        """
        from c3sar.views.user import user_edit
        request = testing.DummyRequest()
        self.config = testing.setUp(request=request)
        _registerRoutes(self.config)
        instance = self._makeUser()
        self.dbsession.add(instance)
        self.dbsession.flush()
        result = user_edit(request)

        # test: a redirect is triggered iff no matchdict
        self.assertTrue(isinstance(result, HTTPFound), 'no redirect seen')
        self.assertTrue('not_found' in str(result.headers),
                        'not redirecting to not_found')

        # and one more with faulty matchdict
        request = testing.DummyRequest()
        self.config = testing.setUp(request=request)
        _registerRoutes(self.config)
        request.matchdict['user_id'] = 'foo'
        result = user_edit(request)
        # test: a redirect is triggered iff matchdict faulty
        self.assertTrue(isinstance(result, HTTPFound), 'no redirect seen')
        self.assertTrue('not_found' in str(result.headers),
                        'not redirecting to not_found')
Beispiel #2
0
    def test_user_edit_submitted_invalid_email(self):
        """
        user edit view -- without validating the form
        """
        from c3sar.views.user import user_edit
        request = testing.DummyRequest(
            post={
                'form.submitted': True,
                'username': u'bar',
                'password': u'passfoo',
                'confirm_password': u'passfoo',
                'city': u'foocity',
                'surname': u'surfooname',
                'lastname': u'lastfooname',
                'number': u'foonumber',
                'phone': u'foophone',
                'street': u'foostreet',
                'postcode': u'foocode',
                'country': u'fooland',
                'email': u'example.com',  # <---------- invalid
                'fax': '',
                })
        self.config = testing.setUp(request=request)
        instance = self._makeUser()
        self.dbsession.add(instance)
        self.dbsession.flush()
        request.matchdict['user_id'] = instance.id
        result = user_edit(request)
        #print "submitted invalid email: "
        #pp.pprint(result)
        # self.assertEquals(result['user'].username, instance.username)
        #print  result['form'].form.errors

        self.assertTrue(not result['form'].form.validate(),
                        "the form should not have validated!")
        #import pdb
        #pdb.set_trace()

        # test: unknown username
        self.assertEquals(
             result['form'].form.errors,
             {'email': u'An email address must contain a single @'},
             "unexpected error message was found")
Beispiel #3
0
 def test_user_edit_non_validating(self):
     """
     user edit view -- without validating the form
     """
     from c3sar.views.user import user_edit
     request = testing.DummyRequest()
     request.POST = {'username': "******"}
     self.config = testing.setUp(request=request)
     instance = self._makeUser()
     self.dbsession.add(instance)
     self.dbsession.flush()
     request.matchdict['user_id'] = instance.id
     result = user_edit(request)
     #print "user edit view -- without validating"
     #pp.pprint(result)
     # test: no errors
     self.assertEquals(
          result['form'].form.errors, {},
          "unexpected error message was found")
Beispiel #4
0
    def test_user_edit_submitted_non_validating(self):
        """
        user edit view -- without validating the form
        """
        from c3sar.views.user import user_edit
        request = testing.DummyRequest(
            post={
                'form.submitted': True,
                'username': u' ',  # <-- can't be edited anyways
                'password': u'passfoo',
                'confirm_password': u'passfoo',
                'city': u'foocity',
                'surname': u'',
                'lastname': u'lastfooname',
                'number': u'foonumber',
                'phone': u'foophone',
                'street': u'foostreet',
                'postcode': u'foocode',
                'country': u'fooland',
                'email': u'*****@*****.**',
                'fax': '',
                })
        self.config = testing.setUp(request=request)
        instance = self._makeUser()
        self.dbsession.add(instance)
        self.dbsession.flush()
        request.matchdict['user_id'] = instance.id
        result = user_edit(request)
        #print "submitted non validating: "
        #pp.pprint(result)
        # self.assertEquals(result['user'].username, instance.username)
        #print  result['form'].form.errors

        # self.assertTrue(result['form'].form.is_validated,
        #                "form not validated?")
        #import pdb
        #pdb.set_trace()

        # test: empty surname --> validation error
        self.assertEquals(
             result['form'].form.errors, {'surname': u'Please enter a value'},
             "unexpected error message was found")
Beispiel #5
0
 def test_user_edit_view(self):
     """
     user edit view -- test return values
     """
     from c3sar.views.user import user_edit
     request = testing.DummyRequest()
     self.config = testing.setUp(request=request)
     instance = self._makeUser()
     self.dbsession.add(instance)
     self.dbsession.flush()
     request.matchdict['user_id'] = instance.id
     result = user_edit(request)
     # test values
     self.assertEquals(result['the_user_id'], instance.id, "wrong id")
     self.assertEquals(
         result['the_username'], instance.username, "wrong username")
     self.assertTrue(result['form'], "no form")
     # test: no errors
     self.assertEquals(
          result['form'].form.errors, {},
          "unexpected error message was found")