Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Pole-Web
Website
Commits
6a72750c
Commit
6a72750c
authored
Apr 26, 2022
by
Thomas VOISIN
Browse files
Black reformat on enibar urls.py, tests.py and views.py
parent
1b8e0807
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Pipfile
View file @
6a72750c
...
...
@@ -12,6 +12,7 @@ types-Markdown = "*"
types-freezegun
=
"*"
types-redis
=
"*"
types-requests
=
"*"
black
=
"*"
[packages]
Markdown
=
"*"
...
...
@@ -26,7 +27,6 @@ psycopg2-binary = "*"
redis
=
"*"
requests
=
"*"
[scripts]
test
=
"./test.sh"
create_recurrent_events
=
"./manage.py create_recurrent_events"
Pipfile.lock
View file @
6a72750c
This diff is collapsed.
Click to expand it.
enibar/tests.py
View file @
6a72750c
...
...
@@ -60,7 +60,9 @@ class TestEnibarImport(TestCase):
Note
.
objects
.
create
(
foreign_id
=
2
,
nickname
=
"toto"
,
mail
=
"coucou@test.fr"
,
note
=
Decimal
(
"10"
)
)
response
=
self
.
client
.
delete
(
"/enibar/api/note"
,
'{"token": "changeme", "id": 2}'
)
response
=
self
.
client
.
delete
(
"/enibar/api/note"
,
'{"token": "changeme", "id": 2}'
)
self
.
assertEqual
(
response
.
status_code
,
200
)
with
self
.
assertRaises
(
Note
.
DoesNotExist
):
Note
.
objects
.
get
(
foreign_id
=
2
)
...
...
@@ -187,8 +189,13 @@ class TestHistoryByUser(TestCase):
self
.
assertNotContains
(
response
,
self
.
note_autre
.
nickname
)
self
.
assertIsInstance
(
json
.
loads
(
response
.
content
),
list
)
self
.
assertEqual
(
len
(
json
.
loads
(
response
.
content
)),
120
)
assert
all
(
isinstance
(
value
,
dict
)
and
all
(
field
.
name
in
value
.
keys
()
for
field
in
HistoryLine
.
_meta
.
get_fields
())
for
value
in
json
.
loads
(
response
.
content
))
assert
all
(
isinstance
(
value
,
dict
)
and
all
(
field
.
name
in
value
.
keys
()
for
field
in
HistoryLine
.
_meta
.
get_fields
()
)
for
value
in
json
.
loads
(
response
.
content
)
)
self
.
assertContains
(
response
,
self
.
note1
.
nickname
)
self
.
assertContains
(
response
,
self
.
note2
.
nickname
)
...
...
@@ -370,6 +377,8 @@ class TestHistoryView(TestCase):
class
TestGetPhotoPaths
(
TestCase
):
def
test_last_update_in_dst_change
(
self
):
"""Regression test for #43"""
resp
=
self
.
client
.
get
(
"/enibar/api/photos?last_updated=2020-10-25T02%3A00%3A01"
)
resp
=
self
.
client
.
get
(
"/enibar/api/photos?last_updated=2020-10-25T02%3A00%3A01"
)
self
.
assertEqual
(
resp
.
status_code
,
200
)
enibar/urls.py
View file @
6a72750c
...
...
@@ -11,10 +11,19 @@ urlpatterns = [
views
.
show_history
,
name
=
"show_history"
,
),
path
(
'api/'
,
include
([
path
(
"note"
,
views
.
request_note
,
name
=
"request_note"
),
path
(
"photos"
,
views
.
get_photo_paths
,
name
=
"photo_paths"
),
path
(
"history"
,
views
.
request_history
,
name
=
"request_history"
),
path
(
"history-by-user"
,
views
.
get_history_by_user
,
name
=
"get_history_by_user"
)
])),
path
(
"api/"
,
include
(
[
path
(
"note"
,
views
.
request_note
,
name
=
"request_note"
),
path
(
"photos"
,
views
.
get_photo_paths
,
name
=
"photo_paths"
),
path
(
"history"
,
views
.
request_history
,
name
=
"request_history"
),
path
(
"history-by-user"
,
views
.
get_history_by_user
,
name
=
"get_history_by_user"
,
),
]
),
),
]
enibar/views.py
View file @
6a72750c
...
...
@@ -99,7 +99,9 @@ request_history = _create_view(HistoryLine)
@
login_required
def
show_history
(
request
:
HttpRequest
,
page
,
nickname
:
Optional
[
str
]
=
None
)
->
HttpResponse
:
def
show_history
(
request
:
HttpRequest
,
page
,
nickname
:
Optional
[
str
]
=
None
)
->
HttpResponse
:
page
=
page
or
1
notes
=
Note
.
objects
.
filter
(
mail
=
request
.
user
.
email
)
# type: ignore[union-attr] # login is required
personal_notes
=
set
(
notes
)
...
...
@@ -133,8 +135,9 @@ def get_photo_paths(request: HttpRequest) -> JsonResponse:
last_updated_in
=
request
.
GET
.
get
(
"last_updated"
)
if
last_updated_in
is
not
None
:
last_updated
=
datetime
.
datetime
.
strptime
(
last_updated_in
,
"%Y-%m-%dT%H:%M:%S"
)
last_updated
=
timezone
.
make_aware
(
last_updated
,
timezone
=
None
,
is_dst
=
True
)
# Make TZ aware avoiding DST by fetching more
last_updated
=
timezone
.
make_aware
(
last_updated
,
timezone
=
None
,
is_dst
=
True
)
# Make TZ aware avoiding DST by fetching more
users
=
User
.
objects
.
filter
(
profile__last_updated__gt
=
last_updated
).
select_related
(
"profile"
)
...
...
@@ -159,8 +162,11 @@ def get_history_by_user(request: HttpRequest) -> JsonResponse:
raise
Http404
result
:
List
[
dict
]
=
[]
for
note
in
notes
:
result
.
extend
(
HistoryLine
.
objects
.
filter
(
note_id
=
note
.
foreign_id
)
.
annotate
(
nick
=
Value
(
note
.
nickname
,
output_field
=
CharField
())).
values
())
result
.
extend
(
HistoryLine
.
objects
.
filter
(
note_id
=
note
.
foreign_id
)
.
annotate
(
nick
=
Value
(
note
.
nickname
,
output_field
=
CharField
()))
.
values
()
)
return
JsonResponse
(
result
,
safe
=
False
)
except
Exception
:
raise
Http404
from
None
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