Skip to content

Commit

Permalink
Merge pull request #57 from hadpro24/develop
Browse files Browse the repository at this point in the history
Develop :  Change name folder application
  • Loading branch information
hadpro24 authored Aug 11, 2021
2 parents 997187f + f6a2148 commit e2fab33
Show file tree
Hide file tree
Showing 14 changed files with 85 additions and 35 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,8 @@ jobs:
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
with:
fail_ci_if_error: true
fail_ci_if_error: true
- name: Changelog
uses: heinrichreimer/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Changelog
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
[![pypi](https://img.shields.io/pypi/v/nimba.svg)](https://pypi.org/project/nimba/)
[![pypi](https://img.shields.io/pypi/l/nimba.svg)](https://pypi.org/project/nimba/)
[![pypi](https://img.shields.io/pypi/pyversions/nimba)](https://pypi.org/project/nimba/)
[![Issues](https://img.shields.io/github/issues/hadpro24/nimba-framework.svg)](https://github.com/hadpro24/nimba-framework/issues)

Nimba Framework is a fast coding, web framework with python.
Nimba is a python web framework for lazy developers, focusing only on your needs.
> **warning** This project is private and is still in design, not ready for production. Create an issue if you encounter any bugs!
Everything you need to know about Nimba Framework
Expand Down Expand Up @@ -48,7 +49,7 @@ $ nimba create --app awesome_app

### Structure project

* `app` - Your app project, you will spend most of your time here.
* `application` - Your app project (you will spend most of your time here).
- `views.py` - Your logic code
- `models.py` - Define here the schema of your database
- `tests.py` - Write your test here
Expand Down
8 changes: 4 additions & 4 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
Everything you need to know about Nimba Framework

Nimba Framework is a modern, fast coding, web framework with Python 3.6+.
Nimba is a python web framework for lazy developers, focusing only on your needs.

The key features are:

* **Fast to code**: Increase the speed to develop features. *
* **Intuitive**: Excellent editor support. Quick understanding. Less debugging time..
* **Fast to code**: Increase the speed to develop features.
* **Intuitive**: Quick understanding. Less debugging time..
* **Easy**: Designed to be easy to use and learn. Less time reading docs.
* **Short**: Minimizes code duplication. Multiple functionalities. Fewer bugs.

Expand All @@ -37,7 +37,7 @@ $ nimba create --app awesome_app

### Structure project

* `app` - Your app project, you will spend most of your time here.
* `application` - Your app project (you will spend most of your time here).
- `views.py` - Your logic code
- `models.py` - Define here the schema of your database
- `tests.py` - Write your test here
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorial/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ $ nimba create --app awesome_app

### Structure project

* `app` - Your app project, you will spend most of your time here.
* `application` - Your application project (you will spend most of your time here).
- `views.py` - Your logic code
- `models.py` - Define here the schema of your database
- `tests.py` - Write your test here
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion nimba/commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def __call__(self):
from nimba.core.welcom import home_default
try:
view_module = importlib.import_module(
os.environ.get('APP_MASK_VIEW', 'app.views')
os.environ.get('APP_MASK_VIEW', 'application.views')
)
for attr in dir(view_module):
if hasattr(attr, '__call__'):
Expand Down
19 changes: 9 additions & 10 deletions nimba/commands/createapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def main():
except ImportError as e:
raise ImportError(
"Couldn't import nimba server. Active your environnement"
"or install nimba framework (ex: pip install nimba-framework)"
"or install nimba framework (ex: pip install nimba)"
)
mont_nimba(sys.argv, pathlib.Path(__file__).parent.absolute())
Expand All @@ -36,9 +36,9 @@ def home(request):
return render('awesome_app/home.html')
"""

import_test = """#write your test here """
import_models = """#write your models here """
import_settings = """#all settings application """
import_test = """# write your test here """
import_models = """# write your models here """
import_settings = """# all settings application """

class CreateApp:
"""
Expand Down Expand Up @@ -71,26 +71,25 @@ def handle(self):
)
)
with Loader("Create application...", "Done!"):
import shutil
#create application
os.makedirs(path_application)
os.makedirs(os.path.join(path_application, 'app'))
os.makedirs(os.path.join(path_application, 'application'))
os.makedirs(os.path.join(path_application, f'templates/{self.app_label}'))
os.makedirs(os.path.join(path_application, 'staticfiles'))
#template
f = open(os.path.join(path_application, f'templates/{self.app_label}', 'home.html'), 'w+')
f.write(DEFAULT_DIRECTORY_INDEX_TEMPLATE)
f.close()
#init
f = open(os.path.join(path_application, 'app', '__init__.py'), 'w+')
f = open(os.path.join(path_application, 'application', '__init__.py'), 'w+')
f.close()
f = open(os.path.join(path_application, 'app', 'models.py'), 'w+')
f = open(os.path.join(path_application, 'application', 'models.py'), 'w+')
f.write(import_models)
f.close()
f = open(os.path.join(path_application, 'app', 'views.py'), 'w+')
f = open(os.path.join(path_application, 'application', 'views.py'), 'w+')
f.write(import_view)
f.close()
f = open(os.path.join(path_application, 'app', 'tests.py'), 'w+')
f = open(os.path.join(path_application, 'application', 'tests.py'), 'w+')
f.write(import_test)
f.close()
#setting
Expand Down
30 changes: 20 additions & 10 deletions nimba/test/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ def get(self, path, data=None, secure=False):

url = self.base_url+url
res = {}
f = open(os.devnull, 'w')
old_target = sys.stdout
sys.stdout = f
# f = open(os.devnull, 'w')
# old_target = sys.stdout
# sys.stdout = f
try:
response = urllib.request.urlopen(url)
res['status_code'] = response.code
Expand All @@ -138,19 +138,29 @@ def get(self, path, data=None, secure=False):
except urllib.error.URLError as error_sys:
res['status_code'] = error_sys.code
res['text'] = error_sys.read().decode('utf-8')
f.close()
sys.stdout = old_target
# f.close()
# sys.stdout = old_target
return res

def post(self, path, data=None, secure=False,
content_type='multipart/form-data; boundary=BoUnDaRyStRiNg'):
data = self._encode_json({} if data is None else data, content_type)
query_string = urllib.parse.urlencode(data)
data = query_string.encode('ascii')
# query_string = urllib.parse.urlencode(data)
# data = query_string.encode('ascii')
path = self.base_url+path
with urllib.request.urlopen(path, data) as response:
response_text = response.read()
return response_text
res = {}
try:
response = urllib.request.urlopen(path, data)
res['status_code'] = response.code
res['text'] = response.read().decode('utf-8')
except urllib.error.HTTPError as error:
res['status_code'] = error.code
# response['text'] = e.msg
res['text'] = error.file.read().decode('utf-8')
except urllib.error.URLError as error_sys:
res['status_code'] = error_sys.code
res['text'] = error_sys.read().decode('utf-8')
return res

def _encode_json(self, data, content_type):
"""
Expand Down
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[metadata]
name = nimba
version = 0.0.13
description = Nimba is a fast coding, web framework with Python.
version = 0.0.14
description = Nimba is a python web framework for lazy developers, focusing only on your needs.
long_description = file: README.rst
keywords = python, python3, framework, nimba, nimba-solution, web
url = https://github.com/hadpro24/nimba-framework
Expand Down
43 changes: 39 additions & 4 deletions tests/test_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@

from nimba.test.client import TestCase

from nimba.core.welcom import (
DEFAULT_DIRECTORY_INDEX_TEMPLATE,
home_default
)

TEST = 'test'

@router('/about')
Expand Down Expand Up @@ -68,16 +73,26 @@ def get_data(request):
{'success': True, 'data': [4, 5, 6]},
)

@router('/users/create', methods=['POST'])
def users_post(request):
return 'Ok'

@router('/users', methods=['GET'])
def users_list(request):
return 'Ok'

@router('/error-test')
def error_test(request):
raise ValueError("error")
return 'Ok'

class TestRouterRender(TestCase):
def setUp(self):
os.environ['PROJECT_MASK_PATH'] = str(pathlib.Path(
__file__
).parent.absolute())
self.url = 'tests/templates/awesome_app'
os.makedirs(self.url)
f = open(os.path.join(self.url, 'home.html'), 'w+')
f.write(TEST)
f.close()
#wrtie me
f = open(os.path.join(self.url, 'me.html'), 'w+')
f.write('hello, world')
Expand All @@ -86,7 +101,10 @@ def setUp(self):
def test_route_home(self):
response = self.get('/')
self.assertEqual(200, response['status_code'])
self.assertEqual(TEST, response['text'])
self.assertIn(
"Nimba Framework successfully installed",
response['text']
)

def test_route_about(self):
response = self.get('/about')
Expand Down Expand Up @@ -125,6 +143,23 @@ def test_reverse_with_name(self):
self.assertEqual(200, response['status_code'])
self.assertEqual(TEST, response['text'])

def test_method_authorized(self):
url = reverse('users_post')
response = self.get(url)
self.assertEqual(401, response['status_code'])
response = self.post(url)
self.assertEqual(200, response['status_code'])

def test_method_post(self):
url =reverse('users_list')
response = self.post(url)
self.assertEqual(401, response['status_code'])

def test_error_view(self):
url = reverse('error_test')
response = self.get(url)
self.assertEqual(500, response['status_code'])

def test_reverse_with_name_and_kwargs(self):
#error type name path
with self.assertRaises(ValueError) as error:
Expand Down

0 comments on commit e2fab33

Please sign in to comment.