Пример #1
0
    def test_migrate_screenshot(self):
        content = copy.deepcopy(CURRENT)
        content["RobotSpareBin.Username"]["screenshot"] = "not-exist.png"
        content["RobotSpareBin.Password"]["screenshot"] = (
            "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAA"
            "AACklEQVR42mMAAQAABQABoIJXOQAAAABJRU5ErkJggg=="
        )

        with temp_cwd() as cwd:
            images = Path(cwd) / ".images"
            screenshot_username = images / "robotsparebin-username-screenshot.png"
            screenshot_password = images / "robotsparebin-password-screenshot.png"

            database = LocatorsDatabase(to_stream(content))
            database.load()

            assert database.error is None
            assert len(database.locators) == 4

            assert images.is_dir()
            assert not (screenshot_username).is_file()
            assert (screenshot_password).is_file()

            username = database.locators["RobotSpareBin.Username"]
            assert username.screenshot == "not-exist.png"

            password = database.locators["RobotSpareBin.Password"]
            assert password.screenshot == str(screenshot_password.relative_to(cwd))
Пример #2
0
    def test_load_invalid(self):
        database = LocatorsDatabase(to_stream(ERRORS))
        database.load()

        assert database.error is None
        assert len(database.locators) == 1
        assert len(database._invalid) == 2
Пример #3
0
    def test_load_malformed(self):
        stream = io.StringIO("not-a-json{]}\\''")

        database = LocatorsDatabase(stream)
        database.load()

        assert database.error is not None
        assert len(database.error) == 2
        assert len(database.locators) == 0
Пример #4
0
    def test_legacy_missing_name(self):
        content = copy.deepcopy(LEGACY)
        del content[1]["name"]

        database = LocatorsDatabase(to_stream(content))
        database.load()

        assert database.error is None
        assert len(database.locators) == 2
Пример #5
0
    def test_resolve_paths(self):
        database = LocatorsDatabase(to_stream(CURRENT))
        database.load()

        database.path = "/example/root/path/locators.json"

        locator = database.resolve("RobotSpareBin.Logo")
        assert isinstance(locator, ImageLocator)
        assert Path(locator.path) == Path(
            "/example/root/path/relative/locator/path.png")
        assert Path(locator.source) == Path("/absolute/locator/path.png")
Пример #6
0
    def test_save(self):
        stream = to_stream(CURRENT)
        database = LocatorsDatabase(stream)
        database.load()

        stream.truncate(0)
        stream.seek(0)
        database.locators["RobotSpareBin.Password"].value = "paswerd"
        database.save()

        data = stream.getvalue()
        content = json.loads(data)
        assert content["RobotSpareBin.Password"]["value"] == "paswerd"
Пример #7
0
    def test_reset_error(self):
        database = LocatorsDatabase()

        database.path = io.StringIO("some-error")
        database.load()

        assert database.error is not None
        assert len(database.locators) == 0

        database.path = to_stream(CURRENT)
        database.load()

        assert database.error is None
        assert len(database.locators) == 4
Пример #8
0
    def test_load_missing(self):
        database = LocatorsDatabase("not/a/valid/path")
        database.load()

        assert database.error is None
        assert len(database.locators) == 0
Пример #9
0
    def test_load_legacy_empty(self):
        database = LocatorsDatabase(to_stream({}))
        database.load()

        assert database.error is None
        assert len(database.locators) == 0
Пример #10
0
 def current_database(self):
     database = LocatorsDatabase(to_stream(CURRENT))
     database.load()
     return database
Пример #11
0
 def legacy_database(self):
     database = LocatorsDatabase(to_stream(LEGACY))
     database.load()
     return database