Skip to content

Commit

Permalink
Started 3rd part of wog project
Browse files Browse the repository at this point in the history
  • Loading branch information
mattisafur committed Jul 26, 2024
1 parent 72bef2b commit 02fe01a
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 2 deletions.
11 changes: 11 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
14 changes: 14 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
properties([pipelineTriggers([pollSCM('H * * * *')])])

pipeline {
stages {
stage('Checkout') {
steps {
checkout scm
}
}
stage('Build') {
docker build
}
}
}
5 changes: 5 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
services:
web:
image: python:alpine
ports:
- 8777:5000
39 changes: 39 additions & 0 deletions e2e.py
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 1 addition & 1 deletion main_score.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ def main_page() -> str:
</body>
</html>'''

score_website.run()
score_website.run('0.0.0.0')
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 02fe01a

Please sign in to comment.