-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_repository.py
829 lines (657 loc) · 24.3 KB
/
test_repository.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
"""Tests the integration between the repositories and their storage layer.
The tests are all the same for all the repositories. If you want to add a new one
add them to the cases.
"""
import logging
import os
from typing import Any, List, Type
import pytest
from _pytest.logging import LogCaptureFixture
from py._path.local import LocalPath
from pydantic import ValidationError
from repository_orm import (
AutoIncrementError,
EntityNotFoundError,
Repository,
TinyDBRepository,
)
from repository_orm.exceptions import TooManyEntitiesError
from ..cases import Entity, OtherEntity, RepositoryTester
from ..cases.entities import ListEntityFactory
from ..cases.model import Author, Book, BoolEntity, ListEntity
def test_apply_repository_creates_schema( # noqa: AAA01
database: Any,
empty_repo: Repository,
caplog: LogCaptureFixture,
repo_tester: RepositoryTester[Repository],
) -> None:
"""
Given: an empty repository.
When: the apply_migrations method is called.
Then: The migrations are applied as expected.
"""
caplog.set_level(logging.DEBUG)
repo_tester.apply_migrations(empty_repo)
repo_tester.assert_schema_exists(database, caplog)
def test_repository_handles_inexistent_database_file(
repo: Repository, tmpdir: LocalPath
) -> None:
"""
Given: A database url pointing to an inexistent file
When: the repository is initialized
Then: The object is well initialized, and the database file is created.
The FakeRepository should not create any file, as all entities are stored in
memory.
"""
database_url = str(tmpdir.join("inexistent.db")) # type: ignore
result = repo.__class__(database_url=database_url)
assert isinstance(result, repo.__class__)
if result.__class__.__name__ != "FakeRepository":
assert os.path.isfile(database_url)
def test_repository_handles_connection_errors(repo: Repository) -> None:
"""
Given: A database url pointing to an inexistent file
When: the repository is initialized with an inexistent directory
Then: a ConnectionError is raised. This doesn't apply to FakeRepository as it
doesn't create a database
"""
with pytest.raises(ConnectionError):
repo.__class__(database_url="/inexistent_dir/database.db") # act
def test_repository_can_save_an_entity(
database: Any,
repo: Repository,
repo_tester: RepositoryTester[Repository],
entity: Entity,
) -> None:
"""Saved entities remain in the repository."""
repo.add(entity)
repo.commit() # act
assert entity == repo_tester.get_entity(database, entity)
def test_repository_can_save_an_entity_without_id_in_empty_repo(
repo: Repository,
int_entity: Entity,
) -> None:
"""
Given: An empty repository and an entity whose id_ type is an int
When: adding an entity without id
Then: the id 0 is set
"""
entity = int_entity.__class__(name="Entity without id")
added_entity = repo.add(entity)
repo.commit() # act
entities = repo.all(type(entity))
assert len(entities) == 1
assert added_entity.id_ == 0
assert entities[0].id_ == 0
def test_repository_can_save_an_two_entities_without_id_in_empty_repo(
repo: Repository,
int_entity: Entity,
) -> None:
"""
Given: An empty repository and an entity whose id_ type is an int
When: adding two entity without id
Then: the ids 0 and 1 are set
"""
first_entity = int_entity.__class__(name="First entity without id")
second_entity = int_entity.__class__(name="Second entity without id")
repo.add(first_entity)
repo.add(second_entity)
repo.commit() # act
entities = repo.all(type(int_entity))
assert len(entities) == 2
assert entities[0].id_ == 0
assert entities[0].name == "First entity without id"
assert entities[1].id_ == 1
assert entities[1].name == "Second entity without id"
def test_repository_can_save_an_entity_without_id(
repo: Repository,
inserted_int_entity: Entity,
) -> None:
"""
Given: A repository with an entity whose id_ type is an int
When: adding an entity without id
Then: the id of the new entity is one unit greater than the last one.
"""
entity = inserted_int_entity.__class__(name="Entity without id")
repo.add(entity)
repo.commit() # act
saved_entity = repo.last(type(inserted_int_entity))
# ignore: we know that the entities have an int id_
assert saved_entity.id_ == inserted_int_entity.id_ + 1 # type: ignore
assert saved_entity.name == "Entity without id"
def test_repository_can_save_two_entities_without_id_full_repo(
repo: Repository,
inserted_int_entity: Entity,
) -> None:
"""
Given: A repository with an entity whose id_ type is an int
When: adding two entities without id
Then: the id of the new entities is one unit greater than the last one.
"""
first_entity = inserted_int_entity.__class__(name="First entity without id")
second_entity = inserted_int_entity.__class__(name="Second entity without id")
repo.add(first_entity)
repo.add(second_entity)
repo.commit() # act
entities = repo.all(type(inserted_int_entity))
assert len(entities) == 3
# ignore: we know that the entities have an int id_
assert entities[1].id_ == inserted_int_entity.id_ + 1 # type: ignore
assert entities[1].name == "First entity without id"
# ignore: we know that the entities have an int id_
assert entities[2].id_ == inserted_int_entity.id_ + 2 # type: ignore
assert entities[2].name == "Second entity without id"
def test_repository_cant_save_an_entity_with_a_negative_id(
repo: Repository,
inserted_int_entity: Entity,
) -> None:
"""
Given: A repository with an entity
When: adding an entity with a negative id
Then: the id of the new entity is one unit greater than the last one.
"""
entity = inserted_int_entity.__class__(id=-3, name="Entity with negative id")
repo.add(entity)
repo.commit() # act
saved_entity = repo.last(type(inserted_int_entity))
# ignore: we know for sure that the id_ is an int
assert saved_entity.id_ == inserted_int_entity.id_ + 1 # type: ignore
assert saved_entity.name == "Entity with negative id"
def test_repo_add_entity_is_idempotent(
database: Any,
repo: Repository,
repo_tester: RepositoryTester[Repository],
entity: Entity,
) -> None:
"""
Given: An empty repository.
When: We insert the same entity twice and then commit.
Then: Only one item exists.
"""
repo.add(entity)
repo.add(entity)
repo.commit() # act
entities = repo_tester.get_all(database, type(entity))
assert len(entities) == 1
assert entity == entities[0]
def test_repo_add_entity_is_idempotent_if_entity_is_commited(
database: Any,
repo: Repository,
repo_tester: RepositoryTester[Repository],
entity: Entity,
) -> None:
"""
Given: A repository with the identity we want to add already commited.
When: We insert the same entity again and then commit.
Then: Only one item exists.
"""
repo_tester.insert_entity(database, entity)
repo.add(entity)
repo.commit() # act
entities = repo_tester.get_all(database, type(entity))
assert len(entities) == 1
assert entity == entities[0]
def test_repo_add_entity_updates_attribute(
database: Any,
repo: Repository,
repo_tester: RepositoryTester[Repository],
entity: Entity,
) -> None:
"""
Given: A repository with the identity we want to add already commited.
When: We insert the same entity with an attribute changed then commit.
Then: Only one item exists.
"""
repo_tester.insert_entity(database, entity)
# ignore: Although Entity doesn't have the rating attribute, all the entities
# defined in the tests models do.
entity.rating += 1 # type: ignore
repo.add(entity)
repo.commit() # act
entities = repo_tester.get_all(database, type(entity))
assert len(entities) == 1
assert entity.rating == entities[0].rating # type: ignore
def test_repository_doesnt_add_an_entity_if_we_dont_commit_changes(
database: Any,
repo: Repository,
repo_tester: RepositoryTester[Repository],
entity: Entity,
) -> None:
"""
Given: an empty repository.
When: an entity is added but we don't commit the changes.
Then: the entity is not found in the repository.
"""
repo.add(entity)
with pytest.raises(EntityNotFoundError):
repo_tester.get_entity(database, entity)
def test_repository_can_retrieve_an_entity(
repo: Repository,
inserted_entity: Entity,
) -> None:
"""Given an entity_id the repository returns the entity object."""
result = repo.get(inserted_entity.id_, type(inserted_entity))
assert result == inserted_entity
assert result.id_ == inserted_entity.id_
def test_repository_can_retrieve_an_entity_if_no_model_defined(
repo: Repository,
inserted_entity: Entity,
) -> None:
"""Given an entity_id the repository returns the entity object."""
result: Entity = repo.get(inserted_entity.id_)
assert result == inserted_entity
assert result.id_ == inserted_entity.id_
def test_repository_can_retrieve_an_entity_if_list_of_models_defined(
repo: Repository,
inserted_entity: Entity,
) -> None:
"""Given an entity_id the repository returns the entity object."""
entity_models: List[Type[Entity]] = [type(inserted_entity), OtherEntity]
result = repo.get(inserted_entity.id_, entity_models)
assert result == inserted_entity
assert result.id_ == inserted_entity.id_
def test_repository_raises_error_if_no_entity_found_by_get(
repo: Repository,
entity: Entity,
) -> None:
"""As the entity is not inserted into the repository, it shouldn't be found."""
with pytest.raises(
EntityNotFoundError,
match=(
f"There are no entities of type {entity._model_name} in the "
f"repository with id {entity.id_}"
),
):
repo.get(entity.id_, type(entity))
def test_repository_raises_error_if_get_finds_more_than_one_entity(
repo: Repository, inserted_entity: Entity
) -> None:
"""
Given: Two entities of different type with the same ID
When: We get the ID without specifying the model
Then: a TooManyEntitiesError error is raised
"""
other_entity = OtherEntity(id_=inserted_entity.id_, name="Other entity")
repo.add(other_entity)
repo.commit()
with pytest.raises(TooManyEntitiesError, match=""):
repo.get(inserted_entity.id_)
def test_repository_can_retrieve_all(
repo: Repository,
inserted_entities: List[Entity],
) -> None:
"""
Given: A repository with inserted entities
When: all is called
Then: all entities are returned
"""
result: List[Entity] = repo.all()
assert result == inserted_entities
assert len(result) == 3
assert result[0].id_ == inserted_entities[0].id_
def test_repository_can_retrieve_all_objects_of_an_entity_type(
repo: Repository,
inserted_entities: List[Entity],
) -> None:
"""Given an entity type all the entity objects that match should be returned."""
entity_type = type(inserted_entities[0])
result = repo.all(entity_type)
assert result == inserted_entities
assert len(result) == 3
assert result[0].id_ == inserted_entities[0].id_
def test_repository_can_retrieve_all_objects_of_a_list_of_entity_types(
repo: Repository,
inserted_entities: List[Entity],
) -> None:
"""
Given: Three entities of a type and another of other type.
When: all is called using a list of entities
Then: all elements are returned.
"""
other_entity = OtherEntity(id_=0, name="Other entity")
repo.add(other_entity)
repo.commit()
entity_types: List[Type[Entity]] = [type(inserted_entities[0]), OtherEntity]
result = repo.all(entity_types)
assert result == inserted_entities + [other_entity]
assert len(result) == 4
def test_repository_all_is_idempotent(
repo: Repository,
inserted_entities: List[Entity],
) -> None:
"""
Given: A repository that has already used the all method.
When: all is called again.
Then: it returns the same results.
"""
entity_type = type(inserted_entities[0])
expected_results = repo.all(entity_type)
result = repo.all(entity_type)
assert result == expected_results
def test_repository_all_returns_empty_list_if_there_are_no_entities_of_a_type(
repo: Repository,
entity: Entity,
) -> None:
"""
Given: An empty repo
When: all is used with an entity type
Then: An empty list is returned
"""
result: List[Entity] = repo.all()
assert result == []
def test_repository_can_search_by_property(
repo: Repository,
inserted_entities: List[Entity],
) -> None:
"""Search should return the objects that match the desired property."""
expected_entity = inserted_entities[1]
result = repo.search({"id_": expected_entity.id_}, type(inserted_entities[1]))
assert result == [expected_entity]
def test_repository_can_search_by_property_without_specifying_the_type(
repo: Repository,
inserted_entities: List[Entity],
) -> None:
"""Search should return the objects that match the desired property."""
expected_entity = inserted_entities[1]
result: List[Entity] = repo.search({"id_": expected_entity.id_})
assert result == [expected_entity]
def test_repository_can_search_by_property_specifying_a_list_of_types(
repo: Repository,
inserted_entities: List[Entity],
) -> None:
"""Search should return the objects that match the desired property."""
entity_types: List[Type[Entity]] = [type(inserted_entities[0]), OtherEntity]
expected_entity = inserted_entities[1]
result = repo.search({"id_": expected_entity.id_}, entity_types)
assert result == [expected_entity]
def test_repository_can_search_by_bool_property(
repo: Repository,
inserted_entities: List[Entity],
) -> None:
"""Search should return the objects that have a bool property."""
expected_entity = BoolEntity(name="Name", active=True)
repo.add(expected_entity)
repo.commit()
result = repo.search({"active": True}, [BoolEntity])
assert result == [expected_entity]
def test_repository_can_search_regular_expression(
repo: Repository, inserted_entities: List[Entity]
) -> None:
"""
Given: More than one entity is inserted in the repository.
When: We search using a regular expression
Then: The matching entity is found
"""
expected_entities = [
entity_
for entity_ in inserted_entities
if entity_.name == inserted_entities[0].name
]
regular_expression = fr"^{expected_entities[0].name}.*"
result = repo.search({"name": regular_expression}, type(expected_entities[0]))
assert result == expected_entities
def test_repository_search_by_regular_expression_is_case_insensitive(
repo: Repository, inserted_entities: List[Entity]
) -> None:
"""
Given: More than one entity is inserted in the repository.
When: We search using a regular expression with the wrong capitalization
Then: The matching entity is found
If you come to disable this functionality, make it configurable instead, being the
default the search as case insensitive
"""
expected_entities = [
entity_
for entity_ in inserted_entities
if entity_.name == inserted_entities[0].name
]
regular_expression = fr"^{expected_entities[0].name.upper()}.*"
result = repo.search({"name": regular_expression}, type(expected_entities[0]))
assert result == expected_entities
def test_repository_search_raises_error_if_searching_by_inexistent_field(
repo: Repository,
inserted_entities: List[Entity],
) -> None:
"""If no object has the property of the search criteria, raise the desired
error.
"""
entity = inserted_entities[0]
with pytest.raises(
EntityNotFoundError,
match=(
f"There are no entities of type {entity._model_name} in the repository that"
" match the search filter {'inexistent_field': 'inexistent_value'}"
),
):
repo.search({"inexistent_field": "inexistent_value"}, type(entity))
def test_repository_search_raises_error_if_searching_by_inexistent_value(
repo: Repository,
inserted_entities: List[Entity],
) -> None:
"""If no object has a value like the search criteria raise the desired error."""
entity = inserted_entities[0]
with pytest.raises(
EntityNotFoundError,
match=(
f"There are no entities of type {entity._model_name} in the repository that"
" match the search filter {'id_': 'inexistent_value'}"
),
):
repo.search({"id_": "inexistent_value"}, type(entity))
def test_repository_can_search_by_multiple_properties(
repo: Repository,
inserted_entities: List[Entity],
) -> None:
"""
Given: a full repository.
When: a search is performed by multiple properties.
Then: the matching objects are returned.
"""
entity = inserted_entities[1]
result = repo.search({"state": entity.state, "name": entity.name}, type(entity))
assert result == [entity]
def test_repo_can_search_entity_if_two_different_entities_match(
repo: Repository,
) -> None:
"""
Given: Two different entities with the same ID
When: we search by a property equal in both entities and give only one model.
Then: only the entity that matches the model is returned
"""
author = Author(id_="author_id", name="common name")
book = Book(id_=1, name="common name")
repo.add(author)
repo.add(book)
repo.commit()
result = repo.search({"name": "common name"}, [Author])
assert result == [author]
def test_repo_can_search_entity_if_two_different_entities_match_giving_both_models(
repo: Repository,
) -> None:
"""
Given: Two different entities with the same ID
When: we search by a property equal in both entities and give both models.
Then: both entities that matches the model are returned
"""
author = Author(id_="author_id", name="common name")
book = Book(id_=1, name="common name")
repo.add(author)
repo.add(book)
repo.commit()
result = repo.search({"name": "common name"}, [Author, Book])
assert result == [author, book]
@pytest.mark.skip(
"Supported by Fake and TinyDB, not by Pypika yet. Once mappers are supported "
"it should be easy to add this particular case."
)
def test_repo_can_search_in_list_of_str_attribute(repo: Repository) -> None:
"""
Given: A repository with an entity that contains an attribute with a list of str
When: search is called with a regexp that matches one of the list elements
Then: the entity is returned
"""
expected_entity = ListEntityFactory.create()
repo.add(expected_entity)
repo.commit()
regexp = fr"{expected_entity.elements[0][:-1]}."
result = repo.search({"elements": regexp}, ListEntity)
assert result == [expected_entity]
@pytest.mark.secondary()
def test_repository_can_delete_an_entity(
repo: Repository,
inserted_entities: List[Entity],
) -> None:
"""
Given: a full repository.
When: an entity is deleted.
Then: the entity is not longer in the repository.
"""
entity_to_delete = inserted_entities[1]
repo.delete(entity_to_delete)
repo.commit() # act
remaining_entities = repo.all(type(entity_to_delete))
assert entity_to_delete not in remaining_entities
@pytest.mark.secondary()
def test_repository_doesnt_delete_the_entity_if_we_dont_commit(
database: Any,
repo: Repository,
repo_tester: RepositoryTester[Entity],
inserted_entities: List[Entity],
) -> None:
"""
Given: a full repository.
When: an entity is deleted but we don't commit the changes.
Then: the entity is still in the repository.
"""
entity_to_delete = inserted_entities[1]
repo.delete(entity_to_delete) # act
remaining_entities = repo_tester.get_all(database, type(entity_to_delete))
assert entity_to_delete in remaining_entities
def test_repository_delete_raise_error_if_entity_not_found(
repo: Repository,
entity: Entity,
) -> None:
"""
Given: an empty repository.
When: trying to delete an inexistent entity.
Then: An EntityNotFoundError error is raised.
"""
with pytest.raises(EntityNotFoundError) as error:
repo.delete(entity)
assert (
f"Unable to delete entity {entity} because it's not in the repository"
in str(error.value)
)
def test_repository_last_returns_last_entity(
repo: Repository,
inserted_entities: List[Entity],
) -> None:
"""
Given: A repository with many entities.
When: using the last method.
Then: The greater entity is returned
"""
greater_entity = max(inserted_entities)
result = repo.last(type(greater_entity))
assert result == greater_entity
def test_repository_last_returns_last_entity_if_no_type_specified(
repo: Repository,
inserted_entities: List[Entity],
) -> None:
"""
Given: A repository with many entities.
When: using the last method without any argument.
Then: The greater entity is returned
"""
greater_entity = max(inserted_entities)
result: List[Entity] = repo.last()
assert result == greater_entity
def test_repository_last_returns_last_entity_if_list_of_types(
repo: Repository,
inserted_entities: List[Entity],
) -> None:
"""
Given: A repository with many entities.
When: using the last method with a list of types.
Then: The greater entity is returned
"""
entity_types: List[Type[Entity]] = [type(inserted_entities[0]), OtherEntity]
greater_entity = max(inserted_entities)
result = repo.last(entity_types)
assert result == greater_entity
def test_repository_last_raise_error_if_entity_not_found(
repo: Repository,
entity: Entity,
) -> None:
"""
Given: an empty repository.
When: trying to get the last entity.
Then: An EntityNotFoundError error is raised.
"""
with pytest.raises(
EntityNotFoundError,
match=f"There are no entities of type {entity._model_name} in the repository",
):
repo.last(type(entity))
def test_repository_first_returns_first_entity(
repo: Repository,
inserted_entities: List[Entity],
) -> None:
"""
Given: A repository with many entities.
When: using the first method.
Then: The smallest entity is returned
"""
smaller_entity = min(inserted_entities)
result = repo.first(type(smaller_entity))
assert result == smaller_entity
def test_repository_first_raise_error_if_entity_not_found(
repo: Repository,
entity: Entity,
) -> None:
"""
Given: an empty repository.
When: trying to get the first entity.
Then: An EntityNotFoundError error is raised.
"""
with pytest.raises(
EntityNotFoundError,
match=f"There are no entities of type {entity._model_name} in the repository",
):
repo.first(type(entity))
def test_repository_next_id_raise_error_if_entity_has_str_id(
repo: Repository,
inserted_str_entity: Entity,
) -> None:
"""
Given: an empty repository.
When: trying to get the next id of an entity with str id.
Then: An AutoIncrementError error is raised.
"""
with pytest.raises(
AutoIncrementError,
match="Auto increment is not yet supported for Entities with string id_s",
):
repo._next_id(inserted_str_entity)
def test_tinydb_raises_error_if_wrong_model_data(
repo_tinydb: TinyDBRepository, caplog: LogCaptureFixture
) -> None:
"""
Given: A tinydb repository with data than doesn't match the model.
When: Get is called
Then: The id_ of the model and it's data is shown before the error.
This doesn't apply to the fake repository due to how it handles the entities, and
in Pypika it would mean a database schema change without change on the model, which
is much more difficult than in the case of TinyDB, so I'm not going to test it
in the first approach.
"""
# The name is required
entity_data = {"id_": 1, "model_type_": "entity"}
repo_tinydb.db_.insert(entity_data)
with pytest.raises(ValidationError, match="name"):
repo_tinydb.get(1, [Entity])
assert (
"repository_orm.adapters.data.tinydb",
logging.ERROR,
"Error loading the model Entity for the register {'id_': 1}",
) in caplog.record_tuples