示例#1
0
    def test_05_client_2_synchronizes(self):
        data = {
            "logical_clock": self.client["client_2"]["logical_clock"],
            "diffs": []
        }
        res = self.mobync.apply(data["logical_clock"], data["diffs"], self.owner_id)
        self.assertEqual(res, {"logical_clock": 3, "diffs": [self.diff2], "success": True, "message": ""})
        self.merge_response_to_client_data("client_2", res)

        res = self.mobync.synchronizer.read("diffs", [ReadFilter(Diff.OWNER, FilterType.equal, self.owner_id)])
        self.assertEqual(json.loads(res), [self.diff1, self.diff3, self.diff2])
示例#2
0
    def test_01_client_1_creates_local_object_and_synchronizes(self):
        self.merge_diffs_into_client_data("client_1", [self.diff1])
        data = {
            "logical_clock": self.client["client_1"]["logical_clock"],
            "diffs": [self.diff1]
        }
        res = self.mobync.apply(data["logical_clock"], data["diffs"], self.owner_id)
        self.assertEqual(res, {"logical_clock": 1, "diffs": [], "success": True, "message": ""})
        self.merge_response_to_client_data("client_1", res)

        res = self.mobync.synchronizer.read("diffs", [ReadFilter(Diff.OWNER, FilterType.equal, self.owner_id)])
        self.assertEqual(json.loads(res), [self.diff1])
示例#3
0
    def test_05_apply_diff(self):
        self.reset_db()

        self.mobync._Mobync__apply_diff(self.create_diff)

        res = self.mobync.synchronizer.read(
            'diffs',
            [ReadFilter(Diff.OWNER, FilterType.equal, self.owner_id1)])
        self.assertEqual(json.loads(res), [self.create_diff])

        self.assertTrue(
            self.mobync._Mobync__validate_diff(self.update_diff,
                                               self.owner_id1))
        self.mobync._Mobync__apply_diff(self.update_diff)

        res = self.mobync.synchronizer.read(
            "diffs",
            [ReadFilter(Diff.OWNER, FilterType.equal, self.owner_id1)])
        self.assertEqual(json.loads(res), [self.create_diff, self.update_diff])

        res = self.mobync.synchronizer.read("model1", [])
        self.assertEqual(json.loads(res), [{'field1': 'b', 'id': 'uuid1'}])

        self.assertTrue(
            self.mobync._Mobync__validate_diff(self.delete_diff,
                                               self.owner_id1))
        self.mobync._Mobync__apply_diff(self.delete_diff)

        res = self.mobync.synchronizer.read(
            "diffs",
            [ReadFilter(Diff.OWNER, FilterType.equal, self.owner_id1)])
        self.assertEqual(
            json.loads(res),
            [self.create_diff, self.update_diff, self.delete_diff])

        res = self.mobync.synchronizer.read("model1", [])
        self.assertEqual(json.loads(res), [])
示例#4
0
    def update(self):
        self.mobync.synchronizer.update(self.create_diff[Diff.MODEL],
                                        self.update_diff[Diff.JSON_DATA])

        return self.mobync.synchronizer.read(
            'model1', [ReadFilter('id', FilterType.equal, "uuid1")])