Skip to content

Commit

Permalink
Creative testing
Browse files Browse the repository at this point in the history
  • Loading branch information
jochenklar committed Nov 29, 2024
1 parent ef9e35f commit 9e07a4e
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 45 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ jobs:
if: matrix.python-version == '3.12' && matrix.db-backend == 'postgres'
- name: Run Tests
run: |
pytest -p randomly -p no:cacheprovider --cov --reuse-db --numprocesses=auto --dist=loadscope rdmo/projects/tests/test_view_project_copy.py
pytest -s -p randomly -p no:cacheprovider --cov --reuse-db --numprocesses=auto --dist=loadscope rdmo/projects/tests/test_utils.py::test_copy_project
env:
GITHUB_DB_BACKEND: ${{ matrix.db-backend }}
- name: Upload coverage data to coveralls.io
Expand Down
93 changes: 49 additions & 44 deletions rdmo/projects/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,53 +70,58 @@ def test_copy_project(db, files):
assert snapshot_copy == snapshot

# check the values
value_fields = (
'attribute',
'set_prefix',
'set_collection',
'set_index',
'collection_index',
'text',
'option',
'value_type',
'unit',
'external_id'
)
# value_fields = (
# 'attribute',
# 'set_prefix',
# 'set_collection',
# 'set_index',
# 'collection_index',
# 'text',
# 'option',
# 'value_type',
# 'unit',
# 'external_id'
# )
ordering = (
'attribute',
'set_prefix',
'set_index',
'collection_index'
)
for value_copy, value in zip(
project_copy.values.filter(snapshot=None).order_by(*ordering),
project.values.filter(snapshot=None).order_by(*ordering)
):
for field in value_fields:
assert getattr(value_copy, field) == getattr(value, field), field

if value_copy.file:
assert value_copy.file.path == value_copy.file.path.replace(
f'/projects/{project.id}/values/{value.id}/',
f'/projects/{project_copy.id}/values/{value_copy.id}/'
)
assert value_copy.file.size == value_copy.file.size
else:
assert not value.file

for snapshot_copy, snapshot in zip(project_copy.snapshots.all(), project.snapshots.all()):
for value_copy, value in zip(
project_copy.values.filter(snapshot=snapshot_copy).order_by(*ordering),
project.values.filter(snapshot=snapshot).order_by(*ordering)
):
for field in value_fields:
assert getattr(value_copy, field) == getattr(value, field)

if value_copy.file:
assert value_copy.file.path == value_copy.file.path.replace(
f'/projects/{project.id}/snapshot/{snapshot.id}/values/{value.id}/',
f'/projects/{project_copy.id}/snapshot/{snapshot.id}/values/{value_copy.id}/'
)
assert value_copy.file.open('rb').read() == value_copy.file.open('rb').read()
else:
assert not value.file

assert \

Check failure on line 92 in rdmo/projects/tests/test_utils.py

View workflow job for this annotation

GitHub Actions / Test (Python: 3.8, DB: mysql)

test_copy_project AssertionError: assert 101 == 98 + where 101 = count() + where count = <ValueQuerySet [<Value: Test / - / 0 / 0 / 0>, <Value: Test / - / 0 / 1 / 0>, <Value: Test / - / 1 / 0 / 0>, <Value: T...|2 / 0 / 0>, <Value: Test / - / 1|2 / 1 / 0>, <Value: Test / - / 1|2 / 2 / 0>, '...(remaining elements truncated)...']>.count + where <ValueQuerySet [<Value: Test / - / 0 / 0 / 0>, <Value: Test / - / 0 / 1 / 0>, <Value: Test / - / 1 / 0 / 0>, <Value: T...|2 / 0 / 0>, <Value: Test / - / 1|2 / 1 / 0>, <Value: Test / - / 1|2 / 2 / 0>, '...(remaining elements truncated)...']> = order_by(*('attribute', 'set_prefix', 'set_index', 'collection_index')) + where order_by = <ValueQuerySet [<Value: Test / - / 1 / 0 / 0>, <Value: Test / - / 0 / 0 / 0>, <Value: Test / - / 0 / 1 / 0>, <Value: T...|2 / 0 / 0>, <Value: Test / - / 1|2 / 1 / 0>, <Value: Test / - / 1|2 / 2 / 0>, '...(remaining elements truncated)...']>.order_by + where <ValueQuerySet [<Value: Test / - / 1 / 0 / 0>, <Value: Test / - / 0 / 0 / 0>, <Value: Test / - / 0 / 1 / 0>, <Value: T...|2 / 0 / 0>, <Value: Test / - / 1|2 / 1 / 0>, <Value: Test / - / 1|2 / 2 / 0>, '...(remaining elements truncated)...']> = filter(snapshot=None) + where filter = <django.db.models.fields.related_descriptors.create_reverse_many_to_one_manager.<locals>.RelatedManager object at 0x7f9e980cfca0>.filter + where <django.db.models.fields.related_descriptors.create_reverse_many_to_one_manager.<locals>.RelatedManager object at 0x7f9e980cfca0> = <Project: Test>.values + and 98 = count() + where count = <ValueQuerySet [<Value: Test / - / 0 / 0 / 0>, <Value: Test / - / 0 / 1 / 0>, <Value: Test / - / 1 / 0 / 0>, <Value: T...|2 / 0 / 0>, <Value: Test / - / 1|2 / 1 / 0>, <Value: Test / - / 1|2 / 2 / 0>, '...(remaining elements truncated)...']>.count + where <ValueQuerySet [<Value: Test / - / 0 / 0 / 0>, <Value: Test / - / 0 / 1 / 0>, <Value: Test / - / 1 / 0 / 0>, <Value: T...|2 / 0 / 0>, <Value: Test / - / 1|2 / 1 / 0>, <Value: Test / - / 1|2 / 2 / 0>, '...(remaining elements truncated)...']> = order_by(*('attribute', 'set_prefix', 'set_index', 'collection_index')) + where order_by = <ValueQuerySet [<Value: Test / - / 0 / 0 / 0>, <Value: Test / - / 1 / 0 / 0>, <Value: Test / - / 0 / 1 / 0>, <Value: T...|2 / 0 / 0>, <Value: Test / - / 1|2 / 1 / 0>, <Value: Test / - / 1|2 / 2 / 0>, '...(remaining elements truncated)...']>.order_by + where <ValueQuerySet [<Value: Test / - / 0 / 0 / 0>, <Value: Test / - / 1 / 0 / 0>, <Value: Test / - / 0 / 1 / 0>, <Value: T...|2 / 0 / 0>, <Value: Test / - / 1|2 / 1 / 0>, <Value: Test / - / 1|2 / 2 / 0>, '...(remaining elements truncated)...']> = filter(snapshot=None) + where filter = <django.db.models.fields.related_descriptors.create_reverse_many_to_one_manager.<locals>.RelatedManager object at 0x7f9e9828bfa0>.filter + where <django.db.models.fields.related_descriptors.create_reverse_many_to_one_manager.<locals>.RelatedManager object at 0x7f9e9828bfa0> = <Project: Test>.values

Check failure on line 92 in rdmo/projects/tests/test_utils.py

View workflow job for this annotation

GitHub Actions / Test (Python: 3.12, DB: mysql)

