From 02fe01a3cff928ea2f13a9d6891fdda136c2ebd9 Mon Sep 17 00:00:00 2001 From: mattisafur <46404761+mattisafur@users.noreply.github.com> Date: Fri, 26 Jul 2024 14:26:46 +0300 Subject: [PATCH] Started 3rd part of wog project --- Dockerfile | 11 +++++++++++ Jenkinsfile | 14 ++++++++++++++ docker-compose.yml | 5 +++++ e2e.py | 39 +++++++++++++++++++++++++++++++++++++++ main_score.py | 2 +- requirements.txt | 1 - 6 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 Dockerfile create mode 100644 Jenkinsfile create mode 100644 docker-compose.yml create mode 100644 e2e.py diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..24a6f9f --- /dev/null +++ b/Dockerfile @@ -0,0 +1,11 @@ +FROM python:alpine + +WORKDIR /app + +COPY main_score.py . +COPY utils.py . +RUN echo 800 > Scores.txt + +RUN pip install Flask + +CMD ["python", "main_score.py"] diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..673dfd7 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,14 @@ +properties([pipelineTriggers([pollSCM('H * * * *')])]) + +pipeline { + stages { + stage('Checkout') { + steps { + checkout scm + } + } + stage('Build') { + docker build + } + } +} \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..3b6ba0f --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,5 @@ +services: + web: + image: python:alpine + ports: + - 8777:5000 \ No newline at end of file diff --git a/e2e.py b/e2e.py new file mode 100644 index 0000000..5b0adae --- /dev/null +++ b/e2e.py @@ -0,0 +1,39 @@ +"""End to end tests for main_score.py""" + +import sys +import selenium +import selenium.webdriver +from selenium.webdriver.common.by import By + +import input_validation + + +def test_scores_service(url: str) -> bool: + """Tests if score shows up in website and is between 1 and 1000""" + with selenium.webdriver.Firefox() as driver: + driver.get(url) + + # raise error if website returns an error + title = driver.find_element(By.XPATH, "/html/body/h1").text + if title == "ERROR:": + raise ValueError + + # get and parse scoreERROR: + score = driver.find_element(By.ID, "score").text + + parsed_score = input_validation.validate_int(score) + if parsed_score is not None: + if 1 <= parsed_score <= 1000: + return True + else: + return False + else: + raise ValueError + + +def main_function() -> None: + """Calls test_score_service exists with a return code ased on the result of the function""" + if test_scores_service("http://127.0.0.1:8777"): + sys.exit(0) + else: + sys.exit(-1) diff --git a/main_score.py b/main_score.py index 3281b44..bd6b487 100644 --- a/main_score.py +++ b/main_score.py @@ -35,4 +35,4 @@ def main_page() -> str: ''' -score_website.run() +score_website.run('0.0.0.0') diff --git a/requirements.txt b/requirements.txt index e7e0dea..9033659 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,4 @@ currencyapicom==0.1.1 keyboard==0.13.5 Flask==3.0.3 -webdriver-manager==4.0.1 selenium==4.23.0