Skip to content
Snippets Groups Projects
Commit c6818472 authored by piscione's avatar piscione
Browse files

Merge branch 'TTF_T027' of https://forge.etsi.org/rep/mec/gs032p3-robot-test-suite into TTF_T027

parents 5160fd67 ad0d14ce
No related branches found
No related tags found
1 merge request!3Merge of TT027 branch into master
Pipeline #17766 failed
##Docker file containing the environment for running robot3.1 based on python3.9
## As example, MEC016 test suite are used
##How to run this container.
## Build the image using this docker file, make sure the server side is up and running and eventually run the tests.
FROM python:3.10-slim
RUN addgroup robot && adduser -D -G robot -h /home/robot robot
WORKDIR /home/robot
# Install system packages
RUN apt-get update && apt-get install -y \
build-essential \
libssl-dev \
libffi-dev
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY libraries libraries
# Guide to Run Robot Tests in a Docker Container
This guide provides instructions on how to build a Docker image and run Robot Framework tests in a Docker container.
## Prerequisites
- Docker must be installed and running on your system.
## Steps
### 1. Build the Docker Image
To build the Docker image, navigate to the root directory of your project and run the following script:
```sh
$ ./docker/build_img.sh
```
### 2. Run the Test
To execute a Robot Framework test, use the following script and specify the path to the test file relative to the root directory:
```sh
$ ./docker/run_test.sh <robot_test_file_from_root>
```
### Example
Here is an example of how to run a specific test file:
```sh
$ ./docker/run_test.sh MEC029/SRV/FAIS/PlatFixedAcessInfo.robot
```
## Notes
- Ensure that the specified test file path is correct and accessible from the root directory.
## Troubleshooting
- If you encounter any issues with Docker, ensure that your Docker service is running and that you have the necessary permissions to execute Docker commands.
- Verify that the test file exists and that the path is correct.
## Additional Resources
- [Docker Documentation](https://docs.docker.com/)
- [Robot Framework Documentation](https://robotframework.org/)
\ No newline at end of file
#!/bin/bash
script_dir_path=$(dirname "$(realpath "$0")")
dockerfile_path="${script_dir_path}/Dockerfile"
docker build -f "${dockerfile_path}" "${script_dir_path}/.." -t ttf-robot-img:latest
#!/bin/bash
# Function to display usage message
usage() {
echo "Usage: $0 testname"
exit 1
}
if [ "$#" -ne 1 ]; then
usage
fi
testname=$1
if [ -f "$testname" ]; then
full_dir_path=$(dirname "$(realpath "$testname")")
echo "Running the test: $(realpath "$testname")"
else
echo "The file '$testname' does not exist."
exit 1
fi
script_dir_path=$(dirname "$(realpath "$0")")
root_path="${script_dir_path}/../"
docker run --rm -it --name etsi-ttf-robot \
-v "${root_path}":/home/robot \
--workdir "/home/robot/" \
-e TEST_FILE="${testname}" \
ttf-robot-img:latest \
python -m robot -X "${TEST_FILE}"
#!/usr/bin/python3
from http.server import BaseHTTPRequestHandler, HTTPServer
import json
# Library version
__version__ = '0.0.1'
class Server ( object ):
ROBOT_LIBRARY_VERSION = '0.0.1'
def spawn_web_server (self, host, port, timeout, method, endpoint, resp_body):
class GET_Server(BaseHTTPRequestHandler):
def __call__(self, *args, **kwargs):
"""Handle a request."""
super().__init__(*args, **kwargs)
def __init__(self, endpoint, resp_body):
self.resp_body = resp_body
self.endpoint = endpoint
def do_GET(self):
self.send_response(200)
self.send_header('Content-Type', 'application/json')
self.end_headers()
if self.path == self.endpoint:
self.wfile.write(json.dumps(self.resp_body).encode(encoding='utf_8'))
else:
self.wfile.write(json.dumps("wrong endpoint").encode(encoding='utf_8'))
class POST_Server(BaseHTTPRequestHandler):
def __call__(self, *args, **kwargs):
"""Handle a request."""
super().__init__(*args, **kwargs)
def __init__(self, endpoint, resp_body):
self.resp_body = resp_body
self.endpoint = endpoint
def do_POST(self):
self.send_response(200)
self.send_header('Content-Type', 'application/json')
self.end_headers()
if self.path == self.endpoint:
self.wfile.write(json.dumps(self.resp_body).encode(encoding='utf_8'))
else:
self.wfile.write(json.dumps("wrong endpoint").encode(encoding='utf_8'))
class PUT_Server(BaseHTTPRequestHandler):
def __call__(self, *args, **kwargs):
"""Handle a request."""
super().__init__(*args, **kwargs)
def __init__(self, endpoint, resp_body):
self.resp_body = resp_body
self.endpoint = endpoint
def do_PUT(self):
self.send_response(200)
self.send_header('Content-Type', 'application/json')
self.end_headers()
if self.path == self.endpoint:
self.wfile.write(json.dumps(self.resp_body).encode(encoding='utf_8'))
else:
self.wfile.write(json.dumps("wrong endpoint").encode(encoding='utf_8'))
class DELETE_Server(BaseHTTPRequestHandler):
def __call__(self, *args, **kwargs):
"""Handle a request."""
super().__init__(*args, **kwargs)
def __init__(self, endpoint, resp_body):
self.resp_body = resp_body
self.endpoint = endpoint
def do_DELETE(self):
self.send_response(200)
self.send_header('Content-Type', 'application/json')
self.end_headers()
if self.path == self.endpoint:
self.wfile.write(json.dumps(self.resp_body).encode(encoding='utf_8'))
else:
self.wfile.write(json.dumps("wrong endpoint").encode(encoding='utf_8'))
if method == "GET":
self.handler = GET_Server(endpoint, resp_body)
elif method == "POST":
self.handler = POST_Server(endpoint, resp_body)
elif method == "PUT":
self.handler = PUT_Server(endpoint, resp_body)
elif method == "DELETE":
self.handler = DELETE_Server(endpoint, resp_body)
else:
print("Error, unknown endpoint")
exit(1)
self.app = HTTPServer((host, int(port)), self.handler)
self.app.timeout = int(timeout)
self.app.handle_request()
self.app.server_close()
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment