creating stub classes and functions for every dataclass object. This will be the foundation for the traffic-light system, as the tests will be based on artificial entries (stubs) instead of data from the real system. tests will be added soon.
This commit is contained in:
parent
a25c786b3c
commit
a4b70006f9
3
.gitignore
vendored
3
.gitignore
vendored
@ -439,4 +439,7 @@ FodyWeavers.xsd
|
||||
change_log_metz.md
|
||||
src/notebooks_metz
|
||||
**.egg-info
|
||||
docs/traffic_light_examples
|
||||
**/.~lock*
|
||||
misc/berths_and_terminals.csv
|
||||
|
||||
|
||||
5
src/lib_brecal_utils/brecal_utils/stubs/__init__.py
Normal file
5
src/lib_brecal_utils/brecal_utils/stubs/__init__.py
Normal file
@ -0,0 +1,5 @@
|
||||
|
||||
def generate_uuid1_int():
|
||||
"""# TODO: clarify, what kind of integer ID is used in mysql"""
|
||||
from uuid import uuid1
|
||||
return uuid1().int>>64
|
||||
27
src/lib_brecal_utils/brecal_utils/stubs/berth.py
Normal file
27
src/lib_brecal_utils/brecal_utils/stubs/berth.py
Normal file
@ -0,0 +1,27 @@
|
||||
import datetime
|
||||
from brecal_utils.stubs import generate_uuid1_int
|
||||
from BreCal.schemas.model import Berth
|
||||
|
||||
def get_berth_simple():
|
||||
berth_id = generate_uuid1_int() # uid?
|
||||
|
||||
# Note: #TODO: name, participant_id & lock state are arbitrary
|
||||
name = "Avangard Dalben"
|
||||
participant_id = 1 # e.g., Avangard
|
||||
lock = False
|
||||
|
||||
created = datetime.datetime.now()
|
||||
modified = created+datetime.timedelta(seconds=10)
|
||||
deleted = modified+datetime.timedelta(seconds=3)
|
||||
|
||||
berth = Berth(
|
||||
berth_id,
|
||||
name,
|
||||
participant_id,
|
||||
lock,
|
||||
created,
|
||||
modified,
|
||||
deleted,
|
||||
)
|
||||
return berth
|
||||
|
||||
32
src/lib_brecal_utils/brecal_utils/stubs/participant.py
Normal file
32
src/lib_brecal_utils/brecal_utils/stubs/participant.py
Normal file
@ -0,0 +1,32 @@
|
||||
import datetime
|
||||
from brecal_utils.stubs import generate_uuid1_int
|
||||
from BreCal.schemas.model import Participant
|
||||
|
||||
def get_participant_simple():
|
||||
participant_id = generate_uuid1_int()
|
||||
|
||||
# #TODO: role_type and flags are arbitrary
|
||||
name = "Max Mustermann"
|
||||
street = "Musterstrasse 1"
|
||||
postal_code = "12345"
|
||||
city = "Bremen"
|
||||
role_type = 1 # integer
|
||||
flags = 0 # integer. unclear
|
||||
|
||||
created = datetime.datetime.now()
|
||||
modified = created+datetime.timedelta(seconds=10)
|
||||
deleted = modified+datetime.timedelta(seconds=3)
|
||||
|
||||
participant = Participant(
|
||||
participant_id,
|
||||
name,
|
||||
street,
|
||||
postal_code,
|
||||
city,
|
||||
role_type,
|
||||
flags,
|
||||
created,
|
||||
modified,
|
||||
deleted
|
||||
)
|
||||
return participant
|
||||
0
src/lib_brecal_utils/brecal_utils/stubs/roles.py
Normal file
0
src/lib_brecal_utils/brecal_utils/stubs/roles.py
Normal file
39
src/lib_brecal_utils/brecal_utils/stubs/ship.py
Normal file
39
src/lib_brecal_utils/brecal_utils/stubs/ship.py
Normal file
@ -0,0 +1,39 @@
|
||||
import datetime
|
||||
from brecal_utils.stubs import generate_uuid1_int
|
||||
from BreCal.schemas.model import Ship
|
||||
|
||||
def get_ship_simple():
|
||||
ship_id = generate_uuid1_int()
|
||||
name = "african halcyon".upper() # 'Schiffe_sample_format.xlsx' uses .upper() for every ship
|
||||
imo = 9343613 # assert str(len(imo))==7
|
||||
callsign = 1234567 # up to 7 characters. assert str(len(callsign))<=7
|
||||
participant_id = generate_uuid1_int()
|
||||
length = 177.13 # assert 0>length<=500
|
||||
width = 28.4 # assert 0>width<=500
|
||||
is_tug = False
|
||||
bollard_pull = None # only if is_tug
|
||||
participant_id = None # only if is_tug
|
||||
eni = "01234567" # Alternative to IMO. Dynamic assertion?. assert len(str(eni))==8
|
||||
|
||||
created = datetime.datetime.now()
|
||||
modified = created+datetime.timedelta(seconds=10)
|
||||
deleted = modified+datetime.timedelta(seconds=3)
|
||||
|
||||
|
||||
ship = Ship(
|
||||
ship_id,
|
||||
name,
|
||||
imo,
|
||||
callsign,
|
||||
participant_id,
|
||||
length,
|
||||
width,
|
||||
is_tug,
|
||||
bollard_pull,
|
||||
eni,
|
||||
created,
|
||||
modified,
|
||||
deleted
|
||||
)
|
||||
return ship
|
||||
|
||||
76
src/lib_brecal_utils/brecal_utils/stubs/shipcall.py
Normal file
76
src/lib_brecal_utils/brecal_utils/stubs/shipcall.py
Normal file
@ -0,0 +1,76 @@
|
||||
import datetime
|
||||
from brecal_utils.stubs import generate_uuid1_int
|
||||
from BreCal.schemas.model import Shipcall
|
||||
from dataclasses import field
|
||||
|
||||
def get_shipcall_simple():
|
||||
base_time = datetime.datetime.now()
|
||||
|
||||
shipcall_id = generate_uuid1_int()
|
||||
ship_id = generate_uuid1_int()
|
||||
|
||||
eta = base_time+datetime.timedelta(hours=3, minutes=12)
|
||||
role_type = 1
|
||||
voyage = "987654321"
|
||||
etd = base_time+datetime.timedelta(hours=6, minutes=12) # should never be before eta
|
||||
|
||||
arrival_berth_id = generate_uuid1_int()
|
||||
departure_berth_id = generate_uuid1_int()
|
||||
|
||||
tug_required = False
|
||||
pilot_required = False
|
||||
|
||||
flags = 0 # #TODO_shipcall_flags. What is meant here? What should be tested?
|
||||
pier_side = False # whether a ship will be fixated on the pier side. en: pier side, de: Anlegestelle
|
||||
bunkering = False # #TODO_bunkering_unclear
|
||||
replenishing_terminal = False # en: replenishing terminal, de: Nachfüll-Liegeplatz
|
||||
replenishing_lock = False # en: replenishing lock, de: Nachfüllschleuse
|
||||
|
||||
draft = 0.12 # #TODO_draft_value: clarify, what 'draft' means and what kind of values are to be expected
|
||||
|
||||
# tidal window: built in a way, where ETA and ETD are in-between the window
|
||||
# #TODO_tidal_window_source: are these windows taken from a database or provided by the user? How do they know this?
|
||||
tidal_window_from = base_time+datetime.timedelta(hours=2, minutes=12)
|
||||
tidal_window_to = base_time+datetime.timedelta(hours=7, minutes=12)
|
||||
rain_sensitive_cargo = False
|
||||
recommended_tugs = 2 # assert 0<recommended_tugs<={threshold}. E.g., 20 should not be exceeded.
|
||||
anchored = False
|
||||
moored_lock = False # de: 'Festmacherschleuse', en: 'moored lock'
|
||||
|
||||
canceled = False
|
||||
created = datetime.datetime.now()
|
||||
modified = created+datetime.timedelta(seconds=10)
|
||||
|
||||
participants = field(default_factory=[generate_uuid1_int(), generate_uuid1_int(), generate_uuid1_int(), generate_uuid1_int()]) # list
|
||||
|
||||
shipcall = Shipcall(
|
||||
shipcall_id,
|
||||
ship_id,
|
||||
role_type,
|
||||
eta,
|
||||
voyage,
|
||||
etd,
|
||||
arrival_berth_id,
|
||||
departure_berth_id,
|
||||
tug_required,
|
||||
pilot_required,
|
||||
flags,
|
||||
pier_side,
|
||||
bunkering,
|
||||
replenishing_terminal,
|
||||
replenishing_lock,
|
||||
draft,
|
||||
tidal_window_from,
|
||||
tidal_window_to,
|
||||
rain_sensitive_cargo,
|
||||
recommended_tugs,
|
||||
anchored,
|
||||
moored_lock,
|
||||
canceled,
|
||||
created,
|
||||
modified,
|
||||
participants,
|
||||
)
|
||||
return Shipcall
|
||||
|
||||
|
||||
5
src/lib_brecal_utils/brecal_utils/stubs/times_full.py
Normal file
5
src/lib_brecal_utils/brecal_utils/stubs/times_full.py
Normal file
@ -0,0 +1,5 @@
|
||||
"""
|
||||
this stub creates an example time object, where the times of every role are present.
|
||||
users will thereby be able to modify these values
|
||||
"""
|
||||
|
||||
6
src/lib_brecal_utils/brecal_utils/stubs/tugs.py
Normal file
6
src/lib_brecal_utils/brecal_utils/stubs/tugs.py
Normal file
@ -0,0 +1,6 @@
|
||||
|
||||
|
||||
def get_tug_simple():
|
||||
raise NotImplementedError("unclarified")
|
||||
return
|
||||
|
||||
35
src/lib_brecal_utils/brecal_utils/stubs/user.py
Normal file
35
src/lib_brecal_utils/brecal_utils/stubs/user.py
Normal file
@ -0,0 +1,35 @@
|
||||
import bcrypt
|
||||
import datetime
|
||||
from brecal_utils.stubs import generate_uuid1_int
|
||||
from BreCal.schemas.model import User
|
||||
|
||||
|
||||
def get_user_simple():
|
||||
user_id = generate_uuid1_int()
|
||||
participant_id = generate_uuid1_int() # should be taken from the database
|
||||
|
||||
first_name = "Max"
|
||||
last_name = "Mustermann"
|
||||
user_name = "maxm123"
|
||||
user_email = "max.mustermann@brecal.de"
|
||||
user_phone = "0173123456" # formatting?
|
||||
password_hash = bcrypt.hashpw("123456".encode('utf-8'), bcrypt.gensalt( 12 )).decode('utf8')
|
||||
api_key = bcrypt.hashpw("apikey123".encode('utf-8'), bcrypt.gensalt( 12 )).decode('utf8')
|
||||
|
||||
created = datetime.datetime.now()
|
||||
modified = created+datetime.timedelta(seconds=10)
|
||||
|
||||
user = User(
|
||||
user_id,
|
||||
participant_id,
|
||||
first_name,
|
||||
last_name,
|
||||
user_name,
|
||||
user_email,
|
||||
user_phone,
|
||||
password_hash,
|
||||
api_key,
|
||||
created,
|
||||
modified
|
||||
)
|
||||
return user
|
||||
Reference in New Issue
Block a user