示例#1
0
 def test_fetch_model_ADD_BEFORE_DB_nothing_no_exception(self) -> None:
     result = self.datastore.fetch_model(
         fqid=FullQualifiedId(Collection("meeting"), 1),
         mapped_fields=["name"],
         exception=False,
     )
     self.assertEqual(result.get("name"), None)
示例#2
0
 def test_fetch_model_ADD_BEFORE_DB_onlyAdd(self) -> None:
     self.init_only_add()
     result = self.datastore.fetch_model(
         fqid=FullQualifiedId(Collection("meeting"), 1),
         mapped_fields=["name"],
     )
     self.assertEqual(result["name"], "meetingAdd")
示例#3
0
 def test_full_qualified_field_fqid(self) -> None:
     fqfield = FullQualifiedField(Collection("collection_quephah8Oo"),
                                  3148072663, "field_Ein2Aos0Ku")
     self.assertEqual(
         fqfield.fqid,
         FullQualifiedId(Collection("collection_quephah8Oo"), 3148072663),
     )
示例#4
0
 def init_both(self) -> None:
     self.set_models(
         {"meeting/1": {"name": "meetingDB", "description": "descriptionDB"}}
     )
     self.datastore.additional_relation_models[
         FullQualifiedId(Collection("meeting"), 1)
     ] = {"id": 1, "name": "meetingAdd"}
示例#5
0
 def test_fetch_model_ONLY_ADD_nothing(self) -> None:
     with pytest.raises(DatastoreException) as e:
         self.datastore.fetch_model(
             fqid=FullQualifiedId(Collection("meeting"), 1),
             mapped_fields=["name"],
             db_additional_relevance=InstanceAdditionalBehaviour.ONLY_ADDITIONAL,
         )
     self.assertIn("meeting/1 not found at all.", e.value.message)
示例#6
0
 def test_get_use_changed_models_empty(self) -> None:
     result = self.adapter.get(
         FullQualifiedId(self.collection, 1),
         ["f"],
     )
     assert result == {"f": 1}
     self.db_method_mock.assert_called()
     self.add_get_many_mock.assert_called()
示例#7
0
 def test_fetch_model_DB_BEFORE_ADD_onlyAdd(self) -> None:
     self.init_only_add()
     result = self.datastore.fetch_model(
         fqid=FullQualifiedId(Collection("meeting"), 1),
         mapped_fields=["name"],
         db_additional_relevance=InstanceAdditionalBehaviour.DBINST_BEFORE_ADDITIONAL,
     )
     self.assertEqual(result["name"], "meetingAdd")
示例#8
0
 def test_fetch_model_ONLY_DB_nothing_no_exception(self) -> None:
     result = self.datastore.fetch_model(
         fqid=FullQualifiedId(Collection("meeting"), 1),
         mapped_fields=["name"],
         db_additional_relevance=InstanceAdditionalBehaviour.ONLY_DBINST,
         exception=False,
     )
     self.assertEqual(result.get("name"), None)
示例#9
0
 def test_fetch_model_ONLY_DB_onlyDB(self) -> None:
     self.init_only_db()
     result = self.datastore.fetch_model(
         fqid=FullQualifiedId(Collection("meeting"), 1),
         mapped_fields=["name"],
         db_additional_relevance=InstanceAdditionalBehaviour.ONLY_DBINST,
     )
     self.assertEqual(result.get("name"), "meetingDB")
示例#10
0
def test_getManyByFQIDs() -> None:
    fqid = FullQualifiedId(Collection("fakeModel"), 1)
    command = commands.GetManyByFQIDs([fqid])
    engine.getMany.return_value = {
        "a/1": {"f": 1, "meta_deleted": False, "meta_position": 1}
    }
    result = db.getManyByFQIDs([fqid])
    assert result is not None
    assert command.data == {"requests": [str(fqid)]}
