Ejemplo n.º 1
0
    def test_band_edit_submit_non_validating(self):
        """
        edit a band -- submit non-validating data
        """
        from c3sar.views.band import band_edit

        # put some instance into database
        band_instance = self._makeBand1()
        self.dbsession.add(band_instance)
        self.dbsession.flush()

        # submit some other values: com --> ORG
        request = testing.DummyRequest(
            post={'form.submitted': True,
                  'homepage': u'',         # this one is not validated anyways
                  'name': u'',             # will raise validation error
                  'email': u'invalid@email'})  # will raise error, too
        request.matchdict['band_id'] = 1
        self.config = testing.setUp(request=request)
        _registerRoutes(self.config)
        result = band_edit(request)
        #pp.pprint(result['form'].form.errors)
        self.assertEquals(
            result['form'].form.errors,
            {'email': u'The domain portion of the email address is invalid '
             '(the portion after the @: email)',
             'name': u'Please enter a value'},
            "not the expected error messages")
        self.assertEquals(result['form'].form.validate(),
                          False,
                          "form validated unexpectedly!")
Ejemplo n.º 2
0
 def test_band_edit_None(self):
     """
     edit a band -- redirect if id not exists
     """
     from c3sar.views.band import band_edit
     request = testing.DummyRequest()
     request.matchdict['band_id'] = 12      # <---- non-existand id
     self.config = testing.setUp(request=request)
     _registerRoutes(self.config)
     result = band_edit(request)
     # test: redirect
     self.assertTrue(isinstance(result, HTTPFound), "expected redirect")
     self.assertTrue('not_found' in result.headerlist[2][1])
     self.assertEquals(result.headerlist.pop(),
                       ('Location', 'http://example.com/not_found'),
                       "not the redirect expected")
Ejemplo n.º 3
0
 def test_band_edit_get(self):
     """
     edit a band -- get stored values into edit form
     """
     from c3sar.views.band import band_edit
     band_instance = self._makeBand1()
     self.dbsession.add(band_instance)
     self.dbsession.flush()
     the_id = band_instance.id  # the id of the band just created
     request = testing.DummyRequest()
     request.matchdict['band_id'] = the_id
     self.config = testing.setUp(request=request)
     _registerRoutes(self.config)
     result = band_edit(request)
     # test: form
     self.assertTrue('form' in result, "expected form not seen")
     # test: form has values from db
     self.assertEquals(result['form'].form.data,
                       {'homepage': u'http://band1.example.com',
                        'name': u'firstBandname',
                        'email': u'*****@*****.**'})
Ejemplo n.º 4
0
    def test_band_edit_submit(self):
        """
        edit a band -- re-submit changed values in edit form
        """
        from c3sar.views.band import band_edit

        # put some instance into database
        band_instance = self._makeBand1()
        self.dbsession.add(band_instance)
        self.dbsession.flush()

        # submit some other values: com --> ORG
        request = testing.DummyRequest(
            post={'form.submitted': True,
                  'homepage': u'http://band1.example.ORG',
                  'name': u'firstBandnameCHANGED',
                  'email': u'*****@*****.**'})
        request.matchdict['band_id'] = 1
        self.config = testing.setUp(request=request)
        _registerRoutes(self.config)
        result = band_edit(request)
        #pp.pprint(result)
        # test: redirect to band/view/1
        self.assertTrue(isinstance(result, HTTPFound),
                        "expected redirect not seen")
        self.assertTrue('band/view/1' in result.headerlist[2][1])
        #print(result.headerlist[2][1])
        self.assertEquals(result.headerlist.pop(),
                          ('Location', 'http://example.com/band/view/1'),
                          "not the redirect expected")

        from c3sar.models import Band
        db_band = Band.get_by_band_id(1)
        # test changed values in db?
        self.assertEquals(db_band.homepage, u'http://band1.example.ORG',
                          "changed value didn't make it to database!?")
        self.assertEquals(db_band.name, u'firstBandnameCHANGED',
                          "changed value didn't make it to database!?")
        self.assertEquals(db_band.email, u'*****@*****.**',
                          "changed value didn't make it to database!?")