Skip to content

Commit be1a2bf

Browse files
Merge pull request #518 from Abdur-rahmaanJ/test/init
Test/init
2 parents 2220bb5 + 19f2ee8 commit be1a2bf

File tree

24 files changed

+550
-935
lines changed

24 files changed

+550
-935
lines changed

.github/workflows/tests.yml

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
2+
3+
name: Tests
4+
on:
5+
push:
6+
branches:
7+
- dev
8+
pull_request:
9+
branches:
10+
- dev
11+
paths-ignore:
12+
- 'shopyo/sphinx_src/**'
13+
- '*.md'
14+
- '*.rst'
15+
jobs:
16+
tests:
17+
name: ${{ matrix.name }}
18+
runs-on: ${{ matrix.os }}
19+
strategy:
20+
fail-fast: false
21+
matrix:
22+
include:
23+
# - {name: Windows, python: '3.9', os: windows-latest, tox: py39}
24+
# - {name: Mac, python: '3.9', os: macos-latest, tox: py39}
25+
- {name: Linux, python: '3.9', os: ubuntu-latest, tox: py39}
26+
# - {name: '3.8', python: '3.8', os: ubuntu-latest, tox: py38}
27+
# - {name: '3.7', python: '3.7', os: ubuntu-latest, tox: py37}
28+
steps:
29+
- uses: actions/checkout@v2
30+
- uses: actions/setup-python@v2
31+
with:
32+
python-version: ${{ matrix.python }}
33+
- name: update pip
34+
run: |
35+
pip install -U wheel
36+
pip install -U setuptools
37+
python -m pip install -U pip
38+
- name: install requirements
39+
run: |
40+
python -m pip install pytest pytest-coverage coverage
41+
python -m pip install .
42+
- name: get pip cache dir
43+
id: pip-cache
44+
run: echo "::set-output name=dir::$(pip cache dir)"
45+
- name: cache pip
46+
uses: actions/cache@v2
47+
with:
48+
path: ${{ steps.pip-cache.outputs.dir }}
49+
key: pip|${{ runner.os }}|${{ matrix.python }}|${{ hashFiles('setup.py') }}|${{ hashFiles('requirements/*.txt') }}|${{ hashFiles('requirements.txt') }}
50+
- run: pip install tox codecov
51+
- run: tox -e py
52+
- name: Upload coverage to Codecov
53+
uses: codecov/codecov-action@v1

README.md

+9
Original file line numberDiff line numberDiff line change
@@ -258,3 +258,12 @@ SQLALCHEMY_DATABASE_URI: sqlite:///shopcube.db
258258
![](screenshots/new_screenshots/2.png)
259259
![](screenshots/new_screenshots/3.png)
260260
![](screenshots/new_screenshots/4.png)
261+
262+
# Tests
263+
264+
In venv
265+
266+
```
267+
cd src/shopcube
268+
python -m pytest ./
269+
```

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
long_description = f.read()
3535
setup(
3636
name="shopcube", # Required
37-
version="4.3.2", # Required
37+
version="4.4.0", # Required
3838
description="E-commerce solution", # Optional
3939
long_description=long_description, # Optional
4040
long_description_content_type="text/markdown", # Optional (see note above)

src/shopcube/app.py

+16-17
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,27 @@
44
import os
55
import sys
66

7+
import click
8+
79
# from flask import redirect
810
from flask import Flask
911
from flask import send_from_directory
1012
from flask import url_for
11-
12-
import click
1313
from flask_login import current_user
1414
from flask_wtf.csrf import CSRFProtect
1515

1616
sys.path.append(".")
1717

18+
import datetime
19+
20+
import flask
1821
import jinja2
1922
import shopyo
20-
from shopyo.api.file import trycopy
21-
2223
from config import app_config
2324
from init import configure_all_uploads
24-
from init import csrf
25-
from init import db
26-
from init import login_manager
27-
from init import ma
28-
from init import mail
29-
from init import migrate
25+
from init import load_extensions
3026
from init import modules_path
27+
from shopyo.api.file import trycopy
3128

3229
logging.basicConfig(level=logging.DEBUG)
3330

@@ -82,13 +79,7 @@ def create_app(config_name, configs=None):
8279

8380
# app.logger.info(app.config)
8481

85-
migrate.init_app(app, db)
86-
db.init_app(app)
87-
ma.init_app(app)
88-
login_manager.init_app(app)
89-
90-
mail.init_app(app)
91-
csrf.init_app(app)
82+
load_extensions(app)
9283

9384
configure_all_uploads(app)
9485

@@ -260,6 +251,14 @@ def flight_info():
260251
)
261252
)
262253

254+
# some stuffs
255+
256+
@app.before_request
257+
def before_request():
258+
flask.session.permanent = True
259+
app.permanent_session_lifetime = datetime.timedelta(minutes=20)
260+
flask.session.modified = True
261+
263262
# end of func
264263
return app
265264

src/shopcube/config.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ class Config:
1616

1717
UPLOADED_PRODUCTPHOTOS_DEST = os.path.join(STATIC, "uploads", "products")
1818
UPLOADED_CATEGORYPHOTOS_DEST = os.path.join(STATIC, "uploads", "category")
19-
UPLOADED_SUBCATEGORYPHOTOS_DEST = os.path.join(STATIC, "uploads", "subcategory")
19+
UPLOADED_SUBCATEGORYPHOTOS_DEST = os.path.join(
20+
STATIC, "uploads", "subcategory"
21+
)
2022
UPLOADED_PRODUCTEXCEL_DEST = os.path.join(STATIC, "uploads")
2123
UPLOADED_PRODUCTEXCEL_ALLOW = ("xls", "xlsx", "xlsm", "xlsb", "odf")
2224
PASSWORD_SALT = "abcdefghi"
@@ -36,7 +38,7 @@ class DevelopmentConfig(Config):
3638
ENV = "development"
3739
DEBUG = True
3840
# EXPLAIN_TEMPLATE_LOADING = True
39-
LOGIN_DISABLED = True
41+
# LOGIN_DISABLED = True
4042
# control email confirmation for user registration
4143
EMAIL_CONFIRMATION_DISABLED = False
4244
# flask-mailman configs
@@ -46,7 +48,9 @@ class DevelopmentConfig(Config):
4648
MAIL_USE_SSL = False
4749
MAIL_USERNAME = "" # os.environ.get("MAIL_USERNAME")
4850
MAIL_PASSWORD = "" # os.environ.get("MAIL_PASSWORD")
49-
MAIL_DEFAULT_SENDER = "[email protected]" # os.environ.get("MAIL_DEFAULT_SENDER")
51+
MAIL_DEFAULT_SENDER = (
52+
"[email protected]" # os.environ.get("MAIL_DEFAULT_SENDER")
53+
)
5054

5155

5256
class TestingConfig(Config):
@@ -59,7 +63,11 @@ class TestingConfig(Config):
5963
SERVER_NAME = "localhost.com"
6064
BCRYPT_LOG_ROUNDS = 4
6165
TESTING = True
66+
ENV = "testing"
67+
LOGIN_DISABLED = False
6268
WTF_CSRF_ENABLED = False
69+
PREFERRED_URL_SCHEME = "http"
70+
SECRET_KEY = "abcd"
6371

6472

6573
app_config = {

0 commit comments

Comments
 (0)