Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Joakim Saario
aurweb
Commits
a65a6060
Commit
a65a6060
authored
Jun 03, 2021
by
Kevin Morris
Browse files
add ApiRateLimit SQLAlchemy ORM model
Signed-off-by:
Kevin Morris
<
kevr@0cost.org
>
parent
2b83d2fb
Changes
2
Hide whitespace changes
Inline
Side-by-side
aurweb/models/api_rate_limit.py
0 → 100644
View file @
a65a6060
from
sqlalchemy.orm
import
mapper
from
aurweb.schema
import
ApiRateLimit
as
_ApiRateLimit
class
ApiRateLimit
:
def
__init__
(
self
,
IP
:
str
=
None
,
Requests
:
int
=
None
,
WindowStart
:
int
=
None
):
self
.
IP
=
IP
self
.
Requests
=
Requests
self
.
WindowStart
=
WindowStart
mapper
(
ApiRateLimit
,
_ApiRateLimit
,
primary_key
=
[
_ApiRateLimit
.
c
.
IP
])
test/test_api_rate_limit.py
0 → 100644
View file @
a65a6060
import
pytest
from
sqlalchemy.exc
import
IntegrityError
from
aurweb.db
import
create
from
aurweb.models.api_rate_limit
import
ApiRateLimit
from
aurweb.testing
import
setup_test_db
@
pytest
.
fixture
(
autouse
=
True
)
def
setup
():
setup_test_db
(
"ApiRateLimit"
)
def
test_api_rate_key_creation
():
rate
=
create
(
ApiRateLimit
,
IP
=
"127.0.0.1"
,
Requests
=
10
,
WindowStart
=
1
)
assert
rate
.
IP
==
"127.0.0.1"
assert
rate
.
Requests
==
10
assert
rate
.
WindowStart
==
1
def
test_api_rate_key_null_ip_raises_exception
():
from
aurweb.db
import
session
with
pytest
.
raises
(
IntegrityError
):
create
(
ApiRateLimit
,
Requests
=
10
,
WindowStart
=
1
)
session
.
rollback
()
def
test_api_rate_key_null_requests_raises_exception
():
from
aurweb.db
import
session
with
pytest
.
raises
(
IntegrityError
):
create
(
ApiRateLimit
,
IP
=
"127.0.0.1"
,
WindowStart
=
1
)
session
.
rollback
()
def
test_api_rate_key_null_window_start_raises_exception
():
from
aurweb.db
import
session
with
pytest
.
raises
(
IntegrityError
):
create
(
ApiRateLimit
,
IP
=
"127.0.0.1"
,
WindowStart
=
1
)
session
.
rollback
()
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment