mirror of
https://github.com/simon987/nyaa.git
synced 2025-12-14 15:49:02 +00:00
Fix RFC822 filters + More tests (#257)
* Make rfc822 filters compatible with Windows systems. .strftime() is relative to the system it's being run on. UNIX has '%s' for seconds since the EPOCH, Windows doesn't (ValueError). Solution: use .timestamp() to achieve the same result on both platforms. This also allows us to drop the float() around it, since it returns a float. * Start testing filters * Add placeholders for more tests * Make 'tests' folder a Python package Now you can run tests with just `pytest tests` * Update readme and travis config * Test timesince() * Update and organize .gitignore Deleted: (nothing) Added: Coverage files, .idea\ * Test filter_truthy, category_name * Tests for backend.py * Tests for bencode.py * Move (empty) test_models.py to tests package * Tests for utils.py * Fixes for flattenDict * Change name to `flatten_dict` * `newkey` was assigned but never used * Add a helper class for testing * Show coverage on Travis (only Travis for now...) * Remove IDE * Use correct assert functions * Update README.md
This commit is contained in:
@@ -434,12 +434,12 @@ def view_user(user_name):
|
||||
|
||||
@app.template_filter('rfc822')
|
||||
def _jinja2_filter_rfc822(date, fmt=None):
|
||||
return formatdate(float(date.strftime('%s')))
|
||||
return formatdate(date.timestamp())
|
||||
|
||||
|
||||
@app.template_filter('rfc822_es')
|
||||
def _jinja2_filter_rfc822(datestr, fmt=None):
|
||||
return formatdate(float(datetime.strptime(datestr, '%Y-%m-%dT%H:%M:%S').strftime('%s')))
|
||||
def _jinja2_filter_rfc822_es(datestr, fmt=None):
|
||||
return formatdate(datetime.strptime(datestr, '%Y-%m-%dT%H:%M:%S').timestamp())
|
||||
|
||||
|
||||
def render_rss(label, query, use_elastic, magnet_links=False):
|
||||
|
||||
@@ -35,7 +35,7 @@ def cached_function(f):
|
||||
return decorator
|
||||
|
||||
|
||||
def flattenDict(d, result=None):
|
||||
def flatten_dict(d, result=None):
|
||||
if result is None:
|
||||
result = {}
|
||||
for key in d:
|
||||
@@ -44,7 +44,7 @@ def flattenDict(d, result=None):
|
||||
value1 = {}
|
||||
for keyIn in value:
|
||||
value1["/".join([key, keyIn])] = value[keyIn]
|
||||
flattenDict(value1, result)
|
||||
flatten_dict(value1, result)
|
||||
elif isinstance(value, (list, tuple)):
|
||||
for indexB, element in enumerate(value):
|
||||
if isinstance(element, dict):
|
||||
@@ -52,10 +52,10 @@ def flattenDict(d, result=None):
|
||||
index = 0
|
||||
for keyIn in element:
|
||||
newkey = "/".join([key, keyIn])
|
||||
value1["/".join([key, keyIn])] = value[indexB][keyIn]
|
||||
value1[newkey] = value[indexB][keyIn]
|
||||
index += 1
|
||||
for keyA in value1:
|
||||
flattenDict(value1, result)
|
||||
flatten_dict(value1, result)
|
||||
else:
|
||||
result[key] = value
|
||||
return result
|
||||
|
||||
Reference in New Issue
Block a user