test_copy_project AssertionError: assert 101 == 98 + where 101 = count() + where count = <ValueQuerySet [<Value: Test / - / 0 / 0 / 0>, <Value: Test / - / 0 / 1 / 0>, <Value: Test / - / 1 / 0 / 0>, <Value: T...|2 / 0 / 0>, <Value: Test / - / 1|2 / 1 / 0>, <Value: Test / - / 1|2 / 2 / 0>, '...(remaining elements truncated)...']>.count + where <ValueQuerySet [<Value: Test / - / 0 / 0 / 0>, <Value: Test / - / 0 / 1 / 0>, <Value: Test / - / 1 / 0 / 0>, <Value: T...|2 / 0 / 0>, <Value: Test / - / 1|2 / 1 / 0>, <Value: Test / - / 1|2 / 2 / 0>, '...(remaining elements truncated)...']> = order_by(*('attribute', 'set_prefix', 'set_index', 'collection_index')) + where order_by = <ValueQuerySet [<Value: Test / - / 1 / 0 / 0>, <Value: Test / - / 0 / 0 / 0>, <Value: Test / - / 0 / 1 / 0>, <Value: T...|2 / 0 / 0>, <Value: Test / - / 1|2 / 1 / 0>, <Value: Test / - / 1|2 / 2 / 0>, '...(remaining elements truncated)...']>.order_by + where <ValueQuerySet [<Value: Test / - / 1 / 0 / 0>, <Value: Test / - / 0 / 0 / 0>, <Value: Test / - / 0 / 1 / 0>, <Value: T...|2 / 0 / 0>, <Value: Test / - / 1|2 / 1 / 0>, <Value: Test / - / 1|2 / 2 / 0>, '...(remaining elements truncated)...']> = filter(snapshot=None) + where filter = <django.db.models.fields.related_descriptors.create_reverse_many_to_one_manager.<locals>.RelatedManager object at 0x7f069db1e7e0>.filter + where <django.db.models.fields.related_descriptors.create_reverse_many_to_one_manager.<locals>.RelatedManager object at 0x7f069db1e7e0> = <Project: Test>.values + and 98 = count() + where count = <ValueQuerySet [<Value: Test / - / 0 / 0 / 0>, <Value: Test / - / 0 / 1 / 0>, <Value: Test / - / 1 / 0 / 0>, <Value: T...|2 / 0 / 0>, <Value: Test / - / 1|2 / 1 / 0>, <Value: Test / - / 1|2 / 2 / 0>, '...(remaining elements truncated)...']>.count + where <ValueQuerySet [<Value: Test / - / 0 / 0 / 0>, <Value: Test / - / 0 / 1 / 0>, <Value: Test / - / 1 / 0 / 0>, <Value: T...|2 / 0 / 0>, <Value: Test / - / 1|2 / 1 / 0>, <Value: Test / - / 1|2 / 2 / 0>, '...(remaining elements truncated)...']> = order_by(*('attribute', 'set_prefix', 'set_index', 'collection_index')) + where order_by = <ValueQuerySet [<Value: Test / - / 0 / 0 / 0>, <Value: Test / - / 1 / 0 / 0>, <Value: Test / - / 0 / 1 / 0>, <Value: T...|2 / 0 / 0>, <Value: Test / - / 1|2 / 1 / 0>, <Value: Test / - / 1|2 / 2 / 0>, '...(remaining elements truncated)...']>.order_by + where <ValueQuerySet [<Value: Test / - / 0 / 0 / 0>, <Value: Test / - / 1 / 0 / 0>, <Value: Test / - / 0 / 1 / 0>, <Value: T...|2 / 0 / 0>, <Value: Test / - / 1|2 / 1 / 0>, <Value: Test / - / 1|2 / 2 / 0>, '...(remaining elements truncated)...']> = filter(snapshot=None) + where filter = <django.db.models.fields.related_descriptors.create_reverse_many_to_one_manager.<locals>.RelatedManager object at 0x7f069d181d30>.filter + where <django.db.models.fields.related_descriptors.create_reverse_many_to_one_manager.<locals>.RelatedManager object at 0x7f069d181d30> = <Project: Test>.values
project_copy.values.filter(snapshot=None).order_by(*ordering).count() == \
project.values.filter(snapshot=None).order_by(*ordering).count()

# for value_copy, value in zip(
# project_copy.values.filter(snapshot=None).order_by(*ordering),
# project.values.filter(snapshot=None).order_by(*ordering)
# ):
# for field in value_fields:
# assert getattr(value_copy, field) == getattr(value, field), field

# if value_copy.file:
# assert value_copy.file.path == value_copy.file.path.replace(
# f'/projects/{project.id}/values/{value.id}/',
# f'/projects/{project_copy.id}/values/{value_copy.id}/'
# )
# assert value_copy.file.size == value_copy.file.size
# else:
# assert not value.file

# for snapshot_copy, snapshot in zip(project_copy.snapshots.all(), project.snapshots.all()):
# for value_copy, value in zip(
# project_copy.values.filter(snapshot=snapshot_copy).order_by(*ordering),
# project.values.filter(snapshot=snapshot).order_by(*ordering)
# ):
# for field in value_fields:
# assert getattr(value_copy, field) == getattr(value, field)

# if value_copy.file:
# assert value_copy.file.path == value_copy.file.path.replace(
# f'/projects/{project.id}/snapshot/{snapshot.id}/values/{value.id}/',
# f'/projects/{project_copy.id}/snapshot/{snapshot.id}/values/{value_copy.id}/'
# )
# assert value_copy.file.open('rb').read() == value_copy.file.open('rb').read()
# else:
# assert not value.file

0 comments on commit 9e07a4e

Please sign in to comment.