Пример #1
0
    def test_correct_output(self, local_client, s3_client):
        clients = [local_client, s3_client]
        worker = sync.SyncWorker(local_client, s3_client)

        utils.set_local_contents(local_client, "foo")
        utils.set_s3_contents(s3_client, "baz", timestamp=2000, data="testing")
        success = worker.run_resolutions({
            "foo":
            Resolution(Resolution.DELETE, local_client, None, "foo", 1000),
            "baz":
            Resolution(Resolution.CREATE, local_client, s3_client, "baz", 20),
        })
        assert sorted(success) == sorted(["foo", "baz"])
        assert_local_keys(clients, ["baz"])
Пример #2
0
    def test_correct_output(self, local_client, s3_client):
        def keyboard_interrupt():
            raise KeyboardInterrupt()

        clients = [local_client, s3_client]
        worker = sync.SyncWorker(local_client, s3_client)

        utils.set_local_contents(local_client, 'foo')
        utils.set_s3_contents(s3_client, 'baz', timestamp=2000, data='testing')
        success = worker.run_resolutions({
            'foo': Resolution(Resolution.DELETE, local_client, None, 'foo', 1000),
            'baz': Resolution(Resolution.CREATE, local_client, s3_client, 'baz', 20),
        })
        assert sorted(success) == sorted(['foo', 'baz'])
        assert_local_keys(clients, ['baz'])
Пример #3
0
    def test_nochanges_but_different_remote_timestamps(self, local_client,
                                                       s3_client):
        utils.set_local_index(local_client, {
            'german.txt': {
                'local_timestamp': 4000,
                'remote_timestamp': 4000,
            }
        })
        utils.set_s3_index(s3_client, {
            'german.txt': {
                'local_timestamp': 6000,
                'remote_timestamp': 6000,
            }
        })
        utils.set_local_contents(local_client, 'german.txt', timestamp=4000)
        utils.set_s3_contents(s3_client, 'german.txt', timestamp=6000)

        worker = sync.SyncWorker(local_client, s3_client)
        resolutions, unhandled_events = worker.get_sync_states()
        expected_resolutions = {
            'german.txt':
            Resolution("UPDATE", local_client, s3_client, 'german.txt', 6000)
        }
        assert resolutions == expected_resolutions
        assert unhandled_events == {}
Пример #4
0
 def test_invalid_action(self, local_client, s3_client):
     worker = sync.SyncWorker(local_client, s3_client)
     with pytest.raises(ValueError):
         worker.run_resolutions({
             'foo':
             Resolution('UNKNOWN', None, None, None, None),
         })
Пример #5
0
    def test_correct_behaviour(self, local_client, s3_client):
        utils.set_s3_contents(s3_client, 'art.txt', data='swirly abstract objects')

        worker = sync.SyncWorker(local_client, s3_client)

        resolution = Resolution(
            action=Resolution.CREATE,
            to_client=local_client,
            from_client=s3_client,
            key='art.txt',
            timestamp=6000,
        )
        worker.move_client(resolution)

        assert utils.get_local_contents(local_client, 'art.txt') == b'swirly abstract objects'
        assert local_client.get_remote_timestamp('art.txt') == 6000
