Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tests #130

Merged
merged 37 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
6b111cd
remove function from tests
Oct 4, 2023
6fdb96f
fix test
Oct 4, 2023
35ad0de
cleanup update with delete_project_now
Oct 4, 2023
11c0823
black style
Oct 4, 2023
3dcaa24
update project delete
Oct 4, 2023
b5076e0
add init_sync_from_db and functions
Oct 5, 2023
78de23e
tests for init from db
Oct 5, 2023
bde3d47
tests data
Oct 5, 2023
2105ea2
update tests
Oct 6, 2023
d8efbec
update description
Oct 6, 2023
89b2d90
use functions to make test more general
Oct 6, 2023
5dbfba4
skip test due to changes in MM
Oct 6, 2023
d21d46d
use functions
Oct 6, 2023
b915dce
simplify
Oct 11, 2023
4fe240b
add docstrings
Oct 11, 2023
e08b734
docstring
Oct 11, 2023
05eaeb3
sql file as parameter
Oct 11, 2023
7e3e746
constant schema names
Oct 11, 2023
70e9f9c
update sql files for tests
Oct 11, 2023
412de1c
simplify tests according to review
Oct 11, 2023
5169f7f
do not skip test
Oct 11, 2023
4cc4bb8
install from requirements files
Dec 8, 2023
dc21f42
Merge branch 'fix_test_workflow' into fix-tests
Dec 8, 2023
5cb924f
remove
Dec 8, 2023
d659e93
require versions
Dec 8, 2023
5d956e2
files that trigger testing
Dec 8, 2023
57bcc93
run only basic tests
Dec 8, 2023
82e07a9
fix project info obtaining using updated mergin-client api
Dec 8, 2023
3e7f934
correctly access project info
Dec 8, 2023
72a99f6
need to actively read project metadata, otherwise old info is stored
Dec 8, 2023
c16e04a
correctly convert to list
Dec 8, 2023
fa64ffb
Revert "run only basic tests"
Dec 8, 2023
fe907a3
removed deprecated metadata calls
Dec 9, 2023
93bda81
use full project name
Dec 9, 2023
04d0a51
fix skip tables
Dec 9, 2023
cfabb8b
fix ignored tables setup
Dec 9, 2023
59cf6c5
install using requirements.txt
Dec 9, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/build_windows.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ jobs:

- name: Install dependencies
run: |
python -m pip install dynaconf pyinstaller mergin-client psycopg2
python -m pip install -r requirements.txt
python -m pip install pyinstaller

- name: Build Binary
run: |
Expand Down
11 changes: 8 additions & 3 deletions .github/workflows/tests_mergin_db_sync.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ on:
paths:
- "test/**"
- "**.py"
- "requirements.txt"
- "requirements-dev.txt"
- "pyproject.toml"
- ".github/workflows/tests_mergin_db_sync.yaml"

env:
Expand Down Expand Up @@ -46,14 +49,16 @@ jobs:

- name: Check Geodiff version
run: geodiff version

- name: Checkout
uses: actions/checkout@v4

- name: Install Python dependencies
run: |
python3 -m pip install --upgrade pip
python3 -m pip install mergin-client pytest pytest-cov dynaconf psycopg2
python3 -m pip install -r requirements.txt
python3 -m pip install -r requirements-dev.txt

- name: Checkout
uses: actions/checkout@v2

- name: Run tests
run: |
Expand Down
5 changes: 5 additions & 0 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import tempfile

from dynaconf import Dynaconf
import dynaconf

from smtp_functions import create_connection_and_log_user

