Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
common_helper_encoder
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
fact-depend
common_helper_encoder
Commits
c62fa0d0
Commit
c62fa0d0
authored
Apr 29, 2016
by
Peter Weidenbach
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
byte conversion added
parent
3c7a1309
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
0 deletions
+20
-0
json_encoder.py
common_helper_encoder/json_encoder.py
+3
-0
__init__.py
tests/__init__.py
+0
-0
test_json_encoder.py
tests/test_json_encoder.py
+17
-0
No files found.
common_helper_encoder/json_encoder.py
View file @
c62fa0d0
import
json
import
datetime
from
base64
import
standard_b64encode
class
ReportEncoder
(
json
.
JSONEncoder
):
def
default
(
self
,
obj
):
if
isinstance
(
obj
,
datetime
.
datetime
):
return
obj
.
isoformat
()
elif
isinstance
(
obj
,
bytes
):
return
standard_b64encode
(
obj
)
.
decode
(
'utf-8'
)
return
json
.
JSONEncoder
.
default
(
self
,
obj
)
tests/__init__.py
0 → 100644
View file @
c62fa0d0
tests/test_json_encoder.py
0 → 100644
View file @
c62fa0d0
import
unittest
from
common_helper_encoder.json_encoder
import
ReportEncoder
class
Test_json_encoder
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
encoder
=
ReportEncoder
()
def
test_byte_encoding
(
self
):
input_data
=
b
'TEST'
result
=
self
.
encoder
.
default
(
input_data
)
self
.
assertEqual
(
result
,
"VEVTVA=="
,
"base64 encoding not correct"
)
if
__name__
==
"__main__"
:
unittest
.
main
()
Write
Preview
Markdown
is supported
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