Пример #6
0
    def test_correct_output(self, local_client, s3_client):
        utils.set_local_index(local_client, {
            'chemistry.txt': {
                'local_timestamp': 9431,
                'remote_timestamp': 9431,
            },
            'physics.txt': {
                'local_timestamp': 10000,
                'remote_timestamp': 10000,
            },
            'maltese.txt': {
                'local_timestamp': 7000,
                'remote_timestamp': 6000,
            },
        })
        utils.set_s3_index(s3_client, {
            'chemistry.txt': {
                'local_timestamp': 10000,
                'remote_timestamp': 9431,
            },
            'physics.txt': {
                'local_timestamp': 13000,
                'remote_timestamp': 12000,
            },
            'maltese.txt': {
                'local_timestamp': 6000,
                'remote_timestamp': 6000,
            },
        })

        utils.set_local_contents(local_client, 'history.txt', timestamp=5000)
        utils.set_s3_contents(s3_client, 'art.txt', timestamp=200000)
        utils.set_local_contents(local_client, 'english.txt', timestamp=90000)
        utils.set_s3_contents(s3_client, 'english.txt', timestamp=93000)
        utils.set_s3_contents(s3_client, 'chemistry.txt', timestamp=10000)
        utils.set_local_contents(local_client, 'physics.txt', timestamp=11000)
        utils.set_s3_contents(s3_client, 'physics.txt', timestamp=13000)
        utils.set_local_contents(local_client, 'maltese.txt', timestamp=7000)
        utils.set_s3_contents(s3_client, 'maltese.txt', timestamp=8000)

        worker = sync.SyncWorker(local_client, s3_client)
        resolutions, unhandled_events = worker.get_sync_states()
        expected_unhandled_events = {
            'english.txt': (
                SyncState(SyncState.CREATED, 90000, None),
                SyncState(SyncState.CREATED, 93000, None)
            ),
            'physics.txt': (
                SyncState(SyncState.UPDATED, 11000, 10000),
                SyncState(SyncState.NOCHANGES, 13000, 12000),
            )
        }
        expected_resolutions = {
            'maltese.txt': Resolution(
                Resolution.UPDATE, local_client, s3_client, 'maltese.txt', 8000
            ),
            'chemistry.txt': Resolution(
                Resolution.DELETE, s3_client, None, 'chemistry.txt', 9431
            ),
            'history.txt': Resolution(
                Resolution.CREATE, s3_client, local_client, 'history.txt', 5000
            ),
            'art.txt': Resolution(
                Resolution.CREATE, local_client, s3_client, 'art.txt', 200000
            ),
        }
        assert unhandled_events == expected_unhandled_events
        assert resolutions == expected_resolutions
Пример #7
0
    def test_correct_output(self, local_client, s3_client):
        utils.set_local_index(
            local_client,
            {
                "chemistry.txt": {
                    "local_timestamp": 9431,
                    "remote_timestamp": 9431
                },
                "physics.txt": {
                    "local_timestamp": 10000,
                    "remote_timestamp": 10000
                },
                "maltese.txt": {
                    "local_timestamp": 7000,
                    "remote_timestamp": 6000
                },
            },
        )
        utils.set_s3_index(
            s3_client,
            {
                "chemistry.txt": {
                    "local_timestamp": 10000,
                    "remote_timestamp": 9431
                },
                "physics.txt": {
                    "local_timestamp": 13000,
                    "remote_timestamp": 12000
                },
                "maltese.txt": {
                    "local_timestamp": 6000,
                    "remote_timestamp": 6000
                },
            },
        )

        utils.set_local_contents(local_client, "history.txt", timestamp=5000)
        utils.set_s3_contents(s3_client, "art.txt", timestamp=200000)
        utils.set_local_contents(local_client, "english.txt", timestamp=90000)
        utils.set_s3_contents(s3_client, "english.txt", timestamp=93000)
        utils.set_s3_contents(s3_client, "chemistry.txt", timestamp=10000)
        utils.set_local_contents(local_client, "physics.txt", timestamp=11000)
        utils.set_s3_contents(s3_client, "physics.txt", timestamp=13000)
        utils.set_local_contents(local_client, "maltese.txt", timestamp=7000)
        utils.set_s3_contents(s3_client, "maltese.txt", timestamp=8000)

        worker = sync.SyncWorker(local_client, s3_client)
        resolutions, unhandled_events = worker.get_sync_states()
        expected_unhandled_events = {
            "english.txt": (
                SyncState(SyncState.CREATED, 90000, None),
                SyncState(SyncState.CREATED, 93000, None),
            ),
            "physics.txt": (
                SyncState(SyncState.UPDATED, 11000, 10000),
                SyncState(SyncState.NOCHANGES, 13000, 12000),
            ),
        }
        expected_resolutions = {
            "maltese.txt":
            Resolution(Resolution.UPDATE, local_client, s3_client,
                       "maltese.txt", 8000),
            "chemistry.txt":
            Resolution(Resolution.DELETE, s3_client, None, "chemistry.txt",
                       9431),
            "history.txt":
            Resolution(Resolution.CREATE, s3_client, local_client,
                       "history.txt", 5000),
            "art.txt":
            Resolution(Resolution.CREATE, local_client, s3_client, "art.txt",
                       200000),
        }
        assert unhandled_events == expected_unhandled_events
        assert resolutions == expected_resolutions