Skip to content

Instantly share code, notes, and snippets.

@yaniviny
yaniviny / simple-docker-deploy.rb
Created October 17, 2017 10:55
Simple docker deploy with sshkit instead of capistrano
# This was inspired by: https://gist.github.com/johnbintz/36bd6d6bcd9e6cfcb8f4
# the idea is that capistrano is an overkill for this docker deploy, so it's much easier to add rake tasks with sshkit.
# sshkit (which is used by capistrano) is much lighter than capistrano
require 'sshkit'
require 'sshkit/dsl'
include SSHKit::DSL
name = "my-cool-application"
app_name = "my-cool-application/app"
@yaniviny
yaniviny / run_status_compute.rb
Last active July 20, 2017 09:11
Shows how PractiTest computes the run status of a test run
def compute_status
statuses = all_statuses.uniq - ['N/A'] #take all statuses, make them unique, remove 'N/A'
if statuses.include?("FAILED") #if you have FAILED, everything is FAILED
"FAILED"
elsif statuses.include?("BLOCKED") # otherwise, if you have BLOCKED, everything is set to BLOCKED
"BLOCKED"
elsif (statuses == ["NO RUN"]) || statuses.empty? # IF YOU HAVE "NO RUN", or don't have steps at all -> It should be no run
"NO RUN"
elsif statuses == ["PASSED"] #if you're left with only one status -> PASSED, it means that all steps are passed (we already did unique, remember?)
"PASSED"
@yaniviny
yaniviny / gist:c199dc865997ca499ed3f23eaba8ab80
Last active January 23, 2017 11:16 — forked from stask/gist:10469324
PT Authentication in PHP
<?php
$api_token = ""; // here goes your api_token
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.practitest.com/api/v1/automated_tests/upload_test_result.json");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "{}"); // here goes the JSON you're uploading
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "Authorization: custom api_token=" . $api_token));
# on some older linux distros, our CA is not recognized,
@yaniviny
yaniviny / delete-instances.py
Last active January 23, 2017 11:35
An example of using PT API to bulk delete multiple instances
import json
import requests
URL = "https://api.practitest.com/api/v1/sets/1/instances.json"
headers = {
'Authorization': 'custom api_token=your_token',
'Content-Type': 'application/json',
}
@yaniviny
yaniviny / upload_test_results.rb
Last active January 22, 2017 14:30
Upload Test Results - Update Automated Tests results to PractiTest example in Ruby - simple authentication with api_token
require 'net/http'
require 'net/https'
require 'uri'
require 'json'
URL = "https://api.practitest.com/api/v1"
API_TOKEN = "your_api_token"
json_results = {
project_id: 1890,
@yaniviny
yaniviny / api_exporter_csv.rb
Last active December 5, 2016 10:47
Call PractiTest API to export all issues / Tests / TestSets / Requirements / Steps to a CSV file
require 'net/http'
require 'net/https'
require 'digest/md5'
require 'uri'
URL = "https://prod.practitest.com/api/v1"
API_TOKEN = "your_new_api_token"
def authorization
{"Authorization" => "custom api_token=#{API_TOKEN}"}
@yaniviny
yaniviny / upload_test_result_json.py
Last active January 23, 2017 11:10
Update Automated Tests results to PractiTest example (Python)
import requests
headers = {
'Authorization': 'custom api_token=your_token',
'Content-Type': 'application/json',
}
data = '{ "project_id": 2, "instance_display_id": "2:1", "exit_code": 0 }'
@yaniviny
yaniviny / upload_test_result.rb
Last active January 22, 2017 14:33
Update Automated Tests results to PractiTest example in Ruby
require 'net/http'
require 'net/https'
require 'uri'
require 'json'
URL = "https://api.practitest.com/api/v1"
API_TOKEN = "your_api_token"
def authorization
@yaniviny
yaniviny / api_issues_json.rb
Last active January 22, 2017 14:32
PractiTest issues API
require 'net/http'
require 'net/https'
require 'uri'
URL = "https://api.practitest.com/api/v1"
API_TOKEN = "your_api_token"
def get_request(path, extra_params = {})
uri = URI.parse("#{URL}/#{path}")
uri.query = URI.encode_www_form(extra_params)
@yaniviny
yaniviny / api_example.cs
Last active December 5, 2016 10:47
Calling PractiTest's Api via C#
// Calling PractiTest's API -- this script is irrelevant.
// Use now API_TOKEN only in the header, and json only
using System;
using System.IO;
using System.Net;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Security.Cryptography;