def test_subscribe_anon(self): logout() provideAdapter( adapts=(Interface, IBrowserRequest), provides=Interface, factory=SubscriberForm, name=u"subscriber-form" ) # empty form request = self.request adapter = getMultiAdapter((self.gfolder, request), IGazetteSubscription) self.gfolder.subscription_require_tos = True subscriberForm = getMultiAdapter((self.gfolder, request), name=u"subscriber-form") subscriberForm.update() data, errors = subscriberForm.extractData() self.assertEquals(len(errors), 1) self.assertEquals(adapter.subscribe("", ""), INVALID_DATA) self.gfolder.subscription_require_tos = False subscriberForm = getMultiAdapter((self.gfolder, request), name=u"subscriber-form") subscriberForm.update() data, errors = subscriberForm.extractData() self.assertEquals(len(errors), 1) # FIXME - there should be 1 in this test - TOS is disabled self.assertEquals(adapter.subscribe("", ""), INVALID_DATA) # fill email only request.form = {"form.widgets.email": u"*****@*****.**", "form.widgets.tos:list": u"selected"} subscriberForm = getMultiAdapter((self.context, request), name=u"subscriber-form") subscriberForm.update() data, errors = subscriberForm.extractData() self.assertEquals(len(errors), 0) self.assertEquals(adapter.subscribe("*****@*****.**", ""), WAITING_FOR_CONFIRMATION) self.assertEquals(len(self.mailhost.messages), 1) # second subscription of inactive user resends activation email self.assertEquals(adapter.subscribe("*****@*****.**", ""), WAITING_FOR_CONFIRMATION) self.assertEquals(len(self.mailhost.messages), 2) msg = _parseMessage(self.mailhost.messages[1]) self.assertEquals(msg["To"], "*****@*****.**") msgtext = msg.get_payload(decode=True) # let's retrieve the key from the message groups = re.search("\?key=([a-f0-9]+)", msgtext).groups() self.assertEquals(len(groups), 1) key = groups[0] activationView = ActivationView(self.context, request) soup = getSoup(self.context, config.SUBSCRIBERS_SOUP_ID) subscriber = soup.data.values()[0] self.assertEquals(subscriber.email, u"*****@*****.**") self.assertEquals(subscriber.active, False) self.assertEquals(subscriber.key, key) self.assertEquals(subscriber.username, "") activationView.activate(key) self.assertEquals(subscriber.key, u"") self.assertEquals(subscriber.active, True) self.assertEquals(subscriber.username, "")
def test_unsubscribe_anon(self): logout() provideAdapter( adapts=(Interface, IBrowserRequest), provides=Interface, factory=SubscriberForm, name=u"subscriber-form" ) # subscribe user request = self.request adapter = getMultiAdapter((self.gfolder, request), IGazetteSubscription) request.form = {"form.widgets.email": u"*****@*****.**"} subscriberForm = getMultiAdapter((self.context, request), name=u"subscriber-form") subscriberForm.update() data, errors = subscriberForm.extractData() self.assertEquals(adapter.subscribe("*****@*****.**", ""), WAITING_FOR_CONFIRMATION) msg = _parseMessage(self.mailhost.messages[0]) self.assertEquals(msg["To"], "*****@*****.**") msgtext = msg.get_payload(decode=True) groups = re.search("\?key=([a-f0-9]+)", msgtext).groups() self.assertEquals(len(groups), 1) key = groups[0] # activate activationView = ActivationView(self.context, request) activationView.activate(key) self.assertEquals(adapter.unsubscribe("*****@*****.**"), WAITING_FOR_CONFIRMATION) msg = _parseMessage(self.mailhost.messages[1]) msgtext = msg.get_payload(decode=True) key = re.search("\?key=([a-f0-9]+)", msgtext).groups()[0] # deactivate activationView.deactivate(key) soup = getSoup(self.context, config.SUBSCRIBERS_SOUP_ID) subscriber = soup.data.values()[0] self.assertEquals(subscriber.active, False)