Beispiel #1
0
def test_shouldEncodeLocationsAsMultipleOptions(fixture):
    fixture.functions.expectCalls(
        mock.callMatching(
            "callVoid", lambda _, args, options: dictIncludes(
                options, {
                    "SomePlaceProtocol": "ftp",
                    "SomePlaceLogin": "******",
                    "SomePlaceHost": "mansion",
                    "SomePlacePort": "10",
                    "SomePlacePath": "/blah/quux",
                    "LocalProtocol": "file",
                    "LocalPath": "/foo",
                    "RestoreLogin": "",
                    "RestoreHost": "blah",
                    "RestorePath": "/foo"
                })))

    options = {
        "SomePlace":
        remoteLocation(protocol="ftp",
                       login="******",
                       host="mansion",
                       port="10",
                       path="/blah/quux"),
        "Local":
        localLocation("/foo")
    }

    fixture.syncer.restore(options, "file", 2, anyUTCDateTime(),
                           remoteLocation("http", host="blah", path="/foo"))

    fixture.functions.checkExpectedCalls()
Beispiel #2
0
 def shouldTreatEqually(protocol1, protocol2, onlyAbsolutePaths):
     self.assertLocIsWithin(
         remoteLocation(protocol=protocol1, path="/"),
         remoteLocation(protocol=protocol2, path="/"))
     loc1 = remoteLocation(protocol=protocol1, path=".")
     loc2 = remoteLocation(protocol=protocol2, path=".")
     if onlyAbsolutePaths:
         assert not loc1.contains(loc2)
     else:
         self.assertLocIsWithin(loc2, loc1)
Beispiel #3
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"]
Beispiel #4
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"]
Beispiel #5
0
    def test_shouldAlsoRequireLoginAndPortToBeEqualIfPathsAreRelative(self):
        assert not remoteLocation(login="******", path=".").contains(
            remoteLocation(login="******"))
        assert not remoteLocation(port="123", path=".").contains(
            remoteLocation(port="321", path="."))

        self.assertLocIsWithin(remoteLocation(port="123", path="/"),
                               remoteLocation(port="321", path="/"),
                               relPart=".")
        self.assertLocIsWithin(remoteLocation(login="******", path="/"),
                               remoteLocation(login="******", path="/"),
                               relPart=".")
Beispiel #6
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())
Beispiel #7
0
 def ret(path):
     return remoteLocation(protocol=protocol,
                           login="",
                           host="localhost",
                           port=str(port),
                           path=path)
Beispiel #8
0
def sshLocationFromPath(path):
    return remoteLocation(protocol="ssh",
                          login="",
                          host="localhost",
                          port=str(sshserver.Port),
                          path=path)
Beispiel #9
0
 def test_shouldRequireProtocolsAndHostsToBeEqualForContainsTest(self):
     assert not remoteLocation(protocol="this").contains(
         remoteLocation(protocol="that"))
     assert not remoteLocation(host="this").contains(
         remoteLocation(host="that"))
Beispiel #10
0
 def test_shouldTakeProtocolEtcIntoAccountWhenComparingWithRemoteLocs(self):
     assert remoteLocation(protocol="a") != remoteLocation(protocol="b")