Example #1
0
 def test_update_filtered_by_id(self, dao: InMemoryDao):
     ids = dao.filter(pred_not_a).filter_by(id_=2).update(char='z')
     assert ids == [2]
     assert list(dao.all()) == [
         {'char': 'a', 'is_a': True},
         {'char': 'z', 'is_a': False},
         {'char': 'c', 'is_a': False},
     ]
Example #2
0
 def test_update_all(self, dao: InMemoryDao):
     ids = dao.all().update(char='z')
     assert ids == [1, 2, 3]
     assert list(dao.all()) == [
         {'char': 'z', 'is_a': True},
         {'char': 'z', 'is_a': False},
         {'char': 'z', 'is_a': False},
     ]
Example #3
0
 def test_update_none(self, dao: InMemoryDao):
     ids = dao.filter(pred_z).update(char='z')
     assert ids == []
     assert list(dao.all()) == [
         {'char': 'a', 'is_a': True},
         {'char': 'b', 'is_a': False},
         {'char': 'c', 'is_a': False},
     ]
Example #4
0
 def test_update_none(self, dao: InMemoryDao):
     ids = dao.filter(pred_z).update(char="z")
     assert ids == []
     assert list(dao.all()) == [
         {
             "char": "a",
             "is_a": True
         },
         {
             "char": "b",
             "is_a": False
         },
         {
             "char": "c",
             "is_a": False
         },
     ]
Example #5
0
 def test_update_none(self, dao: InMemoryDao):
     ids = dao.filter(pred_z).update(char='z')
     assert ids == []
     assert list(dao.all()) == [
         {
             'char': 'a',
             'is_a': True
         },
         {
             'char': 'b',
             'is_a': False
         },
         {
             'char': 'c',
             'is_a': False
         },
     ]
Example #6
0
 def test_update_all(self, dao: InMemoryDao):
     ids = dao.all().update(char="z")
     assert ids == [1, 2, 3]
     assert list(dao.all()) == [
         {
             "char": "z",
             "is_a": True
         },
         {
             "char": "z",
             "is_a": False
         },
         {
             "char": "z",
             "is_a": False
         },
     ]
Example #7
0
 def test_update_filtered_by_id(self, dao: InMemoryDao):
     ids = dao.filter(pred_not_a).filter_by(id_=2).update(char="z")
     assert ids == [2]
     assert list(dao.all()) == [
         {
             "char": "a",
             "is_a": True
         },
         {
             "char": "z",
             "is_a": False
         },
         {
             "char": "c",
             "is_a": False
         },
     ]
Example #8
0
 def test_update_filtered_by_id(self, dao: InMemoryDao):
     ids = dao.filter(pred_not_a).filter_by(id_=2).update(char='z')
     assert ids == [2]
     assert list(dao.all()) == [
         {
             'char': 'a',
             'is_a': True
         },
         {
             'char': 'z',
             'is_a': False
         },
         {
             'char': 'c',
             'is_a': False
         },
     ]
Example #9
0
 def test_update_all(self, dao: InMemoryDao):
     ids = dao.all().update(char='z')
     assert ids == [1, 2, 3]
     assert list(dao.all()) == [
         {
             'char': 'z',
             'is_a': True
         },
         {
             'char': 'z',
             'is_a': False
         },
         {
             'char': 'z',
             'is_a': False
         },
     ]
Example #10
0
 def dao(self, mock_container, content):
     """
     In-memory table that has three documents pre-assigned:
         {'char': 'a', 'is_a': True},
         {'char': 'b', 'is_a': False},
         {'char': 'c', 'is_a': False}
     """
     dao = InMemoryDao(mock_container, initial_content=content)
     return dao
Example #11
0
 def test_multiple_filter_success(self, dao: InMemoryDao):
     assert list(dao.filter(pred_not_a).filter(pred_c)) == [{
         'char': 'c',
         'is_a': False
     }]
Example #12
0
 def test_remove_filtered(self, dao: InMemoryDao):
     ids = dao.filter(pred_a).remove()
     assert ids == [1]
     assert get_ids(dao.all()) == [2, 3]
Example #13
0
 def test_exists_filtered_success(self, dao: InMemoryDao):
     assert dao.filter(pred_c).exists()
Example #14
0
 def test_filtered_get_success(self, dao: InMemoryDao):
     object_2 = dao.get(2)
     assert dao.filter(pred_not_a).get(2) == object_2
Example #15
0
 def test_all(self, dao: InMemoryDao):
     assert get_ids(dao.all()) == [1, 2, 3]
Example #16
0
 def test_initial_content(self, mock_container, content):
     dao = InMemoryDao(mock_container, initial_content=content)
     assert list(dao.all()) == content
Example #17
0
 def test_clear(self, dao: InMemoryDao):
     dao.clear()
     assert list(dao.all()) == []
Example #18
0
 def test_batch_insert(self, dao: InMemoryDao):
     batch = [{'foo': 'bar'}, {'foo': 'baz'}]
     result = dao.batch_insert(batch)
     assert result == (4, 5)
     assert list(dao.filter(where('foo').exists())) == batch
Example #19
0
 def test_insert(self, dao: InMemoryDao):
     id_ = dao.insert(foo='bar')
     assert id_ == 4
Example #20
0
 def test_remove_none(self, dao: InMemoryDao):
     ids = dao.filter(pred_z).remove()
     assert ids == []
     assert get_ids(dao.all()) == [1, 2, 3]
Example #21
0
 def test_remove_filtered_by_id(self, dao: InMemoryDao):
     ids = dao.filter(pred_not_a).filter_by(id_=2).remove()
     assert ids == [2]
     assert get_ids(dao.all()) == [1, 3]
