diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 64c2b3d..fe42444 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -34,4 +34,8 @@ jobs: - name: Upload coverage to Codecov uses: codecov/codecov-action@v1 with: - fail_ci_if_error: true \ No newline at end of file + fail_ci_if_error: true + - name: Changelog + uses: heinrichreimer/github-changelog-generator-action@v2.1.1 + with: + token: ${{ secrets.GITHUB_TOKEN }} diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..5ddad42 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1 @@ +# Changelog \ No newline at end of file diff --git a/README.md b/README.md index d854a2a..60d47cf 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 diff --git a/docs/index.md b/docs/index.md index cc793ec..e3e49f7 100644 --- a/docs/index.md +++ b/docs/index.md @@ -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. @@ -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 diff --git a/docs/tutorial/index.md b/docs/tutorial/index.md index 0541bb4..b9de80d 100644 --- a/docs/tutorial/index.md +++ b/docs/tutorial/index.md @@ -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 diff --git a/examples/awesome_app/app/__init__.py b/examples/awesome_app/application/__init__.py similarity index 100% rename from examples/awesome_app/app/__init__.py rename to examples/awesome_app/application/__init__.py diff --git a/examples/awesome_app/app/models.py b/examples/awesome_app/application/models.py similarity index 100% rename from examples/awesome_app/app/models.py rename to examples/awesome_app/application/models.py diff --git a/examples/awesome_app/app/tests.py b/examples/awesome_app/application/tests.py similarity index 100% rename from examples/awesome_app/app/tests.py rename to examples/awesome_app/application/tests.py diff --git a/examples/awesome_app/app/views.py b/examples/awesome_app/application/views.py similarity index 100% rename from examples/awesome_app/app/views.py rename to examples/awesome_app/application/views.py diff --git a/nimba/commands/__init__.py b/nimba/commands/__init__.py index e603102..e8b9561 100644 --- a/nimba/commands/__init__.py +++ b/nimba/commands/__init__.py @@ -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__'): diff --git a/nimba/commands/createapp.py b/nimba/commands/createapp.py index d415623..cb4bff8 100644 --- a/nimba/commands/createapp.py +++ b/nimba/commands/createapp.py @@ -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()) @@ -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: """ @@ -71,10 +71,9 @@ 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 @@ -82,15 +81,15 @@ def handle(self): 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 diff --git a/nimba/test/client.py b/nimba/test/client.py index 4dbc9dd..6d6fc08 100644 --- a/nimba/test/client.py +++ b/nimba/test/client.py @@ -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 @@ -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): """ diff --git a/setup.cfg b/setup.cfg index 5f1aad2..7339603 100644 --- a/setup.cfg +++ b/setup.cfg @@ -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 diff --git a/tests/test_router.py b/tests/test_router.py index 790378d..f03a609 100644 --- a/tests/test_router.py +++ b/tests/test_router.py @@ -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') @@ -68,6 +73,19 @@ 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( @@ -75,9 +93,6 @@ def setUp(self): ).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') @@ -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') @@ -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: