Last active
August 29, 2015 14:04
-
-
Save fabiobatalha/b6d03158da215fe65d89 to your computer and use it in GitHub Desktop.
Check delayed content
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python2.7 | |
# coding: utf-8 | |
import unittest | |
import datetime | |
def is_delayed(ratio, periodicity, last_publication_date): | |
""" | |
ratio (integer): numero de fasciculos para considerar o atraso. | |
periodicity (integer): periodicidade do periodico em meses 1, 2, 3, 4, 5..... | |
last_publication_date YYYY-MM-DD: Data iso valida ex: 2014-02-01 | |
return: | |
Boolean | |
""" | |
per = 30 * periodicity | |
delay_range = ratio * per | |
delay_delta = datetime.timedelta(delay_range) | |
delay_limit = datetime.datetime.now()-delay_delta | |
last_publication_date = datetime.datetime.strptime(last_publication_date, "%Y-%m-%d") | |
if last_publication_date < delay_limit: | |
return True | |
return False | |
class TestCases(unittest.TestCase): | |
def test_is_delayed_True(self): | |
result = is_delayed(1, 3, '2014-06-02') | |
self.assertEqual(result, False) | |
def test_is_delayed_False(self): | |
result = is_delayed(1, 2, '2014-06-01') | |
self.assertEqual(result, True) | |
if __name__ == '__main__': | |
unittest.main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment