Robyn
Robyn copied to clipboard
Added add_template_global function to JinjaTemplate.
Description
This PR fixes #
- Added add_template_global function to JinjaTemplate.
- Added the docs
@carrycooldude is attempting to deploy a commit to the sparckles Team on Vercel.
A member of the Team first needs to authorize it.
Hey @carrycooldude 👋
Good job with the PR 😄 I have some inline suggestions.
CodSpeed Performance Report
Merging #758 will not alter performance
Comparing carrycooldude:main
(f72d0ea) with main
(bccbe4c)
Summary
✅ 106
untouched benchmarks
🆕 2
new benchmarks
Benchmarks breakdown
Benchmark | main |
carrycooldude:main |
Change | |
---|---|---|---|---|
🆕 | test_url_for[async] |
N/A | 24 ms | N/A |
🆕 | test_url_for[sync] |
N/A | 24 ms | N/A |
Hey @carrycooldude 👋
Good update. Two more things
We already have a documentation page for jinja (https://github.com/sparckles/Robyn/blob/main/docs_src/src/pages/documentation/api_reference/templating.mdx) , can you add pertinent documentation there?
Also, can you add an integration test in the integration_tests/base_routes.py
folder?
Hey @sansyrox , I never did integration testing before but let me know what I am suggesting below is it the same?
import pytest
from robyn.templating import JinjaTemplate
@pytest.mark.integration
def test_add_template_global():
template = JinjaTemplate()
template.add_template_global("my_global", "Hello, world!")
rendered_template = template.render_template("my_template.html")
assert "Hello, world!" in rendered_templateimport pytest
from robyn.templating import JinjaTemplate
@pytest.mark.integration
def test_jinja_template():
template = JinjaTemplate()
template.add_template_global("my_global", "Hello, world!")
rendered_template = template.render_template("my_template.html")
assert "Hello, world!" in rendered_template
# Test loading static resources
static_url = template.render_template("static_url.html")
assert static_url == "/static/images/planets.jpeg"
# Test route URL
route_url = template.render_template("route_url.html")
assert route_url == "/"
@carrycooldude , first add a route like this in the base_routes/integration_tests.py
file.
Then alter this test in integration_tests/test_get_requests.py
.
What you have written atm is a unit test. But I like to write integration tests for most changes. I can explain the rationale on a call. But I hope this makes sense for now. 😄
Hey @carrycooldude 👋
Thank you for the PR. I have some suggestions for the code.
![]()
@carrycooldude , first add a route like this in the
base_routes/integration_tests.py
file.Then alter this test in
integration_tests/test_get_requests.py
.What you have written atm is a unit test. But I like to write integration tests for most changes. I can explain the rationale on a call. But I hope this makes sense for now. 😄
Hey @sansyrox , for integration testing , we need add both sync and async routes right with different endpoint ? This is kinda example for the same
import unittest
from flask import Flask, url_for
class TestURLGeneration(unittest.TestCase):
def setUp(self):
self.app = Flask(__name__)
# Define some routes for testing
@self.app.route('/')
def home():
return 'Home Page'
@self.app.route('/user/<username>')
def profile(username):
return f'Profile Page for {username}'
# Define a static file route
@self.app.route('/static/<path:filename>')
def static_file(filename):
return f'Static File: {filename}'
def test_home_url(self):
with self.app.test_request_context():
# Generate URL for the home route
url = url_for('home')
self.assertEqual(url, '/')
def test_profile_url(self):
with self.app.test_request_context():
# Generate URL for the profile route with a username parameter
url = url_for('profile', username='john_doe')
self.assertEqual(url, '/user/john_doe')
def test_static_file_url(self):
with self.app.test_request_context():
# Generate URL for a static file
url = url_for('static', filename='style.css')
self.assertEqual(url, '/static/style.css')
if __name__ == '__main__':
unittest.main()
@carrycooldude ,
what you have mentioned is again a unitTest
. You need to add it to the existing endpoints in the codebase.
@carrycooldude , I have left a few comments.
I don't know why importing error is coming...
Same error with
tests_get_requests.py
@sansyrox need your help in this...