Some tokens have an expires_at
value as a float (example: 1612807300.1613762
) which causes this line to throw a ValueError: invalid literal for int() with base 10
. This could be solved using int(float(response.get('expires_at')))
(or rounding to not truncate).
Just above that self._expires_at
is made a float:
self._expires_at = time.time() + int(self.expires_in)
The usage of expires_at
is not defined in RFC, so it seems confusion is in the code as well. We can assume it is an int similarly to expires_in
.
Any PR to fix its usage and add unit test to cover this edge-case is welcome.
hey, can i have this issue? I'm just starting with open source, so this will be a good start ig.
hey, can i have this issue? I'm just starting with open source, so this will be a good start ig.
@default-303 go for it!
@ggiill thanks, I did the following changes
- self._expires_at = int(response.get('expires_at'))
+ self._expires_at = round(float(response.get('expires_at')))
and passes all the tests is when i run pytest
But what kinda tests you want me to add ? like a simple typecheck
test something like this -
```
import unittest
import fix ## a sample script i made up for this demo
import time
class TestFix(unittest.TestCase) :
def test_float(self) :
string_time = str(time.time())
self.assertIsInstance(fix.get_time("123345.1222"), int)
def test_int(self) :
string_time = str(round(time.time()))
self.assertIsInstance(fix.get_time("12333"), int)
```
or a full on mock test
?
@ggiill hey, can i get a review ?
lmao its been a month even i forgot abt it.
@ggiill hey, can i get a review ?
lmao its been a month even i forgot abt it.
@default-303 I'm not a maintainer - pinging @JonathanHuot. You probably want to put in a PR for review as well.
Most helpful comment
The usage of
expires_at
is not defined in RFC, so it seems confusion is in the code as well. We can assume it is an int similarly toexpires_in
.Any PR to fix its usage and add unit test to cover this edge-case is welcome.