示例#11
0
def test_get() -> None:
    fqid = FullQualifiedId(Collection("fakeModel"), 1)
    fields = ["a", "b", "c"]
    command = commands.Get(fqid=fqid, mappedFields=fields)
    engine.get.return_value = {"f": 1, "meta_deleted": False, "meta_position": 1}
    partial_model = db.get(fqid, fields)
    assert command.data == {"fqid": str(fqid), "mapped_fields": fields}
    assert partial_model is not None
    engine.get.assert_called_with(command)
示例#12
0
 def test_get_use_changed_models_exception(self) -> None:
     self.mock_datastore_content = {}
     with pytest.raises(DatastoreException):
         self.adapter.get(
             FullQualifiedId(self.collection, 1),
             ["f"],
         )
     self.db_method_mock.assert_called()
     self.add_get_many_mock.assert_called()
示例#13
0
 def test_fetch_model_ADD_BEFORE_DB_nothing(self) -> None:
     with pytest.raises(DatastoreException) as e:
         self.datastore.fetch_model(
             fqid=FullQualifiedId(Collection("meeting"), 1),
             mapped_fields=["name"],
         )
     self.assertIn(
         "Datastore service sends HTTP 400. Model 'meeting/1' does not exist.",
         e.value.message,
     )
示例#14
0
 def test_fetch_model_ADD_BEFORE_DB_both(self) -> None:
     self.init_both()
     result = self.datastore.fetch_model(
         fqid=FullQualifiedId(Collection("meeting"), 1),
         mapped_fields=["name", "id", "description", "not_there"],
     )
     self.assertEqual(result["name"], "meetingAdd")
     self.assertEqual(result["id"], 1)
     self.assertEqual(result["description"], "descriptionDB")
     self.assertEqual(result.get("not_there", "None"), "None")
示例#15
0
 def test_fetch_model_ONLY_DB_nothing(self) -> None:
     with pytest.raises(DatastoreException) as e:
         self.datastore.fetch_model(
             fqid=FullQualifiedId(Collection("meeting"), 1),
             mapped_fields=["name"],
             db_additional_relevance=InstanceAdditionalBehaviour.ONLY_DBINST,
         )
     self.assertIn(
         "Datastore service sends HTTP 400. Model 'meeting/1' does not exist.",
         e.value.message,
     )
示例#16
0
 def test_get_use_changed_models_missing_fields(self) -> None:
     self.set_additional_models({
         "test/1": {
             "weight": 42
         },
     })
     result = self.adapter.get(
         FullQualifiedId(self.collection, 1),
         ["f", "weight"],
     )
     assert result == {"f": 1, "weight": 42}
     self.db_method_mock.assert_called()
     self.add_get_many_mock.assert_called()
示例#17
0
 def test_get_only_db(self) -> None:
     self.set_additional_models({
         "test/1": {
             "f": 2
         },
     })
     result = self.adapter.get(
         FullQualifiedId(self.collection, 1),
         ["f"],
         use_changed_models=False,
     )
     assert result == {"f": 1}
     self.db_method_mock.assert_called()
     self.add_get_many_mock.assert_not_called()
示例#18
0
 def test_get_only_db_exception(self) -> None:
     self.set_additional_models({
         "test/1": {
             "f": 2
         },
     })
     self.mock_datastore_content = {}
     with pytest.raises(DatastoreException):
         self.adapter.get(
             FullQualifiedId(self.collection, 1),
             ["f"],
             use_changed_models=False,
         )
     self.db_method_mock.assert_called()
     self.add_get_many_mock.assert_not_called()
 def test_get(self) -> None:
     fqid = FullQualifiedId(Collection("fakeModel"), 1)
     fields = ["a", "b", "c"]
     command = commands.Get(fqid=fqid, mappedFields=fields)
     self.engine.retrieve.return_value = (
         json.dumps({
             "f": 1,
             "meta_deleted": False,
             "meta_position": 1
         }),
         200,
     )
     partial_model = self.db.get(fqid, fields)
     assert command.get_raw_data() == {
         "fqid": str(fqid),
         "mapped_fields": fields
     }
     assert partial_model is not None
     self.engine.retrieve.assert_called_with("get", command.data)
 def test_get(self) -> None:
     fqid = FullQualifiedId(Collection("fakeModel"), 1)
     fields = set(["a", "b", "c"])
     command = commands.Get(fqid=fqid, mapped_fields=fields)
     self.engine.retrieve.return_value = (
         json.dumps({"f": 1, "meta_deleted": False, "meta_position": 1}),
         200,
     )
     partial_model = self.db.get(fqid, list(fields))
     raw_data = command.get_raw_data()
     assert raw_data["fqid"] == str(fqid)
     assert isinstance(raw_data["mapped_fields"], list)
     assert set(raw_data["mapped_fields"]) == fields
     assert partial_model is not None
     self.engine.retrieve.assert_called()
     call_args = self.engine.retrieve.call_args[0]
     assert call_args[0] == "get"
     data = json.loads(call_args[1])
     assert data["fqid"] == str(fqid)
     assert set(data["mapped_fields"]) == fields
示例#21
0
def test_get() -> None:
    fqid = FullQualifiedId(Collection("a"), 1)
    fields = ["f"]
    partial_model = db.get(fqid, fields)
    assert partial_model["f"] is not None
    assert partial_model is not None
示例#22
0
def get_fqid(value: str) -> FullQualifiedId:
    """
    Returns a FullQualifiedId parsed from the given value.
    """
    collection, id = value.split(KEYSEPARATOR)
    return FullQualifiedId(Collection(collection), int(id))
示例#23
0
from openslides_backend.shared.interfaces import WriteRequestElement
from openslides_backend.shared.patterns import Collection, FullQualifiedId

TEST_POSITION = 1

OLD_TESTDATA = {
    "mediafile_pubilc_file": {
        9283748294: {
            "meeting_id": 4256427454
        }
    },
    "mediafile": {
        3549387598: {
            "meeting_ids": [3611987967],
            "attachment_ids":
            [FullQualifiedId(collection=Collection("topic"), id=6259289755)],
        },
        7583920032: {
            "meeting_ids": [],
            "attachment_ids": []
        },
    },
    "agenda_item": {
        3393211712: {
            "meeting_id": 9079236097,
            "content_object_id": "topic/5756367535"
        },
    },
    "topic": {
        1312354708: {
            "meeting_id": 7816466305,
示例#24
0
 def init_only_add(self) -> None:
     self.datastore.additional_relation_models[
         FullQualifiedId(Collection("meeting"), 1)
     ] = {"id": 1, "name": "meetingAdd"}
示例#25
0
 def test_full_qualified_id_hashing(self) -> None:
     fqid = FullQualifiedId(Collection("collection_ia5Ooyuiso"), 9638688299)
     self.assertEqual(hash(fqid), hash("collection_ia5Ooyuiso/9638688299"))
示例#26
0
 def test_full_qualified_id_comparing(self) -> None:
     fqid_1 = FullQualifiedId(Collection("collection_reeyie3Woo"),
                              2133862900)
     fqid_2 = FullQualifiedId(Collection("collection_reeyie3Woo"),
                              2133862900)
     self.assertEqual(fqid_1, fqid_2)
示例#27
0
 def test_full_qualified_id_repr(self) -> None:
     fqid = FullQualifiedId(Collection("collection_oozaiX1pee"), 7099085886)
     self.assertEqual(repr(fqid), "FQId collection_oozaiX1pee/7099085886")
示例#28
0
 def test_full_qualified_id(self) -> None:
     fqid = FullQualifiedId(Collection("collection_Aid6ahdooT"), 8283937728)
     self.assertEqual(str(fqid), "collection_Aid6ahdooT/8283937728")