yhttp-dev 3.0.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 yhttp
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,98 @@
1
+ Metadata-Version: 2.1
2
+ Name: yhttp-dev
3
+ Version: 3.0.3
4
+ Summary: yhttp development utilities
5
+ Home-page: https://github.com/yhttp/yhttp-dev
6
+ Author: pylover
7
+ Author-email: vahid.mardani@gmail.com
8
+ Description-Content-Type: text/markdown
9
+ License-File: LICENSE
10
+
11
+ # yhttp-dev
12
+
13
+ A set of development and test fixtures for `yhttp` application development.
14
+
15
+
16
+ ## Contribution
17
+
18
+ ### Dependencies
19
+ Install `postgresql` brefore use of this project.
20
+ ```bash
21
+ apt install postgresql
22
+ ```
23
+
24
+ ### Prepare
25
+
26
+ Create and grant the `postgresql` role with `createdb` permission to
27
+ authenticate the current `unix` user within `postgresql` using the peer
28
+ authentication.
29
+ ```bash
30
+ echo "CREATE USER ${USER} WITH CREATEDB" | sudo -u postgres psql
31
+ # Or
32
+ echo "ALTER USER ${USER} CREATEDB" | sudo -u postgres psql
33
+ ```
34
+
35
+ ### Virtualenv
36
+
37
+ Create virtual environment:
38
+ ```bash
39
+ make venv
40
+ ```
41
+
42
+ Delete virtual environment:
43
+ ```bash
44
+ make venv-delete
45
+ ```
46
+
47
+ Activate the virtual environment:
48
+ ```bash
49
+ source ./activate.sh
50
+ ```
51
+
52
+
53
+ ### Install (editable mode)
54
+ Install this project as editable mode and all other development dependencies:
55
+ ```bash
56
+ make env
57
+ ```
58
+
59
+ # Lint
60
+ ```bash
61
+ make lint
62
+ ```
63
+
64
+
65
+ ### Distribution
66
+ Execute these commands to create `Python`'s standard distribution packages
67
+ at `dist` directory:
68
+ ```bash
69
+ make sdist
70
+ make wheel
71
+ ```
72
+
73
+ Or
74
+ ```bash
75
+ make dist
76
+ ```
77
+ to create both `sdidst` and `wheel` packages.
78
+
79
+
80
+ ### Clean build directory
81
+ Execute:
82
+ ```bash
83
+ make clean
84
+ ```
85
+ to clean-up previous `dist/*` and `build/*` directories.
86
+
87
+
88
+ ### PyPI
89
+
90
+ > **_WARNING:_** Do not do this if you'r not responsible as author and
91
+ > or maintainer of this project.
92
+
93
+ Execute
94
+ ```bash
95
+ make clean
96
+ make pypi
97
+ ```
98
+ to upload `sdists` and `wheel` packages on [PyPI](https://pypi.org).
@@ -0,0 +1,88 @@
1
+ # yhttp-dev
2
+
3
+ A set of development and test fixtures for `yhttp` application development.
4
+
5
+
6
+ ## Contribution
7
+
8
+ ### Dependencies
9
+ Install `postgresql` brefore use of this project.
10
+ ```bash
11
+ apt install postgresql
12
+ ```
13
+
14
+ ### Prepare
15
+
16
+ Create and grant the `postgresql` role with `createdb` permission to
17
+ authenticate the current `unix` user within `postgresql` using the peer
18
+ authentication.
19
+ ```bash
20
+ echo "CREATE USER ${USER} WITH CREATEDB" | sudo -u postgres psql
21
+ # Or
22
+ echo "ALTER USER ${USER} CREATEDB" | sudo -u postgres psql
23
+ ```
24
+
25
+ ### Virtualenv
26
+
27
+ Create virtual environment:
28
+ ```bash
29
+ make venv
30
+ ```
31
+
32
+ Delete virtual environment:
33
+ ```bash
34
+ make venv-delete
35
+ ```
36
+
37
+ Activate the virtual environment:
38
+ ```bash
39
+ source ./activate.sh
40
+ ```
41
+
42
+
43
+ ### Install (editable mode)
44
+ Install this project as editable mode and all other development dependencies:
45
+ ```bash
46
+ make env
47
+ ```
48
+
49
+ # Lint
50
+ ```bash
51
+ make lint
52
+ ```
53
+
54
+
55
+ ### Distribution
56
+ Execute these commands to create `Python`'s standard distribution packages
57
+ at `dist` directory:
58
+ ```bash
59
+ make sdist
60
+ make wheel
61
+ ```
62
+
63
+ Or
64
+ ```bash
65
+ make dist
66
+ ```
67
+ to create both `sdidst` and `wheel` packages.
68
+
69
+
70
+ ### Clean build directory
71
+ Execute:
72
+ ```bash
73
+ make clean
74
+ ```
75
+ to clean-up previous `dist/*` and `build/*` directories.
76
+
77
+
78
+ ### PyPI
79
+
80
+ > **_WARNING:_** Do not do this if you'r not responsible as author and
81
+ > or maintainer of this project.
82
+
83
+ Execute
84
+ ```bash
85
+ make clean
86
+ make pypi
87
+ ```
88
+ to upload `sdists` and `wheel` packages on [PyPI](https://pypi.org).
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,31 @@
1
+ import re
2
+ from os.path import join, dirname
3
+
4
+ from setuptools import setup, find_namespace_packages
5
+
6
+
7
+ # reading package version (same way the sqlalchemy does)
8
+ with open(join(dirname(__file__), 'yhttp/dev', '__init__.py')) as v_file:
9
+ package_version = re.compile('.*__version__ = \'(.*?)\'', re.S).\
10
+ match(v_file.read()).group(1)
11
+
12
+
13
+ dependencies = []
14
+
15
+
16
+ setup(
17
+ name='yhttp-dev',
18
+ version=package_version,
19
+ install_requires=dependencies,
20
+ url='https://github.com/yhttp/yhttp-dev',
21
+ author='pylover',
22
+ author_email='vahid.mardani@gmail.com',
23
+ description='yhttp development utilities',
24
+ long_description=open('README.md').read(),
25
+ long_description_content_type='text/markdown', # This is important!
26
+ packages=find_namespace_packages(
27
+ where='.',
28
+ include=['yhttp.dev'],
29
+ exclude=['tests'],
30
+ )
31
+ )
@@ -0,0 +1 @@
1
+ __version__ = '3.0.3'
@@ -0,0 +1,123 @@
1
+ import os
2
+ import shutil
3
+ import socket
4
+ import tempfile
5
+ import datetime
6
+ from unittest.mock import patch
7
+
8
+ import pytest
9
+
10
+
11
+ @pytest.fixture
12
+ def mockupfs():
13
+ temp_directories = []
14
+
15
+ def create_nodes(root, **kw):
16
+ for k, v in kw.items():
17
+ name = os.path.join(root, k)
18
+
19
+ if isinstance(v, dict):
20
+ os.mkdir(name)
21
+ create_nodes(name, **v)
22
+ continue
23
+
24
+ if hasattr(v, 'read'):
25
+ f = v
26
+ v = f.read()
27
+ f.close()
28
+
29
+ with open(name, 'w') as f:
30
+ f.write(v)
31
+
32
+ def _make_temp_directory(**kw):
33
+ """Structure example: {'a.html': 'Hello', 'b': {}}."""
34
+ root = tempfile.mkdtemp()
35
+ temp_directories.append(root)
36
+ create_nodes(root, **kw)
37
+ return root
38
+
39
+ yield _make_temp_directory
40
+
41
+ for d in temp_directories:
42
+ shutil.rmtree(d)
43
+
44
+
45
+ @pytest.fixture
46
+ def freshdb():
47
+ """ Creates a fresh database for each test.
48
+
49
+ Default configuration is using peer authentication method on
50
+ Postgresql's Unix Domain Socket.
51
+ """
52
+ from yhttp.ext.dbmanager import PostgresqlManager
53
+
54
+ host = os.environ.get('YHTTPDEV_DB_HOST', '')
55
+ user = os.environ.get('YHTTPDEV_DB_USER', '')
56
+ password = os.environ.get('YHTTPDEV_DB_PASS', '')
57
+
58
+ dbname = f'freshdb_{datetime.datetime.now():%Y%m%d%H%M%S}'
59
+ dbmanager = PostgresqlManager(host, 'postgres', user, password)
60
+ dbmanager.create(dbname, dropifexists=True)
61
+ freshurl = f'postgres://{user}:{password}@{host}/{dbname}'
62
+ yield freshurl
63
+ dbmanager.dropifexists(dbname)
64
+
65
+
66
+ @pytest.fixture
67
+ def freetcpport():
68
+ s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
69
+ try:
70
+ s.bind(('localhost', 0))
71
+ return s.getsockname()[1]
72
+ finally:
73
+ s.close()
74
+
75
+
76
+ @pytest.fixture
77
+ def redis():
78
+
79
+ class RedisMock:
80
+ def __init__(self, **kw):
81
+ self.info = kw
82
+ self.maindict = dict()
83
+
84
+ def flushdb(self):
85
+ self.maindict.clear()
86
+
87
+ def srem(self, key, member):
88
+ set_ = self.maindict.setdefault(key, set())
89
+ if member in set_:
90
+ set_.remove(member)
91
+
92
+ def sadd(self, key, member):
93
+ set_ = self.maindict.setdefault(key, set())
94
+ set_.add(member)
95
+
96
+ def sismember(self, key, member):
97
+ if key not in self.maindict:
98
+ return False
99
+
100
+ return member in self.maindict[key]
101
+
102
+ def get(self, key):
103
+ return self.maindict.get(key, '').encode()
104
+
105
+ def set(self, key, value):
106
+ self.maindict[key] = value
107
+
108
+ def setnx(self, key: str, value):
109
+ if not self.maindict.get(key):
110
+ self.set(key, value)
111
+ return 1
112
+ return 0
113
+
114
+ def hset(self, key, field, value):
115
+ hashtable = self.maindict.setdefault(key, {})
116
+ hashtable[field] = value
117
+
118
+ def hget(self, key, field, value):
119
+ hashtable = self.maindict.setdefault(key, {})
120
+ return hashtable[field]
121
+
122
+ with patch('redis.Redis', new=RedisMock) as p:
123
+ yield p
@@ -0,0 +1,98 @@
1
+ Metadata-Version: 2.1
2
+ Name: yhttp-dev
3
+ Version: 3.0.3
4
+ Summary: yhttp development utilities
5
+ Home-page: https://github.com/yhttp/yhttp-dev
6
+ Author: pylover
7
+ Author-email: vahid.mardani@gmail.com
8
+ Description-Content-Type: text/markdown
9
+ License-File: LICENSE
10
+
11
+ # yhttp-dev
12
+
13
+ A set of development and test fixtures for `yhttp` application development.
14
+
15
+
16
+ ## Contribution
17
+
18
+ ### Dependencies
19
+ Install `postgresql` brefore use of this project.
20
+ ```bash
21
+ apt install postgresql
22
+ ```
23
+
24
+ ### Prepare
25
+
26
+ Create and grant the `postgresql` role with `createdb` permission to
27
+ authenticate the current `unix` user within `postgresql` using the peer
28
+ authentication.
29
+ ```bash
30
+ echo "CREATE USER ${USER} WITH CREATEDB" | sudo -u postgres psql
31
+ # Or
32
+ echo "ALTER USER ${USER} CREATEDB" | sudo -u postgres psql
33
+ ```
34
+
35
+ ### Virtualenv
36
+
37
+ Create virtual environment:
38
+ ```bash
39
+ make venv
40
+ ```
41
+
42
+ Delete virtual environment:
43
+ ```bash
44
+ make venv-delete
45
+ ```
46
+
47
+ Activate the virtual environment:
48
+ ```bash
49
+ source ./activate.sh
50
+ ```
51
+
52
+
53
+ ### Install (editable mode)
54
+ Install this project as editable mode and all other development dependencies:
55
+ ```bash
56
+ make env
57
+ ```
58
+
59
+ # Lint
60
+ ```bash
61
+ make lint
62
+ ```
63
+
64
+
65
+ ### Distribution
66
+ Execute these commands to create `Python`'s standard distribution packages
67
+ at `dist` directory:
68
+ ```bash
69
+ make sdist
70
+ make wheel
71
+ ```
72
+
73
+ Or
74
+ ```bash
75
+ make dist
76
+ ```
77
+ to create both `sdidst` and `wheel` packages.
78
+
79
+
80
+ ### Clean build directory
81
+ Execute:
82
+ ```bash
83
+ make clean
84
+ ```
85
+ to clean-up previous `dist/*` and `build/*` directories.
86
+
87
+
88
+ ### PyPI
89
+
90
+ > **_WARNING:_** Do not do this if you'r not responsible as author and
91
+ > or maintainer of this project.
92
+
93
+ Execute
94
+ ```bash
95
+ make clean
96
+ make pypi
97
+ ```
98
+ to upload `sdists` and `wheel` packages on [PyPI](https://pypi.org).
@@ -0,0 +1,9 @@
1
+ LICENSE
2
+ README.md
3
+ setup.py
4
+ yhttp/dev/__init__.py
5
+ yhttp/dev/fixtures.py
6
+ yhttp_dev.egg-info/PKG-INFO
7
+ yhttp_dev.egg-info/SOURCES.txt
8
+ yhttp_dev.egg-info/dependency_links.txt
9
+ yhttp_dev.egg-info/top_level.txt
@@ -0,0 +1 @@
1
+ yhttp