yhttp-dev 3.0.3__py3-none-any.whl

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.
yhttp/dev/__init__.py ADDED
@@ -0,0 +1 @@
1
+ __version__ = '3.0.3'
yhttp/dev/fixtures.py ADDED
@@ -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,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,7 @@
1
+ yhttp/dev/__init__.py,sha256=f3vNGrLTgOxbJH5qxemKyIWl-KEbqvz66qZKwIM1iw8,22
2
+ yhttp/dev/fixtures.py,sha256=uX3_Wc1DKJKRJufoygOQlTF9iTA3ohIgAWUbxppT7gM,3142
3
+ yhttp_dev-3.0.3.dist-info/LICENSE,sha256=34cubtKBXSOdq-BW4NortbFPSBGds_mDyYrQQTG4NLw,1062
4
+ yhttp_dev-3.0.3.dist-info/METADATA,sha256=bU0UC3l_AKmuBOIPV9QNJLRkvsmmSYL87ArEaUthazc,1697
5
+ yhttp_dev-3.0.3.dist-info/WHEEL,sha256=HiCZjzuy6Dw0hdX5R3LCFPDmFS4BWl8H-8W39XfmgX4,91
6
+ yhttp_dev-3.0.3.dist-info/top_level.txt,sha256=efaJ4DfUOs7MO3pjIEyRhnQASGVyD6vH-SL3ogQxkeU,6
7
+ yhttp_dev-3.0.3.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (72.2.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ yhttp