How to use publish method in tavern

Best Python code snippet using tavern

editor.js

Source:editor.js Github

copy

Full Screen

1/*2 * 留言3 * @author yongzhong zhang4 */5;(function($){6 7 8 var tweet = {9 sets: {10 namespace: '.tweet',11 edit_box: '#tweet_editor_box',12 leavemsg_wrapper: '.main-leavemsg-place',13 publish_wrapper: '.publish-wrapper',14 textarea_box: '.main-leavemsg',15 vcode: 'input.securitycode-text',16 vcode_img: 'img.securitycode-img',17 vcode_link: 'a.securitycode-switch',18 publish_btn: '.leavemsg-btn',19 line_height: 20,20 default_text: '对他说点什么',21 is_working: false,22 publish_url: '/a/guestbook/addMessage.htm?_input_encode=UTF-8',23 vcode_url: '/a/guestbook/vcode.htm', // 获取验证码24 vcode_image_url: '/a/guestbook/rand.htm', // 获取验证码图片25 default_height: 18,26 line_height: 18,27 min_height: 72,28 max_height: 180,29 link_to: $space_config._url + 'guestbook/index.htm'30 },31 32 params: {33 receiverPassport: '',34 vcode: ''35 },36 37 timer: null,38 init: function(options){39 $.extend(tweet.sets, options || {});40 41 // 获取被访问用户xpt42 tweet.params.receiverPassport = ($space_config && $space_config._xpt)? $space_config._xpt : '';43 var $edit_box = $(tweet.sets.edit_box),44 $textarea_box = $(tweet.sets.textarea_box, $edit_box),45 $publish_btn = $(tweet.sets.publish_btn, $edit_box);46 $('body')47 .bind('focusin' + tweet.sets.namespace, tweet.leavemsg_handler)48 .bind('click' + tweet.sets.namespace, tweet.leavemsg_handler);49 50 if($textarea_box.val() == ''){51 $textarea_box.val(tweet.sets.default_text);52 }53 54 $textarea_box55 .bind('keyup' + tweet.sets.namespace, tweet.height_adjust);56 57 $publish_btn58 .bind('mouseenter' + tweet.sets.namespace, function(){59 $(this).addClass('leavemsg-btn-hover');60 })61 .bind('mouseleave' + tweet.sets.namespace, function(){62 $(this).removeClass('leavemsg-btn-hover');63 });64 65 },66 67 height_adjust: function(type){68 type = type || 'expand'; // expand|collapse69 var $edit_box = $(tweet.sets.edit_box),70 $textarea_box = $(tweet.sets.textarea_box, $edit_box),71 $duplicate_box = null;72 73 if(!$('#leavemsg_textarea_duplicate').length){74 $('body').append('<div id="leavemsg_textarea_duplicate" style="display: none;"></div>');75 }76 $duplicate_box = $('#leavemsg_textarea_duplicate');77 var pre_text = $textarea_box.val();78 79 pre_text = pre_text.replace(/\&/g, '&amp;');80 pre_text = pre_text.replace(/\</g, '&lt;');81 pre_text = pre_text.replace(/\>/g, '&gt;');82 83 pre_text = pre_text.replace(/\n/g, '<br/> ');84 pre_text = pre_text.replace(/\s/g, '<i> </i>');85 $duplicate_box.html(pre_text);86 87 var h = $duplicate_box.height();88 89 h = (h < tweet.sets.max_height)? h : tweet.sets.max_height;90 91 $textarea_box.height((h > tweet.sets.min_height)? h : tweet.sets.min_height);92 if(type === 'collapse'){93 $textarea_box.height(tweet.sets.default_height);94 }95 96 },97 98 string_length: function(s) {99 return s.replace(/[^\x00-\xff]/g, "**").length;100 },101 102 string_sub: function(s, n) {103 var r = /[^\x00-\xff]/g;104 if (tweet.string_length(s) <= n){105 return s;106 }107 var m = Math.floor(n / 2);108 for ( var i = m; i < s.length; i++) {109 if (tweet.string_length(s.substr(0, i)) >= n) {110 return s.substr(0, i);111 }112 }113 return s;114 },115 116 login: function(){117 if(!$.cookie("ppinf")) {118 $.ppDialog({119 appId: '1019',120 regRedirectUrl: location.href,121 title: '想要查看更多精彩内容,马上登录吧!',122 onLogin: function(userId) {123 location.reload();124 }125 });126 return false;127 }128 return true;129 },130 // 获取验证码131 get_vcode: function($vcode_img){132 $.getJSON(tweet.sets.vcode_url + '?t=' + +new Date, function(json){133 if(typeof json != 'undefined'){134 tweet.params.vcode = json.vcode;135 $vcode_img[0].src = '/a/guestbook/rand.htm?vcode=' + json.vcode;136 }137 }, 'json');138 return tweet.params.vcode;139 },140 141 publish: function(event){142 if(!tweet.login()){143 return;144 }145 var $publish_btn = $(event.target);146 $edit_box = $(tweet.sets.edit_box),147 $publish_wrapper = $(tweet.sets.publish_wrapper, $edit_box),148 $textarea_box = $(tweet.sets.textarea_box, $publish_wrapper),149 $usercode = $(tweet.sets.vcode, $publish_wrapper);150 151 tweet.is_working = true;152 tweet.set_status.call($publish_wrapper, 'disabled');153 154 var params = $.extend(tweet.params, {155 content: $textarea_box.val(),156 usercode: $usercode.val()157 });158 159 // 判断留言内容是否为空160 if($.trim(params.content) == '' || $.trim(params.content) == tweet.sets.default_text){161 tweet.set_status.call($publish_wrapper, 'error');162 $.inform({163 icon: "icon-error",164 delay: 1500,165 easyClose: true,166 content: "内容不能为空。",167 onClose: function(){168 $textarea_box.focus();169 tweet.is_working = false;170 }171 });172 }173 // 验证内容长度174 else if(tweet.string_length($.trim(params.content)) > 400){175 tweet.set_status.call($publish_wrapper, 'error');176 $.inform({177 icon: "icon-error",178 delay: 1500,179 easyClose: true,180 content: "内容不能超过200个字。",181 onClose: function(){182 $textarea_box.focus();183 tweet.is_working = false;184 }185 });186 }187 // 验证码是否为空188 else if($.trim(params.usercode) == '' || $.trim(params.usercode) == ''){189 $usercode.addClass('securitycode-text-active');190 $.inform({191 icon: "icon-error",192 delay: 1500,193 easyClose: true,194 content: "验证码不能为空。",195 onClose: function(){196 $usercode.focus();197 tweet.is_working = false;198 }199 });200 }201 else{202 $.post(tweet.sets.publish_url, params, function(json){203 if(json && parseInt(json.status) === 1){204 $.inform({205 icon: "icon-success",206 delay: 1000,207 easyClose: true,208 content: json.statusText,209 onClose: function(){210 tweet.set_status.call($publish_wrapper, 'normal');211 $textarea_box.val('');212 tweet.is_working = false;213 document.location.href = tweet.sets.link_to;214 }215 });216 }else{217 $.inform({218 icon: "icon-error",219 delay: 1000,220 easyClose: true,221 content: json.statusText,222 onClose: function(){223 $textarea_box.focus();224 tweet.is_working = false;225 }226 });227 }228 }, 'json');229 }230 231 },232 233 set_status: function(status){234 var $this = this;235 if($this.length){236 $this.removeClass('leavemsg-active leavemsg-disabled leavemsg-error');237 switch(status){238 case 'active':239 $this.addClass('leavemsg-active');240 break;241 case 'disabled':242 $this.addClass('leavemsg-disabled');243 break;244 case 'error':245 $this.addClass('leavemsg-error');246 break;247 default: // normal248 break;249 }250 }251 },252 253 leavemsg_handler: function(event){254 var $target = $(event.target);255 var $edit_box = $(tweet.sets.edit_box),256 $leavemsg_wrapper = $(tweet.sets.leavemsg_wrapper, $edit_box),257 $publish_wrapper = $(tweet.sets.publish_wrapper, $edit_box),258 $textarea_box = $(tweet.sets.textarea_box, $publish_wrapper),259 $publish_btn = $(tweet.sets.publish_btn, $edit_box),260 $vcode = $(tweet.sets.vcode, $publish_wrapper),261 $vcode_img = $(tweet.sets.vcode_img, $publish_wrapper);262 if($target.closest(tweet.sets.publish_wrapper).length || $target.closest(tweet.sets.publish_btn).length){263 264 if(!$publish_wrapper.hasClass('leavemsg-active')){265 if($textarea_box.val() == '' || $textarea_box.val() == tweet.sets.default_text){266 $textarea_box.val('');267 }268 269 // 初始化验证码图片270 if(tweet.params.vcode == ''){271 tweet.get_vcode($vcode_img);272 }273 274 // 设置激活状态275 tweet.set_status.call($publish_wrapper, 'active');276 277 // 根据内容调整高度278 tweet.height_adjust('expand');279 }280 }else{281 282 if($publish_wrapper.hasClass('leavemsg-active')){283 if($textarea_box.val() == ''){284 $textarea_box.val(tweet.sets.default_text);285 }286 tweet.height_adjust('collapse');287 tweet.set_status.call($publish_wrapper, 'normal');288 }289 }290 291 if($target.closest(tweet.sets.vcode).length){292 $vcode.addClass('securitycode-text-active');293 }else{294 $vcode.removeClass('securitycode-text-active');295 }296 297 if(event.type == 'click'){298 // 快速留言提交299 if($target.closest(tweet.sets.publish_btn).length){300 tweet.publish.call(event.target, event);301 }302 // 更新验证码303 else if($target.closest(tweet.sets.vcode_img).length || $target.closest(tweet.sets.vcode_link).length){304 tweet.get_vcode($vcode_img);305 }306 307 }308 309 },310 311 textarea_blur: function(event){}312 };313 314 315 316 $(function(){317 318 tweet.init();319 });...

Full Screen

Full Screen

actions-artifacts.js

Source:actions-artifacts.js Github

copy

Full Screen

1import { artifacts as api } from '../api';2export const LOAD_GLOBAL_ARTIFACTS_REQUEST = 'transforms/load__global__artifacts__request';3export const LOAD_GLOBAL_ARTIFACTS_SUCCESS = 'transforms/load__global__artifacts__success';4export const LOAD_GLOBAL_ARTIFACTS_FAILURE = 'transforms/load__global__artifacts__failure';5export const LOAD_PUBLISHED_ARTIFACTS_REQUEST = 'transforms/load__publish__artifacts__request';6export const LOAD_PUBLISHED_ARTIFACTS_SUCCESS = 'transforms/load__publish__artifacts__success';7export const LOAD_PUBLISHED_ARTIFACTS_FAILURE = 'transforms/load__publish__artifacts__failure';8export const PUBLISH_ARTIFACT_REQUEST = 'transforms/publish__artifact__request';9export const PUBLISH_ARTIFACT_SUCCESS = 'transforms/publish__artifact__success';10export const PUBLISH_ARTIFACT_FAILURE = 'transforms/publish__artifact__failure';11export const UNPUBLISH_ARTIFACT_REQUEST = 'transforms/unpublish__artifact__request';12export const UNPUBLISH_ARTIFACT_SUCCESS = 'transforms/unpublish__artifact__success';13export const UNPUBLISH_ARTIFACT_FAILURE = 'transforms/unpublish__artifact__failure';14// -----------------------------------------------------------------------------15// LOAD GLOBAL ARTIFACTS16// -----------------------------------------------------------------------------17function requestLoadGlobalArtifacts() {18 return {19 type: LOAD_GLOBAL_ARTIFACTS_REQUEST,20 };21}22function successLoadGlobalArtifacts(artifacts) {23 return {24 type: LOAD_GLOBAL_ARTIFACTS_SUCCESS,25 payload: artifacts,26 };27}28function failureLoadGlobalArtifacts(json) {29 return {30 type: LOAD_GLOBAL_ARTIFACTS_FAILURE,31 payload: json.error,32 };33}34export function loadGlobalArtifacts(experimentId) {35 return (dispatch) => {36 dispatch(requestLoadGlobalArtifacts());37 const promise = api.loadGlobalArtifacts(experimentId);38 promise39 .then((artifacts) => {40 dispatch(successLoadGlobalArtifacts(artifacts));41 })42 .catch((err) => {43 dispatch(failureLoadGlobalArtifacts(err));44 });45 return promise;46 };47}48// -----------------------------------------------------------------------------49// LOAD ARTIFACTS50// -----------------------------------------------------------------------------51function requestLoadPublishedArtifacts() {52 return {53 type: LOAD_PUBLISHED_ARTIFACTS_REQUEST,54 };55}56function successLoadPublishedArtifacts(artifacts) {57 return {58 type: LOAD_PUBLISHED_ARTIFACTS_SUCCESS,59 payload: artifacts,60 };61}62function failureLoadPublishedArtifacts(json) {63 return {64 type: LOAD_PUBLISHED_ARTIFACTS_FAILURE,65 payload: json.error,66 };67}68export function loadPublishedArtifacts(experimentId) {69 return (dispatch) => {70 dispatch(requestLoadPublishedArtifacts());71 const promise = api.loadPublishedArtifacts(experimentId);72 promise73 .then((artifacts) => {74 dispatch(successLoadPublishedArtifacts(artifacts));75 })76 .catch((err) => {77 dispatch(failureLoadPublishedArtifacts(err));78 });79 return promise;80 };81}82// -----------------------------------------------------------------------------83// PUBLISH ARTIFACT84// -----------------------------------------------------------------------------85function requestPublishArtifact() {86 return {87 type: PUBLISH_ARTIFACT_REQUEST,88 };89}90function successPublishArtifact(artifact) {91 return {92 type: PUBLISH_ARTIFACT_SUCCESS,93 payload: artifact,94 };95}96function failurePublishArtifact(json) {97 return {98 type: PUBLISH_ARTIFACT_FAILURE,99 payload: json.error,100 };101}102export function publishArtifact(experimentId, transformId, description, artifact) {103 return (dispatch) => {104 dispatch(requestPublishArtifact());105 const publishPromise = api.publishArtifact(experimentId, transformId, description, artifact);106 publishPromise107 .then((publishedArtifact) => {108 dispatch(successPublishArtifact(publishedArtifact));109 })110 .catch((error) => {111 dispatch(failurePublishArtifact(error));112 });113 return publishPromise;114 };115}116export function publishArtifactGlobally(description, username, organization, artifact) {117 return (dispatch) => {118 dispatch(requestPublishArtifact());119 const publishPromise =120 api.publishArtifactGlobally(description, username, organization, artifact);121 publishPromise122 .then((publishedArtifact) => {123 dispatch(successPublishArtifact(publishedArtifact));124 })125 .catch((error) => {126 dispatch(failurePublishArtifact(error));127 });128 return publishPromise;129 };130}131// -----------------------------------------------------------------------------132// UNPUBLISH ARTIFACT133// -----------------------------------------------------------------------------134function requestUnpublishArtifact() {135 return {136 type: UNPUBLISH_ARTIFACT_REQUEST,137 };138}139function successUnpublishArtifact(artifactId) {140 return {141 type: UNPUBLISH_ARTIFACT_SUCCESS,142 payload: artifactId,143 };144}145function failureUnpublishArtifact(json) {146 return {147 type: UNPUBLISH_ARTIFACT_FAILURE,148 payload: json.error,149 };150}151export function unpublishArtifact(experimentId, artifact) {152 return (dispatch) => {153 dispatch(requestUnpublishArtifact());154 const promise = api.unpublishArtifact(experimentId, artifact.id);155 promise156 .then(() => {157 dispatch(successUnpublishArtifact(artifact.key));158 })159 .catch((err) => {160 dispatch(failureUnpublishArtifact(err));161 });162 return promise;163 };164}165// -----------------------------------------------------------------------------166// DEFAULT EXPORT167// -----------------------------------------------------------------------------168export default {169 loadGlobalArtifacts,170 loadPublishedArtifacts,171 publishArtifact,172 publishArtifactGlobally,173 unpublishArtifact,...

Full Screen

Full Screen

SyncRcuRingBuffer.py

Source:SyncRcuRingBuffer.py Github

copy

Full Screen

...47 return self._rcu.get(index)48 49 def set(self, value):50 self.set_next_production_elem(value)51 self.publish()52 53 def set_next_production_elem(self, value):54 data = SyncData(self._current_publish_count, value)55 self._rcu.set_next_production_elem(data)56 57 def publish(self):58 self._set_event()59 self.publish_without_events()60 self._reset_event()61 62 def publish_without_events(self):63 self._current_publish_count += 164 data = self._rcu.get_next_production_elem()65 data.publish_count = self._current_publish_count66 self._rcu.set_next_production_elem(data)67 self._rcu.publish()68 69 def get_buffer_size(self):70 return self._rcu.get_buffer_size()71 72 def get_production_index(self):73 return self._rcu.get_production_index()74 75 def _set_event(self):76 self._events[self._get_current_event_index()].set()77 78 def _reset_event(self):79 self._events[self._get_current_event_index()].clear()80class AbstractSyncRcuRingBufferReader(SyncRcuRingBufferBase):81 __metaclass__ = abc.ABCMeta...

Full Screen

Full Screen

publish.js

Source:publish.js Github

copy

Full Screen

1#!/usr/bin/env node2'use strict'3import { join } from 'node:path'4import {5 experimentalPackages,6 stablePackages,7 DesignVersion,8} from '../../versions.mjs'9import { error } from '../theme.mjs'10import { __dirname } from '../utils.mjs'11import parseParams from './publish-commands/parse-publish-params.mjs'12import validateTags from './publish-commands/validate-tags.mjs'13import confirmSkippedPackages from './publish-commands/confirm-skipped-packages.mjs'14import confirmVersionAndTags from './publish-commands/confirm-version-and-tags.mjs'15import validateSkipPackages from './publish-commands/validate-skip-packages.mjs'16import checkNPMPermissions from './publish-commands/check-npm-permissions.mjs'17import publishToNPM from './publish-commands/publish-to-npm.mjs'18import printFollowUpInstructions from './publish-commands/print-follow-up-instructions.mjs'19async function run() {20 const params = await parseParams()21 params.cwd = join(__dirname(import.meta.url), '..', '..')22 const packages = [...experimentalPackages, ...Object.keys(stablePackages)]23 // Pre-filter any skipped packages to simplify the following commands.24 // As part of doing this we can also validate that none of the skipped25 // packages were misspelled.26 params.skipPackages.forEach((packageName) => {27 const index = packages.indexOf(packageName)28 if (index < 0) {29 console.log(30 error('Invalid skip package {package ' + packageName + ' } specified.')31 )32 process.exit(1)33 } else {34 packages.splice(index, 1)35 }36 })37 // Validate everything38 const paramsWithPackages = { ...params, packages }39 await validateTags(paramsWithPackages)40 if (!params.ci) {41 await confirmSkippedPackages(params)42 }43 await confirmVersionAndTags(paramsWithPackages)44 await validateSkipPackages(paramsWithPackages)45 await checkNPMPermissions(packages)46 // Publish47 if (params.ci) {48 let failed = false49 packages.forEach(async (packageName) => {50 try {51 await publishToNPM(params, packageName, null)52 } catch (error) {53 failed = true54 console.error(error.message)55 console.log()56 console.log(57 error`Publish failed. Will attempt to publish remaining packages.`58 )59 }60 })61 if (failed) {62 console.log(error`One or more packages failed to publish.`)63 process.exit(1)64 }65 } else {66 console.clear()67 packages.forEach(async (packageName) => {68 try {69 await publishToNPM(params, packageName)70 } catch (errorData) {71 console.error(errorData.message)72 console.log()73 console.log(error`Publish failed.`)74 }75 })76 await printFollowUpInstructions({ ...params, version: DesignVersion })77 }78}...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run tavern automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful