Skip to content

API Data Test

Test Case Description Verify that the data from the backend is the same as Digitraffic Api data
Test Case ID TCBE-003
Author/Designer Alan Ousi
Date of Creation 10.07.2023
Class Backend

Introduction

This document provides an explanation of the backend data test code. The code performs an API test on Tukko and Digitraffic to compare data from their respective stations. The following sections outline the purpose, functionality, and key components of the code.

Purpose

The purpose of the backend data test code is to verify the consistency and correctness of station data between Tukko and Digitraffic APIs. It retrieves station data from both APIs, compares the IDs and names of the stations, and checks if they match.

Functionality

The code operates as follows:

  1. Get data from Tukko: This step retrieves station data from the Tukko API. - The code creates a session with the Tukko API. - It sends a GET request to the /tms/stations endpoint to fetch the data. - The response content is stored in the Get_Response_Tukko variable. - The JSON response is converted to a Python dictionary using the Convert String to JSON keyword from the JSONLibrary. - The IDs and names of the stations are extracted from the parsed JSON using the Get Value From Json keyword.

  2. Get data from Digitraffic: This step retrieves station data from the Digitraffic API. - The code creates a session with the Digitraffic API. - It sends a GET request to the /stations endpoint to retrieve the data. - The response content is stored in the Get_Response_Digi variable. - The JSON response is converted to a Python dictionary using the Convert String to JSON keyword. - The IDs and names of the stations are extracted from the parsed JSON using the Get Value From Json keyword.

  3. Compare Tukko and Digitraffic data: This step compares the IDs and names of the stations from both APIs. - The code uses the Should Be Equal and Should Be Equal As Strings keywords to check if the IDs and names fetched from Tukko and Digitraffic match. - If the IDs and names match, the test passes. Otherwise, it fails.

Key Components

The code consists of the following key components:

  1. RequestsLibrary: This library allows the code to send HTTP requests to the APIs.
  2. JSONLibrary: This library provides keywords for handling JSON data.
  3. Collections: This library is used implicitly for variable assignment and management.

Usage

To use the code, follow these steps:

  1. Ensure that the necessary libraries (RequestsLibrary, JSONLibrary, Collections) are installed.
  2. Set the value of ${Tukko_API} variable to the base URL of the Tukko API.
  3. Set the value of ${Digi_API} variable to the base URL of the Digitraffic API.
  4. Execute the test case TC_001.

Code

```robotframework Settings Documentation API test on Tukko

Library RequestsLibrary Library JSONLibrary Library Collections

Variables ${Tukko_API} http://localhost:3001 ${Digi_API} https://tie.Digitraffic.fi/api/tms/v1

Test Cases TC_001 # Get data from Tukko Create Session Tukko_Testing ${Tukko_API} ${Get_Response_Tukko} GET On Session Tukko_Testing /tms/stations ${json_response_Tukko} Set Variable ${Get_Response_Tukko.content} ${parsed_json_Tukko} Convert String to JSON ${json_response_Tukko} ${id_fetch_Tukko} Get Value From Json ${parsed_json_Tukko} $.stations[].id ${name_fetch_Tukko} Get Value From Json ${parsed_json_Tukko} $.stations[].name

# Get data from Digitraffic
Create Session    Digi_Testing    ${Digi_API}
${Get_Response_Digi}    GET On Session    Digi_Testing    /stations
${json_response_Digi}    Set Variable    ${Get_Response_Digi.content}
${parsed_json_Digi}    Convert String to JSON    ${json_response_Digi}
${id_fetch_Digi}    Get Value From Json    ${parsed_json_Digi}    $.features[*].id
${name_fetch_Digi}    Get Value From Json    ${parsed_json_Digi}    $..properties[*].name
Should Be Equal    ${id_fetch_Tukko}    ${id_fetch_Digi}
Should Be Equal As Strings    ${name_fetch_Tukko}    ${name_fetch_Digi}