class GCIOrgAppRecordsPageTest(MailTestCase, GCIDjangoTestCase): """Tests for organization applications edit page. """ def setUp(self): super(GCIOrgAppRecordsPageTest, self).setUp() self.init() self.record = SurveyHelper(self.gci, self.dev_test, self.org_app) self.url = '/gci/org/application/records/%s' % self.gci.key().name() def assertTemplatesUsed(self, response): """Asserts all the templates for edit page were used. """ self.assertGCITemplatesUsed(response) self.assertTemplateUsed(response, 'v2/soc/org_app/records.html') def dataPostSingle(self, url, record, status): return self.dataPost(url, {record: status}) def dataPost(self, url, changes): values = {} for record, status in changes.iteritems(): record_data = { 'status': status, } record_id = record.key().id() values[record_id] = record_data data = simplejson.dumps(values) postdata = { 'data': data, 'button_id': 'save', 'idx': 0, } return self.post(url, postdata) def testGetRecords(self): self.data.createHost() record = self.record.createOrgApp('org1', self.data.user, {'status': 'needs review'}) response = self.get(self.url) self.assertTemplatesUsed(response) list_data = self.getListData(self.url, 0) self.assertEqual(1, len(list_data)) self.dataPostSingle(self.url, record, 'bogus') record = db.get(record.key()) self.assertEqual('needs review', record.status) self.assertEmailNotSent() self.dataPostSingle(self.url, record, 'pre-accepted') record = db.get(record.key()) self.assertEqual('pre-accepted', record.status) self.assertEmailNotSent() self.dataPostSingle(self.url, record, 'pre-rejected') record = db.get(record.key()) self.assertEqual('pre-rejected', record.status) self.assertEmailNotSent() self.dataPostSingle(self.url, record, 'accepted') record = db.get(record.key()) self.assertEqual('accepted', record.status) html = 'Organization accepted' self.assertEmailSent(n=1, html=html) self.dataPostSingle(self.url, record, 'rejected') record = db.get(record.key()) self.assertEqual('rejected', record.status) html = 'Organization rejected' self.assertEmailSent(n=1, html=html) self.assertEmailSent(n=2)
class OrgProfilePageTest(GCIDjangoTestCase): """Tests the view for organization profile page. """ def setUp(self): self.init() self.record = SurveyHelper(self.gci, self.dev_test, self.org_app) def assertOrgProfilePageTemplatesUsed(self, response): self.assertGCITemplatesUsed(response) self.assertTemplateUsed(response, 'v2/modules/gci/org_profile/base.html') def testCreateOrgNoLinkid(self): url = '/gci/profile/organization/' + self.gci.key().name() response = self.get(url) self.assertResponseBadRequest(response) def testCreateOrgWrongLinkId(self): url = '/gci/profile/organization/' + self.gci.key().name() response = self.get(url + '?org_id=no_matching_proposal') self.assertResponseNotFound(response) def testCreateOrgRejectedApp(self): self.data.createUser() self.record.createOrgApp('rejected', self.data.user, override={'status': 'rejected'}) url = '/gci/profile/organization/' + self.gci.key().name() response = self.get(url + '?org_id=rejected') self.assertResponseForbidden(response) def testCreateOrgNoProfile(self): self.data.createUser() self.record.createOrgApp('new_org', self.data.user) url = '/gci/profile/organization/' + self.gci.key().name() response = self.get(url + '?org_id=new_org') self.assertResponseRedirect(response) def testCreateOrg(self): """Tests that only the assigned org admin for an organization can edit the org profile. """ self.timeline.orgSignup() self.data.createProfile() self.record.createOrgApp('new_org', self.data.user) url = '/gci/profile/organization/' + self.gci.key().name() create_url = url + '?org_id=new_org' response = self.get(create_url) self.assertResponseOK(response) self.assertOrgProfilePageTemplatesUsed(response) postdata = { 'founder': self.data.user, 'home': self.createDocument().key(), 'scope': self.gci, 'irc_channel': 'irc://example.com', 'pub_mailing_list': 'http://example.com', } response, properties = self.modelPost(create_url, GCIOrganization, postdata) self.assertResponseRedirect(response, url + '/new_org?validated') profile = db.get(self.data.profile.key()) self.assertEqual(1, len(profile.org_admin_for))