added tests and scan for releases

This commit is contained in:
2023-12-01 01:26:38 +01:00
parent b2e49bf99c
commit cb9e02f4a2
7 changed files with 111 additions and 10 deletions

View File

@@ -2,4 +2,7 @@ pillow
python-magic
progressbar
virtualenv
requests
requests
pytest==7.4.*
pytest-cov==4.1.*
pytest-factoryboy==2.5.*

0
src/__init__.py Normal file
View File

View File

@@ -1,10 +1,10 @@
class ExifData:
"""This is for an object that stores the data of a picture"""
def __init__(self, image_path, image_name, day, month, year, time, make) -> None:
self.path = image_path
self.name = image_name
self.day = int(day)
self.month = int(month)
def __init__(self, image_path:str, image_name:str, day:int, month:int, year:int, time:int, make:str) -> None:
self.path:str = image_path
self.name:str = image_name
self.day:int = int(day)
self.month:int = int(month)
self.year = int(year)
self.time = str(time)
self.make = str(make)

View File

@@ -2,17 +2,66 @@ import requests
import json
class Version:
def __init__(self, data:dict):
self.version:str = data['version']
self.version_int:int = int(self.version.replace(".", ""))
self.date:str = data['date']
class Release:
def __init__(self, data:dict):
self.name = data['name']
self.tag_name = data['tag_name']
self.description = data['description']
self.created_at = data['created_at']
self.released_at = data['released_at']
self.upcoming_release = data['upcoming_release']
self.version_int = int(self.tag_name.replace(".", ""))
self.zip_file_url = data['assets']['sources']
self.__proceed()
def __proceed(self):
for assest in self.zip_file_url:
if assest['format'] == 'zip':
self.zip_file_url = assest['url']
break
def read_version():
with open(file=".version.json") as file:
version = json.load(file)
version = Version(json.load(file))
return version
def install():
pass
def check_for_update():
request = "https://gitlab.com/DasMoorhuhn/autopicture-v3/-/raw/main/src/.version.json"
response = requests.get(request)
version_current = read_version()
request = "https://gitlab.com/api/v4/projects/52637155/releases"
response = requests.get(url=request, timeout=1)
if not response.ok: return
print(response.text)
# Get the latest release
releases_json = json.loads(response.text)
# index version
latest_release = [0, 0]
for release_json in releases_json:
release = Release(release_json)
if release.version_int > version_current.version_int:
latest_release[0] = releases_json.index(release_json)
latest_release[1] = release.version_int
if latest_release == [0, 0]: return
release = Release(releases_json[latest_release[0]])
print(f"v{version_current.version} -> v{release.tag_name}")
if release.version_int > version_current.version_int:
# Update
print("Update")
print(release.zip_file_url)
check_for_update()

30
test.gitlab-ci.yml Normal file
View File

@@ -0,0 +1,30 @@
prepare_job:
stage: prepare # This stage must run before the release stage
rules:
- if: $CI_COMMIT_TAG
when: never # Do not run this job when a tag is created manually
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH # Run this job when commits are pushed or merged to the default branch
script:
- echo "EXTRA_DESCRIPTION=some message" >> variables.env # Generate the EXTRA_DESCRIPTION and TAG environment variables
- echo "TAG=v$(cat VERSION)" >> variables.env # and append to the variables.env file
artifacts:
reports:
dotenv: variables.env # Use artifacts:reports:dotenv to expose the variables to other jobs
release_job:
stage: release
image: registry.gitlab.com/gitlab-org/release-cli:latest
needs:
- job: prepare_job
artifacts: true
rules:
- if: $CI_COMMIT_TAG
when: never # Do not run this job when a tag is created manually
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH # Run this job when commits are pushed or merged to the default branch
script:
- echo "running release_job for $TAG"
release:
name: 'Release $TAG'
description: 'Created using the release-cli $EXTRA_DESCRIPTION' # $EXTRA_DESCRIPTION and the $TAG
tag_name: '$TAG' # variables must be defined elsewhere
ref: '$CI_COMMIT_SHA' # in the pipeline. For example, in the

0
tests/__init__.py Normal file
View File

19
tests/test_exif_data.py Normal file
View File

@@ -0,0 +1,19 @@
import unittest
import sys
sys.path.append("../")
from src.exif_data import ExifData
class TestExifData(unittest.TestCase):
exif_data = ExifData(image_path="/my/path/lol",
image_name="Secret.png",
make="SALAMI",
day=10,
month=10,
year=1010,
time=1237127392
)
assert exif_data.name == "Secret.png"
assert exif_data.make == "SALAMI"