Storyboard 03

From Alistair Mann / csi18n
Jump to: navigation, search

Demonstrating how user "test05" can bump a translation uploaded by user "testSubOrdPosts"

  1. testSubOrdPosts creates a new translation
  2. test05 retrieves it and its bump link, decides he doesn't like it
  3. test05 retrieves the bump status
  4. test05 changes the status
  5. test05 uploads the new status
  6. test05 confirms that new status
#!/bin/bash
source acceptance_tests/predefined_codes.sh
 
echo "First POST to visit link should 201 and provide translation link";
curl -i -X POST -H 'Connection: close' -H 'X-APIKey: 798e31c43d6b9f03aa504a6f88cb4550' -H 'Content-Type: application/json;v=1.0' -u 'testSubOrdPosts:test' --data '{"csi18n_xlate_resource":{"language":"en-CA","translation":"Congraturation - A winrar is you","visibility":"anonymous"}}' https://rest.mpsvr.com:443/newmarks/1/A-winner-is-you >/tmp/x
RV=$(cat /tmp/x | grep "HTTP/1.1" | grep -v "X-Testing-Dupe: " | cut -c 10-12)
if [[ "$RV" != "201"  &&  "$RV" != "301" ]]; then
    echo ""
    echo "First POST failed :-(";
    echo $RV
    exit;
fi;
LOCATION=$(cat /tmp/x | grep "Location: " | sed 's|Location: ||' | sed 's|.$||')
if [[ "$LOCATION" == "" ]]; then
    echo ""
    echo "\nFirst POST didn't find a Location :-(\n";
    cat /tmp/x
    exit;
fi;
 
echo "First GET to translation link by Visit SID should bring back representation and bump link";
curl -i -X GET -H 'Accept: application/json' -H 'Connection: close' -H 'X-APIKey: 798e31c43d6b9f03aa504a6f88cb4550' -u 'test05:test' $LOCATION >/tmp/x
RV1=$(cat /tmp/x | grep "HTTP/1.1" | grep -v "X-Testing-Dupe: " | cut -c 10-12)
if [[ "$RV1" != "200" ]]; then
    echo ""
    echo "First GET failed :-(\n";
    echo $RV1
    exit;
fi;
BUMPLINK=$(cat /tmp/x | grep '"bump_uri"' | sed 's/.*"bump_uri":"//' | sed 's/".*//' | sed 's*\\/*/*g')
if [[ "$BUMPLINK" == "" ]]; then
    echo ""
    echo "Bump link not found :-(\n";
    echo $BUMPLINK
    exit;
fi;
 
echo "Second GET to bump link should bring back representation of resource including bump status";
curl -i -X GET -H 'Accept: application/json' -H 'Connection: close' -H 'X-APIKey: 798e31c43d6b9f03aa504a6f88cb4550' -u 'test05:test' $BUMPLINK >/tmp/x
RV1=$(cat /tmp/x | grep "HTTP/1.1" | grep -v "X-Testing-Dupe: " | cut -c 10-12)
if [[ "$RV1" != "200" ]]; then
    echo ""
    echo "Second GET failed :-(\n";
    echo $RV1
    exit;
fi;
RESF=$(cat /tmp/x | grep '"bumped":"false"')
REST=$(cat /tmp/x | grep '"bumped":"true"')
if [[ "$RESF" != "" ]]; then
    echo "Bumped is false, so will change to true"
    RES2=$(echo $RESF | sed 's/"bumped":"false"/"bumped":"true"/');
elif [[ "$REST" != "" ]]; then
    echo "Bumped is true, so will change to false"
    RES2=$(echo $REST | sed 's/"bumped":"true"/"bumped":"false"/');
else
    echo ""
    echo "Resource not found at bump link, or bumped status was not true or false :-(\n";
    cat /tmp/x
    exit;
fi;
 
echo "First PUT to bump link should 201";
curl -i -X PUT -H 'X-Track-Security: true' -H 'Connection: close' -H 'X-APIKey: 798e31c43d6b9f03aa504a6f88cb4550' -H 'Content-Type: application/json;v=1.0' -u 'test05:test' --data "$RES2" $BUMPLINK >/tmp/x
RV=$(cat /tmp/x | grep "HTTP/1.1" | grep -v "X-Testing-Dupe: " | cut -c 10-12)
if [[ "$RV" != "201" ]]; then
    echo ""
    echo "First PUT failed :-(\n";
    echo $RV
    echo $RES2
    echo $BUMPLINK
    cat /tmp/x
    exit;
fi;
 
echo "Third GET to bump link should bring back representation of resource including (changed) bump status";
curl -i -X GET -H 'Accept: application/json' -H 'Connection: close' -H 'X-APIKey: 798e31c43d6b9f03aa504a6f88cb4550' -u 'test05:test' $BUMPLINK >/tmp/x
RV1=$(cat /tmp/x | grep "HTTP/1.1" | grep -v "X-Testing-Dupe: " | cut -c 10-12)
if [[ "$RV1" != "200" ]]; then
    echo ""
    echo "Third GET failed :-(\n";
    echo $RV1
    exit;
fi;
RESF2=$(cat /tmp/x | grep '"bumped":"false"')
REST2=$(cat /tmp/x | grep '"bumped":"true"')
if [[ "$RESF2" != "" ]]; then
    if [[ "$REST" == "" ]]; then
	echo "Bumped status was false and still is :-(\n";
	exit;
    fi
elif [[ "$REST2" != "" ]]; then
    if [[ "$RESF" == "" ]]; then
	echo "Bumped status was true and still is :-(\n";
	exit;
    fi
else
    echo ""
    echo "Resource not found at bump link, or bumped status was not true or false :-(\n";
    cat /tmp/x
    exit;
fi;
 
echo "Completed successfully"

And a sample run, this one changing the bump from false to true:

$ acceptance_tests/bash_storyboard_03.sh
First POST to visit link should 201 and provide translation link
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   213  100    93  100   120    881   1137 --:--:-- --:--:-- --:--:--  1212
First GET to translation link by Visit SID should bring back representation and bump link
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   290  100   290    0     0   2762      0 --:--:-- --:--:-- --:--:--  2929
First GET to bump link should bring back representation of resource including bump status
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   238  100   238    0     0   2255      0 --:--:-- --:--:-- --:--:--  2404
Bumped is false, so will change to true
First PUT to bump link should 201
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   262  100    26  100   236    178   1624 --:--:-- --:--:-- --:--:--  1685
Second GET to bump link should bring back representation of resource including bump status
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   237  100   237    0     0   2276      0 --:--:-- --:--:-- --:--:--  2393
Completed successfully
$