コード例 #1
0
def test_shouldNotAllowSyncersThatAlreadySupportSSHInAnyWay():
    assert not isExtensible(
        mockSyncer(ports=[port(["file", "ssh"]),
                          port(["file"])]))
    assert not isExtensible(
        mockSyncer(
            ports=[port(["file"]), port(["file", "ssh"])]))
コード例 #2
0
def test_shouldReturnVersionsGotFromSynchronizerIfFileIsWithinAPort(fixture):
    syncer = mockSyncer(ports=[port(), port(), port()])
    syncerOptions = mkSyncerOpts(Loc1=location("/mnt/data/loc1"),
                                 Loc2=location("/mnt/backup/loc2"),
                                 Loc3=location("/mnt/foo/loc3"))
    rule = fixture.ruleWith(mockedSynchronizer=syncer,
                            syncerOptions=syncerOptions)

    ret = orderedDateTimes(2)

    def check(path, expectedRelativePath, expectedLoc):
        syncer.expectCalls(
            mock.callMatching(
                "versionsOf",
                lambda options, path, locNumber: path == expectedRelativePath
                and locNumber == expectedLoc and options == syncerOptions,
                ret=ret))
        assert set(versionsOf(
            rule, path)) == {version(rule, ret[0]),
                             version(rule, ret[1])}
        syncer.checkExpectedCalls()

    check(location("/mnt/data/loc1/blah"), "blah", 1)
    check(location("/mnt/backup/loc2/one/two/"), "one/two", 2)
    check(location("/mnt/foo/loc3/bar/../"), ".", 3)
    assert len(versionsOf(rule, location("/mnt/data/quux"))) == 0
コード例 #3
0
def test_shouldThrowExceptionIfInUnstablePhaseWhileGettingVersions(fixture):
    syncer = mockSyncer()
    syncer.versionsOf = lambda *_: [anyUTCDateTime()]
    rule = fixture.ruleWith(mockedSynchronizer=syncer,
                            syncerOptions=mkSyncerOpts(Loc1=location("/loc1")))

    rule.versionsOf(location("/not-in-a-port"),
                    PositiveUnstablePhaseDetector())

    with pytest.raises(UnstablePhaseException):
        rule.versionsOf(location("/loc1"), PositiveUnstablePhaseDetector())
コード例 #4
0
    def checkWriteLocs(writtenToFlags,
                       expectedWriteLocs,
                       expectedNonWriteLocs,
                       loc2=loc2):
        syncer = mockSyncer()
        syncer.ports = [port(isWrittenTo=flag) for flag in writtenToFlags]

        rule = fixture.ruleWith(mockedSynchronizer=syncer,
                                syncerOptions=mkSyncerOpts(Loc1=loc1,
                                                           Loc2=loc2))

        assert set(rule.writeLocs) == set(expectedWriteLocs)
        assert set(rule.nonWriteLocs) == set(expectedNonWriteLocs)
コード例 #5
0
    def ruleWith(self,
                 name="some-rule",
                 scheduler=None,
                 mockedSynchronizer=None,
                 schedOptions={},
                 syncerOptions=mkSyncerOpts()):
        if mockedSynchronizer is None:
            mockedSynchronizer = mockSyncer()

        if "Loc1" not in syncerOptions:
            syncerOptions["Loc1"] = location("/mnt")
        if "Loc2" not in syncerOptions:
            syncerOptions["Loc2"] = location("/etc")
        return SyncRule(name, {}, schedOptions, syncerOptions, False,
                        scheduler, mockedSynchronizer, self.log)
コード例 #6
0
def test_shouldAssignRestoreTargetToThePortTheFileToBeRestoredWasFoundIn(
        fixture):
    syncer = mockSyncer()
    syncer.ports = [port(["a"]), port(["b"])]
    loc1 = remoteLocation(protocol="a", path="/foo")

    rule = fixture.ruleWith(mockedSynchronizer=syncer,
                            syncerOptions=mkSyncerOpts(Loc1=loc1,
                                                       Loc2=remoteLocation(
                                                           protocol="b",
                                                           path="/bar")))

    with pytest.raises(UnsupportedProtocolException) as ex:
        rule.restore(loc1, version(rule), remoteLocation(protocol="b"),
                     detector())
    assert ex.value.supportedProtocols == ["a"]
コード例 #7
0
def test_shouldThrowAnExceptionIfLocOptionsHaveProtocolsNotSupportedBySyncer(
        fixture):
    syncer = mockSyncer()
    syncer.ports = [port(["a", "b"]), port(["c"])]

    fixture.ruleWith(mockedSynchronizer=syncer,
                     syncerOptions=mkSyncerOpts(
                         Loc1=remoteLocation(protocol="b"),
                         Loc2=remoteLocation(protocol="c")))

    with pytest.raises(UnsupportedProtocolException) as ex:
        fixture.ruleWith(mockedSynchronizer=syncer,
                         syncerOptions=mkSyncerOpts(
                             Loc1=remoteLocation(protocol="b"),
                             Loc2=remoteLocation(protocol="d")))
    assert ex.value.optionName == "Loc2"
    assert ex.value.protocol == "d"
    assert ex.value.supportedProtocols == ["c"]
コード例 #8
0
def test_shouldEnforceSpecialInvariantThatOnePortMustHaveFileProtocol(fixture):
    syncer = mockSyncer()
    syncer.onePortMustHaveFileProtocol = True
    syncer.ports = [port(["file", "remote"]), port(["file", "remote"])]

    with pytest.raises(UnsupportedProtocolException) as ex:
        fixture.ruleWith(mockedSynchronizer=syncer,
                         syncerOptions=mkSyncerOpts(
                             Loc1=remoteLocation(protocol="remote"),
                             Loc2=remoteLocation(protocol="remote")))
    assert "at least one" in ex.value.explanation

    rule = fixture.ruleWith(mockedSynchronizer=syncer,
                            syncerOptions=mkSyncerOpts(
                                Loc1=remoteLocation(protocol="remote",
                                                    path="/foo"),
                                Loc2=remoteLocation(protocol="file",
                                                    path="/bar")))
    with pytest.raises(UnsupportedProtocolException) as ex:
        rule.restore(remoteLocation(protocol="file", path="/bar/file"),
                     version(rule), remoteLocation(protocol="remote"),
                     detector())
コード例 #9
0
def test_shouldNotAllowSyncersThatDontSupportLocalFiles():
    assert not isExtensible(mockSyncer(ports=[port(["file"]), port(["ftp"])]))
コード例 #10
0
 def init(self, ports, availableOptions=[]):
     wrapped = mockSyncer(availableOptions=availableOptions, ports=ports)
     self.wrapped = wrapped
     self.processRunner = LoggingProcessRunner()
     self.syncer = SSHFSAutoMountingSynchronizer(wrapped,
                                                 self.processRunner)