Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: content render and restart #236

Merged
merged 19 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ cov:

cov-html:
$(PYTHON) -m coverage html
open htmlcov/index.html

cov-xml:
$(PYTHON) -m coverage xml
Expand Down
File renamed without changes.
Binary file not shown.
8 changes: 8 additions & 0 deletions integration/resources/bundles/example-flask-minimal/hello.py
tdstein marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from flask import Flask

app = Flask(__name__)


@app.route("/")
def hello_world():
return "<p>Hello, World!</p>"
24 changes: 24 additions & 0 deletions integration/resources/bundles/example-flask-minimal/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"version": 1,
"locale": "en_US.UTF-8",
"metadata": {
"appmode": "python-api",
"entrypoint": "hello"
},
"python": {
"version": "3.12.2",
"package_manager": {
"name": "pip",
"version": "24.1.2",
"package_file": "requirements.txt"
}
},
"files": {
"requirements.txt": {
"checksum": "2861f6872b39701536a1fdf2c7bff86b"
},
"hello.py": {
"checksum": "09f4dee97c8b7e2770157cf5d7fb6a73"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Flask==3.0.3
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/.quarto/
_site/
19 changes: 19 additions & 0 deletions integration/resources/bundles/example-quarto-minimal/_quarto.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
project:
type: website

website:
title: "example-quarto-minimal"
navbar:
left:
- href: index.qmd
text: Home
- about.qmd

format:
html:
theme: cosmo
css: styles.css
toc: true



Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: "About"
---

About this site
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
title: "example-quarto-minimal"
---

This is a Quarto website.

To learn more about Quarto websites visit <https://quarto.org/docs/websites>.
30 changes: 30 additions & 0 deletions integration/resources/bundles/example-quarto-minimal/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"version": 1,
"metadata": {
"appmode": "quarto-static",
"content_category": "site"
},
"quarto": {
"version": "1.5.54",
"engines": [
"markdown"
]
},
"files": {
".gitignore": {
"checksum": "ebea58ee833ccab90d803cd345b2c81f"
},
"_quarto.yml": {
"checksum": "619323d181451c463ed77284cb31da12"
},
"about.qmd": {
"checksum": "b3260e8597e68ac0d3a7951d26a2e945"
},
"index.qmd": {
"checksum": "8395ee08073124f3ca275ed29ec1a24a"
},
"styles.css": {
"checksum": "e31c3cdea03dfab8a29456978017bd10"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* css styles */
8 changes: 8 additions & 0 deletions integration/tests/posit/connect/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import os

from packaging import version

from posit import connect

client = connect.Client()
CONNECT_VERSION = version.parse(client.version)
62 changes: 55 additions & 7 deletions integration/tests/posit/connect/test_content.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
from pathlib import Path
from packaging import version

import pytest

from posit import connect

from . import CONNECT_VERSION


class TestContent:
@classmethod
def setup_class(cls):
cls.client = connect.Client()
cls.item = cls.client.content.create(
name="Sample",
description="Simple sample content for testing",
access_type="acl",
)
cls.content = cls.client.content.create(name="example")

@classmethod
def teardown_class(cls):
cls.item.delete()
cls.content.delete()
assert cls.client.content.count() == 0

def test_count(self):
assert self.client.content.count() == 1

def test_get(self):
assert self.client.content.get(self.item.guid) == self.item
assert self.client.content.get(self.content.guid) == self.content

def test_find(self):
assert self.client.content.find()
Expand All @@ -37,3 +40,48 @@ def test_content_item_owner_from_include(self):
item = self.client.content.find_one(include="owner")
owner = item.owner
assert owner.guid == self.client.me.guid

@pytest.mark.skipif(
CONNECT_VERSION <= version.parse("2023.01.1"),
reason="Python 3.12 not available",
)
def test_restart(self):
# create content
content = self.client.content.create(name="example-flask-minimal")
# create bundle
path = Path(
"../../../resources/bundles/example-flask-minimal/bundle.tar.gz"
)
path = (Path(__file__).parent / path).resolve()
bundle = content.bundles.create(str(path))
# deploy bundle
task = bundle.deploy()
task.wait_for()
# restart content
content.restart()
# delete content
content.delete()

@pytest.mark.skipif(
CONNECT_VERSION <= version.parse("2023.01.1"),
reason="Quarto not available",
)
def test_refresh(self):
# create content
content = self.client.content.create(name="example-quarto-minimal")
# create bundle
path = Path(
"../../../resources/bundles/example-quarto-minimal/bundle.tar.gz"
)
path = (Path(__file__).parent / path).resolve()
bundle = content.bundles.create(str(path))
# deploy bundle
task = bundle.deploy()
task.wait_for()
# refresh content
task = content.refresh()
if task:
task.wait_for()

# delete content
content.delete()
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still working on adding support for the skipped versions of Connect, but I'll make a separate change. Theres a bit involved to make it work, so it deserves its own pull request.

41 changes: 41 additions & 0 deletions integration/tests/posit/connect/test_env.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from posit import connect


class TestEnvVars:
@classmethod
def setup_class(cls):
cls.client = connect.Client()
cls.content = cls.client.content.create(
name="Sample",
description="Simple sample content for testing",
access_type="acl",
)

@classmethod
def teardown_class(cls):
cls.content.delete()
assert cls.client.content.count() == 0

def test_clear(self):
self.content.environment_variables.create("KEY", "value")
assert self.content.environment_variables.find() == ["KEY"]
tdstein marked this conversation as resolved.
Show resolved Hide resolved
self.content.environment_variables.clear()
assert self.content.environment_variables.find() == []

def test_create(self):
self.content.environment_variables.create("KEY", "value")
assert self.content.environment_variables.find() == ["KEY"]

def test_delete(self):
self.content.environment_variables.create("KEY", "value")
assert self.content.environment_variables.find() == ["KEY"]
self.content.environment_variables.delete("KEY")
assert self.content.environment_variables.find() == []

def test_find(self):
self.content.environment_variables.create("KEY", "value")
assert self.content.environment_variables.find() == ["KEY"]

def test_update(self):
self.content.environment_variables.update(KEY="value")
assert self.content.environment_variables.find() == ["KEY"]
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ dependencies = ["requests>=2.31.0,<3"]
Source = "https://github.com/posit-dev/posit-sdk-py"
Issues = "https://github.com/posit-dev/posit-sdk-py/issues"

[tool.mypy]
exclude = "integration/resources/*"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ignore the resources folder with static type checking.


[tool.pytest.ini_options]
testpaths = ["tests"]
addopts = ["--import-mode=importlib"]
Expand All @@ -34,6 +37,7 @@ version_file = "src/posit/_version.py"

[tool.ruff]
line-length = 79
exclude = ["integration/resources/*"]
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ignore the resources folder when linting


[tool.ruff.format]
docstring-code-format = true
Expand Down Expand Up @@ -71,5 +75,6 @@ ignore = [
"examples/*" = ["D"]
"tests/*" = ["D"]


[tool.ruff.lint.pydocstyle]
convention = "numpy"
Loading
Loading