Best JavaScript code snippet using tracetest
queue.py
Source:queue.py
...274 # for test275 frappe.local.flags.signed_query_string = query_string276 return get_url(unsubscribe_method + "?" + get_signed_params(params))277@frappe.whitelist(allow_guest=True)278def unsubscribe(doctype, name, email):279 # unsubsribe from comments and communications280 if not verify_request():281 return282 try:283 frappe.get_doc({284 "doctype": "Email Unsubscribe",285 "email": email,286 "reference_doctype": doctype,287 "reference_name": name288 }).insert(ignore_permissions=True)289 except frappe.DuplicateEntryError:290 frappe.db.rollback()291 else:292 frappe.db.commit()...
modules_unsubscribe.py
Source:modules_unsubscribe.py
1# Copyright 2014 Google Inc. All Rights Reserved.2#3# Licensed under the Apache License, Version 2.0 (the "License");4# you may not use this file except in compliance with the License.5# You may obtain a copy of the License at6#7# http://www.apache.org/licenses/LICENSE-2.08#9# Unless required by applicable law or agreed to in writing, software10# distributed under the License is distributed on an "AS-IS" BASIS,11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12# See the License for the specific language governing permissions and13# limitations under the License.14"""Tests for the module to support users unsubscribing from notifications."""15__author__ = 'John Orr (jorr@google.com)'16import urlparse17from common import utils18from controllers import sites19from modules.unsubscribe import unsubscribe20from tests.functional import actions21from google.appengine.ext import db22class BaseUnsubscribeTests(actions.TestBase):23 def assertUnsubscribed(self, email, namespace):24 with utils.Namespace(namespace):25 self.assertTrue(unsubscribe.has_unsubscribed(email))26 def assertSubscribed(self, email, namespace):27 with utils.Namespace(namespace):28 self.assertFalse(unsubscribe.has_unsubscribed(email))29class GetUnsubscribeUrlTests(actions.TestBase):30 def test_get_unsubscribe_url(self):31 handler = actions.MockHandler(32 app_context=actions.MockAppContext(slug='new_course'))33 url = unsubscribe.get_unsubscribe_url(handler, 'test@example.com')34 parsed_url = urlparse.urlparse(url)35 self.assertEquals('http', parsed_url.scheme)36 self.assertEquals('mycourse.appspot.com', parsed_url.netloc)37 self.assertEquals('/new_course/modules/unsubscribe', parsed_url.path)38 query_dict = urlparse.parse_qs(parsed_url.query)39 self.assertEquals(['test@example.com'], query_dict['email'])40 self.assertRegexpMatches(query_dict['s'][0], r'[0-9a-f]{32}')41class SubscribeAndUnsubscribeTests(BaseUnsubscribeTests):42 EMAIL = 'test@example.com'43 def setUp(self):44 super(SubscribeAndUnsubscribeTests, self).setUp()45 self.namespace = 'namespace'46 def test_subscription_state_never_set(self):47 with utils.Namespace(self.namespace):48 self.assertSubscribed(self.EMAIL, self.namespace)49 def test_set_subscription_state(self):50 with utils.Namespace(self.namespace):51 unsubscribe.set_subscribed(self.EMAIL, False)52 self.assertUnsubscribed(self.EMAIL, self.namespace)53 def test_set_then_unset_subscription_state(self):54 with utils.Namespace(self.namespace):55 self.assertSubscribed(self.EMAIL, self.namespace)56 unsubscribe.set_subscribed(self.EMAIL, True)57 self.assertSubscribed(self.EMAIL, self.namespace)58 unsubscribe.set_subscribed(self.EMAIL, False)59 self.assertUnsubscribed(self.EMAIL, self.namespace)60 def test_subscription_state_entity_must_have_key_name(self):61 with self.assertRaises(db.BadValueError):62 unsubscribe.SubscriptionStateEntity()63 with self.assertRaises(db.BadValueError):64 unsubscribe.SubscriptionStateEntity(id='23')65class UnsubscribeHandlerTests(BaseUnsubscribeTests):66 def setUp(self):67 super(UnsubscribeHandlerTests, self).setUp()68 self.base = '/a'69 self.namespace = 'ns_a'70 sites.setup_courses('course:/a::ns_a')71 self.app_context = actions.MockAppContext(72 namespace=self.namespace, slug='a')73 self.handler = actions.MockHandler(74 base_href='http://localhost/',75 app_context=self.app_context)76 self.email = 'test@example.com'77 actions.login(self.email, is_admin=True)78 def test_unsubscribe_and_resubscribe(self):79 self.assertSubscribed(self.email, self.namespace)80 unsubscribe_url = unsubscribe.get_unsubscribe_url(81 self.handler, self.email)82 response = self.get(unsubscribe_url)83 # Confirm the user has unsubscribed84 self.assertUnsubscribed(self.email, self.namespace)85 # Confirm the page content of the response86 root = self.parse_html_string(response.body).find(87 './/*[@id="unsubscribe-message"]')88 confirm_elt = root.find('./p[1]')89 self.assertTrue('has been unsubscribed' in confirm_elt.text)90 email_elt = root.find('.//div[1]')91 self.assertEquals(self.email, email_elt.text.strip())92 resubscribe_url = root.find('.//div[2]/button').attrib[93 'data-resubscribe-url']94 response = self.get(resubscribe_url)95 # Confirm the user has now resubscribed96 self.assertSubscribed(self.email, self.namespace)97 # Confirm the page content of the response98 root = self.parse_html_string(response.body).find(99 './/*[@id="resubscribe-message"]')100 confirm_elt = root.find('./p[1]')101 self.assertTrue('has been subscribed' in confirm_elt.text)102 email_elt = root.find('.//div[1]')103 self.assertEquals(self.email, email_elt.text.strip())104 def test_bad_signature_rejected_with_401(self):105 response = self.get(106 'modules/unsubscribe'107 '?email=test%40example.com&s=bad_signature',108 expect_errors=True)109 self.assertEquals(401, response.status_code)110 def test_unsubscribe_request_with_no_email_prompts_for_login(self):111 actions.logout()112 response = self.get('modules/unsubscribe')113 self.assertEquals(302, response.status_int)114 self.assertEquals(115 'https://www.google.com/accounts/Login'116 '?continue=http%3A//localhost/a/modules/unsubscribe',117 response.headers['Location'])118 def test_unsubscribe_with_no_email_and_in_session(self):119 response = self.get('modules/unsubscribe')120 # Confirm the user has unsubscribed121 self.assertUnsubscribed(self.email, self.namespace)122 # Confirm the page content of the response123 root = self.parse_html_string(response.body).find(124 './/*[@id="unsubscribe-message"]')125 confirm_elt = root.find('./p[1]')126 self.assertTrue('has been unsubscribed' in confirm_elt.text)127 email_elt = root.find('.//div[1]')128 self.assertEquals(self.email, email_elt.text.strip())129 resubscribe_url = root.find('.//div[2]/button').attrib[130 'data-resubscribe-url']131 response = self.get(resubscribe_url)132 # Confirm the user has now resubscribed...
bus.unit.js
Source:bus.unit.js
...70 }71 }72 };73 var bus = new Bus({node: node});74 bus.unsubscribe('dbtest', 'a', 'b', 'c');75 bus.unsubscribe('test', 'a', 'b', 'c');76 unsubscribeService.callCount.should.equal(1);77 unsubscribeDb.callCount.should.equal(1);78 unsubscribeDb.args[0][0].should.equal(bus);79 unsubscribeDb.args[0][1].should.equal('a');80 unsubscribeDb.args[0][2].should.equal('b');81 unsubscribeDb.args[0][3].should.equal('c');82 unsubscribeService.args[0][0].should.equal(bus);83 unsubscribeService.args[0][1].should.equal('a');84 unsubscribeService.args[0][2].should.equal('b');85 unsubscribeService.args[0][3].should.equal('c');86 });87 });88 describe('#close', function() {89 it('will unsubscribe from all events', function() {...
Unsubscribe.js
Source:Unsubscribe.js
...80 /**81 * Now we unsubscribe node 282 * It should work.83 */84 this.unsubscribe(2,1,true);85 86 /**87 * unsubscribe node 3,88 * it should fail since 3 is a forwarder to 4,589 */90 this.unsubscribe(3,1,false);91 92 93 for(var idx=1; idx <= this.getNodeCount(); idx++) { 94 slonArray[idx-1].stop();95 this.coordinator.join(slonArray[idx-1]);96 }97 this.coordinator.log("Unsubscribe.prototype.runTest - complete"); 98}99Unsubscribe.prototype.unsubscribe=function(node_id,set_id,expect_success) {100 this.coordinator.log("Unsubscribe.prototype.unsubscribe - begin"); 101 var slonikPreamble = this.getSlonikPreamble();102 var slonikScript = 'echo \'Unsubscribe.prototype.unsubscribe\';\n';103 slonikScript +='unsubscribe set(id=' + set_id + ',receiver=' + node_id + ');\n';104 var slonik = this.coordinator.createSlonik('unsubscribe ' , slonikPreamble,slonikScript);...
13-malformed-unsubscribe-v5.py
Source:13-malformed-unsubscribe-v5.py
...17port = mosq_test.get_port()18broker = mosq_test.start_broker(filename=os.path.basename(__file__), port=port)19try:20 # mid == 021 unsubscribe_packet = mosq_test.gen_unsubscribe(topic="test/topic", mid=0, proto_ver=5)22 do_test(unsubscribe_packet, mqtt5_rc.MQTT_RC_MALFORMED_PACKET, "mid == 0")23 # command flags != 0x0224 unsubscribe_packet = mosq_test.gen_unsubscribe(topic="test/topic", mid=1, proto_ver=5, cmd=160)25 do_test(unsubscribe_packet, mqtt5_rc.MQTT_RC_MALFORMED_PACKET, "command flags != 0x02")26 # Incorrect property27 props = mqtt5_props.gen_uint32_prop(mqtt5_props.PROP_SESSION_EXPIRY_INTERVAL, 0)28 unsubscribe_packet = mosq_test.gen_unsubscribe(topic="test/topic", mid=1, proto_ver=5, properties=props)29 do_test(unsubscribe_packet, mqtt5_rc.MQTT_RC_MALFORMED_PACKET, "Incorrect property")30 # Truncated packet, no mid31 unsubscribe_packet = struct.pack("!BB", 162, 0)32 do_test(unsubscribe_packet, mqtt5_rc.MQTT_RC_MALFORMED_PACKET, "Truncated packet, no mid")33 # Truncated packet, no properties34 unsubscribe_packet = struct.pack("!BBH", 162, 2, 1)35 do_test(unsubscribe_packet, mqtt5_rc.MQTT_RC_MALFORMED_PACKET, "Truncated packet, no properties")36 # Truncated packet, with properties field, no topic37 unsubscribe_packet = struct.pack("!BBHH", 162, 4, 1, 0)38 do_test(unsubscribe_packet, mqtt5_rc.MQTT_RC_MALFORMED_PACKET, "Truncated packet, with properties field, no topic")39 # Truncated packet, with properties field, empty topic40 unsubscribe_packet = struct.pack("!BBHHH", 162, 5, 1, 0, 0)41 do_test(unsubscribe_packet, mqtt5_rc.MQTT_RC_MALFORMED_PACKET, "Truncated packet, with properties field, empty topic")42 # Bad topic43 unsubscribe_packet = mosq_test.gen_unsubscribe(topic="#/test/topic", mid=1, proto_ver=5)44 do_test(unsubscribe_packet, mqtt5_rc.MQTT_RC_MALFORMED_PACKET, "Bad topic")45except mosq_test.TestError:46 pass47finally:48 broker.terminate()49 broker.wait()50 (stdo, stde) = broker.communicate()51 if rc:52 print(stde.decode('utf-8'))...
unsubscribe.py
Source:unsubscribe.py
...5from zerver.context_processors import common_context6from zerver.lib.actions import do_change_notification_settings7from zerver.lib.send_email import clear_scheduled_emails8from zerver.models import ScheduledEmail, UserProfile9def process_unsubscribe(request: HttpRequest, confirmation_key: str, subscription_type: str,10 unsubscribe_function: Callable[[UserProfile], None]) -> HttpResponse:11 try:12 user_profile = get_object_from_key(confirmation_key, Confirmation.UNSUBSCRIBE)13 except ConfirmationKeyException:14 return render(request, 'zerver/unsubscribe_link_error.html')15 unsubscribe_function(user_profile)16 context = common_context(user_profile)17 context.update({"subscription_type": subscription_type})18 return render(request, 'zerver/unsubscribe_success.html', context=context)19# Email unsubscribe functions. All have the function signature20# processor(user_profile).21def do_missedmessage_unsubscribe(user_profile: UserProfile) -> None:22 do_change_notification_settings(user_profile, 'enable_offline_email_notifications', False)23def do_welcome_unsubscribe(user_profile: UserProfile) -> None:24 clear_scheduled_emails([user_profile.id], ScheduledEmail.WELCOME)25def do_digest_unsubscribe(user_profile: UserProfile) -> None:26 do_change_notification_settings(user_profile, 'enable_digest_emails', False)27def do_login_unsubscribe(user_profile: UserProfile) -> None:28 do_change_notification_settings(user_profile, 'enable_login_emails', False)29# The keys are part of the URL for the unsubscribe link and must be valid30# without encoding.31# The values are a tuple of (display name, unsubscribe function), where the32# display name is what we call this class of email in user-visible text.33email_unsubscribers = {34 "missed_messages": ("missed messages", do_missedmessage_unsubscribe),35 "welcome": ("welcome", do_welcome_unsubscribe),36 "digest": ("digest", do_digest_unsubscribe),37 "login": ("login", do_login_unsubscribe),38}39# Login NOT required. These are for one-click unsubscribes.40def email_unsubscribe(request: HttpRequest, email_type: str,41 confirmation_key: str) -> HttpResponse:42 if email_type in email_unsubscribers:43 display_name, unsubscribe_function = email_unsubscribers[email_type]44 return process_unsubscribe(request, confirmation_key, display_name, unsubscribe_function)...
insite.unsubscribe-from-cart-reminders.controller.ts
Source:insite.unsubscribe-from-cart-reminders.controller.ts
1module insite.account {2 "use strict";3 export class UnsubscribeFromCartRemindersController {4 unsubscribeError: string;5 static $inject = ["queryString", "sessionService"];6 constructor(protected queryString: common.IQueryStringService, protected sessionService: account.ISessionService) {7 }8 $onInit(): void {9 const parameters: ICartRemindersUnsubscribeParameters = {10 username: this.queryString.get("username"),11 unsubscribeToken: this.queryString.get("unsubscribeToken")12 };13 this.sessionService.unsubscribeFromCartReminders(parameters).then(14 (session: SessionModel) => { this.unsubscribeFromCartRemindersCompleted(session); },15 (error: any) => { this.unsubscribeFromCartRemindersFailed(error); });16 }17 protected unsubscribeFromCartRemindersCompleted(session: SessionModel): void {18 }19 protected unsubscribeFromCartRemindersFailed(error: any): void {20 this.unsubscribeError = error.message;21 }22 }23 angular24 .module("insite")25 .controller("UnsubscribeFromCartRemindersController", UnsubscribeFromCartRemindersController);...
UnsubscribeModal.test.js
Source:UnsubscribeModal.test.js
...12 );13 wrapper.find("#cancel").simulate("click");14 expect(closeUnsubscribeModal).toHaveBeenCalled();15});16test("should call unsubscribe() with podcastId and closeUnsubscribeModal() on #unsubscribe click", () => {17 const unsubscribe = jest.fn();18 const closeUnsubscribeModal = jest.fn();19 const podcastId = 928159684;20 const wrapper = shallow(21 <UnsubscribeModal22 podcastId={podcastId}23 unsubscribe={unsubscribe}24 closeUnsubscribeModal={closeUnsubscribeModal}25 />26 );27 wrapper.find("#unsubscribe").simulate("click");28 expect(unsubscribe).toHaveBeenCalledWith(podcastId);29 expect(closeUnsubscribeModal).toHaveBeenCalled();30});
Using AI Code Generation
1var tracetest = require('./tracetest');2var trace = tracetest.trace;3var untrace = tracetest.untrace;4function bar() {5 trace('bar');6 trace('bar');7}8function foo() {9 trace('foo');10 bar();11 trace('foo');12}13foo();14untrace('foo');15foo();16var util = require('util');17function trace(msg) {18 console.log(msg);19}20exports.trace = trace;21function untrace(msg) {22 console.log('untracing: ' + msg);23}24exports.untrace = untrace;
Using AI Code Generation
1var tracetest = require('tracetest');2var trace = tracetest.trace;3var untrace = tracetest.untrace;4var add = tracetest.add;5trace('add');6console.log(add(1,2));7untrace('add');8console.log(add(1,2));9exports.trace = function (name) {10 var original = this[name];11 this[name] = function () {12 console.log('calling', name, 'with', arguments);13 return original.apply(this, arguments);14 };15};16exports.untrace = function (name) {17 this[name] = original;18};19exports.add = function (a, b) {20 return a + b;21};22var tracetest = require('tracetest');23var trace = tracetest.trace;24var untrace = tracetest.untrace;25var add = tracetest.add;26trace('add');27console.log(add(1,2));28untrace('add');29console.log(add(1,2));30exports.trace = function (name) {31 var original = this[name];32 this[name] = function () {33 console.log('calling', name, 'with', arguments);34 return original.apply(this, arguments);35 };36};37exports.untrace = function (name) {38 this[name] = original;39};40exports.add = function (a, b) {41 return a + b;42};
Using AI Code Generation
1var tracer = require('tracetest');2tracer.subscribe(function(data) {3 console.log(data);4});5tracer.unsubscribe(function(data) {6 console.log(data);7});8exports.subscribe = function(callback) {9 callback('subscribe');10};11exports.unsubscribe = function(callback) {12 callback('unsubscribe');13};
Using AI Code Generation
1var tracer = require('tracer');2var trace = tracer.trace;3var trace = tracer.trace;4var trace2 = tracer.trace;5var trace3 = tracer.trace;6var trace4 = tracer.trace;7var trace5 = tracer.trace;8var trace6 = tracer.trace;9var trace7 = tracer.trace;10var trace8 = tracer.trace;11var trace9 = tracer.trace;12var trace10 = tracer.trace;13var trace11 = tracer.trace;14var trace12 = tracer.trace;15var trace13 = tracer.trace;16var trace14 = tracer.trace;17var trace15 = tracer.trace;18var trace16 = tracer.trace;19var trace17 = tracer.trace;20var trace18 = tracer.trace;21var trace19 = tracer.trace;22var trace20 = tracer.trace;23var trace21 = tracer.trace;24var trace22 = tracer.trace;25var trace23 = tracer.trace;26var trace24 = tracer.trace;27var trace25 = tracer.trace;28var trace26 = tracer.trace;29var trace27 = tracer.trace;30var trace28 = tracer.trace;31var trace29 = tracer.trace;32var trace30 = tracer.trace;33var trace31 = tracer.trace;34var trace32 = tracer.trace;35var trace33 = tracer.trace;36var trace34 = tracer.trace;37var trace35 = tracer.trace;38var trace36 = tracer.trace;39var trace37 = tracer.trace;40var trace38 = tracer.trace;41var trace39 = tracer.trace;42var trace40 = tracer.trace;43var trace41 = tracer.trace;44var trace42 = tracer.trace;45var trace43 = tracer.trace;46var trace44 = tracer.trace;47var trace45 = tracer.trace;48var trace46 = tracer.trace;49var trace47 = tracer.trace;50var trace48 = tracer.trace;51var trace49 = tracer.trace;52var trace50 = tracer.trace;53trace.unsubscribe(trace2);54trace3.unsubscribe(trace4);55trace5.unsubscribe(trace6);56trace7.unsubscribe(trace8);57trace9.unsubscribe(trace10);58trace11.unsubscribe(trace12);59trace13.unsubscribe(trace14);60trace15.unsubscribe(trace16);61trace17.unsubscribe(trace18);62trace19.unsubscribe(trace20);63trace21.unsubscribe(trace22);64trace23.unsubscribe(trace24);65trace25.unsubscribe(trace26);66trace27.unsubscribe(trace28);67trace29.unsubscribe(trace30);68trace31.unsubscribe(trace32);69trace33.unsubscribe(trace34);70trace35.unsubscribe(trace36);71trace37.unsubscribe(trace38);72trace39.unsubscribe(trace40);73trace41.unsubscribe(trace42);74trace43.unsubscribe(trace44);75trace45.unsubscribe(trace46);
Using AI Code Generation
1var tracetest = require('tracetest');2var trace = tracetest.trace;3var unsubscribe = tracetest.unsubscribe;4trace('test');5unsubscribe('test');6trace('test');7var trace = function (name) {8 console.log(name);9 return name;10};11var unsubscribe = function (name) {12 console.log(name);13 return name;14};15module.exports.trace = trace;16module.exports.unsubscribe = unsubscribe;17Your name to display (optional):18Your name to display (optional):19module.exports = {20};21Your name to display (optional):22module.exports.trace = trace;23module.exports.unsubscribe = unsubscribe;24But in the test.js file, you are importing them as follows:25var tracetest = require('tracetest');26var trace = tracetest.trace;27var unsubscribe = tracetest.unsubscribe;28Here, you are importing the entire tracetest module as a single object tracetest. So, to access the trace and unsubscribe function, you need to use the dot (.) operator as follows:29var trace = tracetest.trace;30var unsubscribe = tracetest.unsubscribe;31If you want to import the trace and unsubscribe function directly, you can use the following syntax:32var {trace, unsubscribe} = require('tracetest');33Your name to display (optional):
Using AI Code Generation
1var tracetest = require('./tracetest');2var tracer = new tracetest();3tracer.subscribe(function() {4 console.log('event emitted');5});6tracer.unsubscribe();7tracer.emit();8function TraceTest() {9 this.subscribers = [];10}11TraceTest.prototype.subscribe = function(fn) {12 this.subscribers.push(fn);13};14TraceTest.prototype.unsubscribe = function() {15 this.subscribers = [];16};17TraceTest.prototype.emit = function() {18 this.subscribers.forEach(function(subscriber) {19 subscriber();20 });21};22module.exports = TraceTest;
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!