Expand Down Expand Up @@ -158,6 +159,10 @@ def get_ignored_tables(
connection.skip_tables,
list,
):
if len(connection.skip_tables) < 1:
return []
elif isinstance(connection.skip_tables, dynaconf.vendor.box.box_list.BoxList):
return connection.skip_tables.to_list()
return connection.skip_tables
else:
return []
Expand Down
40 changes: 16 additions & 24 deletions dbsync.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,9 +525,7 @@ def _print_mergin_changes(
cached_mergin_project_objects = {}


def _get_mergin_project(
work_path,
):
def _get_mergin_project(work_path) -> MerginProject:
"""
Returns a cached MerginProject object or creates one if it does not exist yet.
This is to avoid creating many of these objects (e.g. every pull/push) because it does
Expand All @@ -538,23 +536,20 @@ def _get_mergin_project(
"""
if work_path not in cached_mergin_project_objects:
cached_mergin_project_objects[work_path] = MerginProject(work_path)
cached_mergin_project_objects[work_path]._read_metadata()
return cached_mergin_project_objects[work_path]


def _get_project_version(
work_path,
):
def _get_project_version(work_path) -> str:
"""Returns the current version of the project"""
mp = _get_mergin_project(work_path)
return mp.metadata["version"]
return mp.version()


def _get_project_id(
mp,
):
def _get_project_id(mp: MerginProject):
"""Returns the project ID"""
try:
project_id = uuid.UUID(mp.metadata["project_id"])
project_id = uuid.UUID(mp.project_id())
except (
KeyError,
ValueError,
Expand Down Expand Up @@ -636,10 +631,9 @@ def _validate_local_project_id(
local_project_id = _get_project_id(mp)
if local_project_id is None:
return
project_path = mp.metadata["name"]
if server_info is None:
try:
server_info = mc.project_info(project_path)
server_info = mc.project_info(mp.project_full_name())
except ClientError as e:
raise DbSyncError("Mergin Maps client error: " + str(e))

Expand Down Expand Up @@ -718,7 +712,7 @@ def revert_local_changes(
mp.dir,
update_delete_file,
update_delete_filepath,
mp.metadata["version"],
mp.version(),
)
except ClientError as e:
raise DbSyncError("Mergin Maps client error: " + str(e))
Expand Down Expand Up @@ -754,12 +748,11 @@ def pull(conn_cfg, mc):
# Make sure that local project ID (if available) is the same as on the server
_validate_local_project_id(mp, mc)

project_path = mp.metadata["name"]
local_version = mp.metadata["version"]
local_version = mp.version()

try:
projects = mc.get_projects_by_names([project_path])
server_version = projects[project_path]["version"]
projects = mc.get_projects_by_names([mp.project_full_name()])
server_version = projects[mp.project_full_name()]["version"]
except ClientError as e:
# this could be e.g. DNS error
raise DbSyncError("Mergin Maps client error: " + str(e))
Expand Down Expand Up @@ -900,8 +893,8 @@ def status(conn_cfg, mc):
mp.set_tables_to_skip(ignored_tables)
if mp.geodiff is None:
raise DbSyncError("Mergin Maps client installation problem: geodiff not available")
project_path = mp.metadata["name"]
local_version = mp.metadata["version"]
project_path = mp.project_full_name()
local_version = mp.version()
logging.debug("Checking status...")
try:
server_info = mc.project_info(
Expand Down Expand Up @@ -1009,12 +1002,11 @@ def push(conn_cfg, mc):
# Make sure that local project ID (if available) is the same as on the server
_validate_local_project_id(mp, mc)

project_path = mp.metadata["name"]
local_version = mp.metadata["version"]
local_version = mp.version()

try:
projects = mc.get_projects_by_names([project_path])
server_version = projects[project_path]["version"]
projects = mc.get_projects_by_names([mp.project_full_name()])
server_version = projects[mp.project_full_name()]["version"]
except ClientError as e:
# this could be e.g. DNS error
raise DbSyncError("Mergin Maps client error: " + str(e))
Expand Down
2 changes: 2 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pytest>=6.2
pytest-cov>=3.0
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
mergin-client>=0.8.3
mergin-client==0.9.0
dynaconf>=3.1
psycopg2>=2.9
Loading