Example #22
0
 def test_filter_by_both_arguments_error(self, dao: InMemoryDao):
     with pytest.raises(QueryError):
         assert dao.all().filter_by(id_=3, ids=[3, 5])
Example #23
0
 def test_get_success(self, dao: InMemoryDao):
     assert dao.get(1) == {'char': 'a', 'is_a': True}
Example #24
0
 def test_multiple_filter_success(self, dao: InMemoryDao):
     assert list(dao.filter(pred_not_a).filter(pred_c)) == [{'char': 'c', 'is_a': False}]
Example #25
0
 def test_exists_all_success(self, dao: InMemoryDao):
     assert dao.all().exists()
Example #26
0
 def test_remove_all_error(self, dao: InMemoryDao):
     with pytest.raises(QueryError) as error_info:
         dao.all().remove()
     assert error_info.value == QueryErrors.UNRESTRICTED_REMOVE
Example #27
0
 def test_count_all(self, dao: InMemoryDao):
     assert dao.all().count() == 3
Example #28
0
 def test_remove_filtered_by_id(self, dao: InMemoryDao):
     ids = dao.filter(pred_not_a).filter_by(id_=2).remove()
     assert ids == [2]
     assert get_ids(dao.all()) == [1, 3]
Example #29
0
 def test_insert(self, dao: InMemoryDao):
     id_ = dao.insert(foo='bar')
     assert id_ == 4
Example #30
0
 def test_clear(self, dao: InMemoryDao):
     dao.clear()
     assert list(dao.all()) == []
Example #31
0
 def test_filter_by_success(self, dao: InMemoryDao):
     assert list(dao.filter(pred_not_a).filter_by(id_=3)) == [{'char': 'c', 'is_a': False}]
Example #32
0
 def test_remove_all_error(self, dao: InMemoryDao):
     with pytest.raises(QueryError) as error_info:
         dao.all().remove()
     assert error_info.value == QueryErrors.UNRESTRICTED_REMOVE
Example #33
0
 def test_remove_filtered(self, dao: InMemoryDao):
     ids = dao.filter(pred_a).remove()
     assert ids == [1]
     assert get_ids(dao.all()) == [2, 3]
Example #34
0
 def test_filter_by_both_arguments_error(self, dao: InMemoryDao):
     with pytest.raises(QueryError):
         assert dao.all().filter_by(id_=3, ids=[3, 5])
Example #35
0
 def test_remove_none(self, dao: InMemoryDao):
     ids = dao.filter(pred_z).remove()
     assert ids == []
     assert get_ids(dao.all()) == [1, 2, 3]
Example #36
0
 def test_filter_by_two_times_error(self, dao: InMemoryDao):
     with pytest.raises(QueryError):
         assert dao.all().filter_by(id_=3).filter_by(id_=5)
Example #37
0
 def test_batch_insert(self, dao: InMemoryDao):
     batch = [{'foo': 'bar'}, {'foo': 'baz'}]
     result = dao.batch_insert(batch)
     assert result == (4, 5)
     assert list(dao.filter(where('foo').exists())) == batch
Example #38
0
 def test_get_success(self, dao: InMemoryDao):
     assert dao.get(1) == {'char': 'a', 'is_a': True}
Example #39
0
 def test_initial_content(self, mock_container, content):
     dao = InMemoryDao(mock_container, initial_content=content)
     assert list(dao.all()) == content
Example #40
0
 def test_get_fail(self, dao: InMemoryDao):
     assert dao.get(42) is None
Example #41
0
 def test_all(self, dao: InMemoryDao):
     assert get_ids(dao.all()) == [1, 2, 3]
Example #42
0
 def test_filtered_get_success(self, dao: InMemoryDao):
     object_2 = dao.get(2)
     assert dao.filter(pred_not_a).get(2) == object_2
Example #43
0
 def test_filter_by_success(self, dao: InMemoryDao):
     assert list(dao.filter(pred_not_a).filter_by(id_=3)) == [{
         'char': 'c',
         'is_a': False
     }]
Example #44
0
 def test_filtered_get_fail(self, dao: InMemoryDao):
     assert dao.filter(pred_not_a).get(1) is None
Example #45
0
 def test_filter_by_two_times_error(self, dao: InMemoryDao):
     with pytest.raises(QueryError):
         assert dao.all().filter_by(id_=3).filter_by(id_=5)
Example #46
0
 def test_exists_all_success(self, dao: InMemoryDao):
     assert dao.all().exists()
Example #47
0
 def test_get_fail(self, dao: InMemoryDao):
     assert dao.get(42) is None
Example #48
0
 def test_exists_empty_fail(self, dao: InMemoryDao):
     dao.clear()
     assert not dao.all().exists()
Example #49
0
 def test_filtered_get_fail(self, dao: InMemoryDao):
     assert dao.filter(pred_not_a).get(1) is None
Example #50
0
 def test_exists_filtered_success(self, dao: InMemoryDao):
     assert dao.filter(pred_c).exists()
Example #51
0
 def test_exists_empty_fail(self, dao: InMemoryDao):
     dao.clear()
     assert not dao.all().exists()
Example #52
0
 def test_exists_filtered_fail(self, dao: InMemoryDao):
     assert not dao.filter(pred_z).exists()
Example #53
0
 def test_exists_filtered_fail(self, dao: InMemoryDao):
     assert not dao.filter(pred_z).exists()
Example #54
0
 def test_count_all(self, dao: InMemoryDao):
     assert dao.all().count() == 3
Example #55
0
 def test_filtered_count(self, dao: InMemoryDao):
     assert dao.filter(pred_not_a).count() == 2
Example #56
0
 def test_filtered_count(self, dao: InMemoryDao):
     assert dao.filter(pred_not_a).count() == 2