Skip to content

Commit

Permalink
feat: content render and restart (#236)
Browse files Browse the repository at this point in the history
Co-authored-by: Jonathan Keane <jkeane@gmail.com>
  • Loading branch information
tdstein and jonkeane authored Jul 24, 2024
1 parent cb71920 commit 2132431
Show file tree
Hide file tree
Showing 24 changed files with 1,436 additions and 120 deletions.
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.
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>"
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/
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>.
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)
60 changes: 53 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,46 @@ 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("2024.04.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/connect/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.restart()
# delete content
content.delete()

@pytest.mark.skipif(
CONNECT_VERSION <= version.parse("2023.01.1"),
reason="Quarto not available",
)
def test_render(self):
# create content
content = self.client.content.create(name="example-quarto-minimal")
# create bundle
path = Path(
"../../../resources/connect/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()
# render
task = content.render()
task.wait_for()
# delete content
content.delete()
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"]
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/*"

[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/*"]

[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

0 comments on commit 2132431

Please sign in to comment.