Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions linux/nikita/Flasko_web_site/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.mongodata
data/**
161 changes: 161 additions & 0 deletions linux/nikita/Flasko_web_site/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
.mongodata
19 changes: 19 additions & 0 deletions linux/nikita/Flasko_web_site/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# start by pulling the python image
FROM python:3.8-alpine

# copy every content from the local file to the image
COPY . /app

# copy the requirements file into the image
COPY ./requirements.txt /app/requirements.txt

WORKDIR /./app
# install the dependencies and packages in the requirements file
RUN pip install -r requirements.txt

# configure the container to run in an executed manner
ENTRYPOINT [ "python" ]

EXPOSE 5000

CMD ["main.py"]
11 changes: 11 additions & 0 deletions linux/nikita/Flasko_web_site/app/conf.d/app.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
upstream backend {
server app:5000;
}

server {
listen 80;

location / {
proxy_pass http://backend;
}
}
40 changes: 40 additions & 0 deletions linux/nikita/Flasko_web_site/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
version: "3.8"
services:
#nginx service
#web:
# container_name: "web"
# image: nginx:alpine
# depends_on:
# - app
# ports:
# - "8080:80"
# volumes:
# - ./app/conf.d:/etc/nginx/conf.d
# networks:
# - custom
app:
container_name: "app"
image: myapp/site:1.6
environment:
- MONGODB_URL=mongodb://mongo_db/
build:
context: .
dockerfile: Dockerfile
ports:
- 8080:5000
networks:
- custom
depends_on:
- mongo_db
mongo_db:
image: mongo
container_name: "mongo_db"
ports:
- 27017:27017
networks:
- custom
volumes:
- ./data/db/.mongodata:/data/db
networks:
custom:
driver: bridge
12 changes: 12 additions & 0 deletions linux/nikita/Flasko_web_site/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from website import create_app
from flask import Flask, render_template

app = create_app()

@app.route('/')
def home():
return render_template('welcome.html')


if __name__ == "__main__":
app.run(debug=True, host="0.0.0.0")
5 changes: 5 additions & 0 deletions linux/nikita/Flasko_web_site/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pymongo[srv]
flask
envparse
mongomock
unittest
57 changes: 57 additions & 0 deletions linux/nikita/Flasko_web_site/test_app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
try:
from main import app
import unittest
import mongomock

except Exception as e:
print("Some Modules are Missing {}".format(e))


class TestApp(unittest.TestCase):
def test_index_status(self):
client = app.test_client(self)
#response_1 = client.get("/home")
response_2 = client.get("/sign-up")
response_3 = client.get("/login")
response_4 = client.get("/logout")

#statuscode_1 = response_1.status_code
statuscode_2 = response_2.status_code
statuscode_3 = response_3.status_code
statuscode_4 = response_4.status_code

#self.assertEqual(statuscode_1, 200)
self.assertEqual(statuscode_2, 200)
self.assertEqual(statuscode_3, 200)
self.assertEqual(statuscode_4, 302)

def test_index_content(self):
client = app.test_client(self)
response = client.get("/login")

self.assertTrue(b'<title>Login</title>' in response.data)
self.assertTrue(b'<h3 align="center">Login</h3>' in response.data)
self.assertTrue(b'<button type="submit" class="btn btn-primary">Login</button>' in response.data)
self.assertTrue(b'<label for="password">Password</label>' in response.data)



class TestMongoDb(unittest.TestCase):
def setUp(self):
self.client = mongomock.MongoClient()
self.db = self.client['test_database']
self.collection = self.db['test_collection']
self.data = ({"email": "test@mail.com", "first_name": "tester", "password1": "testpassword", "password2": "testpassword"})

def test_insert_and_find(self):
self.collection.insert_one(self.data)
doc = self.collection.find_one({"email": "test@mail.com"})

self.assertIsNotNone(doc)
self.assertEqual(doc['email'], "test@mail.com")
self.assertEqual(doc['password1'], "testpassword")
self.assertEqual(doc['password2'], "testpassword")


if __name__ == "__main__":
unittest.main()
Empty file.
36 changes: 36 additions & 0 deletions linux/nikita/Flasko_web_site/testing/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import pytest
from pymongo import MongoClient
from website import create_app

@pytest.fixture(scope="module")
def mongo_client():
client = MongoClient("mongodb://localhost:27017")
yield client
client.close()


@pytest.fixture(scope="module")
def client():
app = create_app()
with app.test_client() as client:
yield client

@pytest.fixture(scope="module")
def test_dbname(mongo_client):
dbname = mongo_client['user_auth']
yield dbname
mongo_client.drop_database("user_auth")


@pytest.fixture(scope="module")
def test_dbname2(mongo_client):
dbname2 = mongo_client['user_note']
yield dbname2
mongo_client.drop_database("user_note")


@pytest.fixture
def math_func(x = 10, y = 5):
return (x + y)


9 changes: 9 additions & 0 deletions linux/nikita/Flasko_web_site/testing/pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[pytest]
python_files=test_project.py
markers =
connection: mark a test as a connection
content: mark a test as a content
db: mark a test as a db
test: mark a test as a test
resgitration: mark a test as a resgitration
login: mark a test as a login
Loading