def test_update_rotating_tables_month_end(self): today = datetime.date.today() next_month = today.month + 1 next_year = today.year if next_month > 12: # pragma: nocover next_month = 1 next_year += 1 tomorrow = datetime.datetime(year=next_year, month=next_month, day=1) AutopushSettings._tomorrow = Mock() AutopushSettings._tomorrow.return_value = tomorrow settings = AutopushSettings(hostname="example.com", resolve_hostname=True) # shift off tomorrow's table. tomorrow_table = sorted(settings.message_tables.keys())[-1] settings.message_tables.pop(tomorrow_table) # Get the deferred back d = settings.update_rotating_tables() def check_tables(result): eq_(len(settings.message_tables), 3) eq_(sorted(settings.message_tables.keys())[-1], tomorrow_table) d.addCallback(check_tables) return d
def test_update_rotating_tables(self): from autopush.db import get_month settings = AutopushSettings(hostname="example.com", resolve_hostname=True) # Erase the tables it has on init, and move current month back one last_month = get_month(-1) settings.current_month = last_month.month settings.message_tables = {} # Create the next month's table, just in case today is the day before # a new month, in which case the lack of keys will cause an error in # update_rotating_tables next_month = get_month(1) settings.message_tables[next_month.month] = None # Get the deferred back e = Deferred() d = settings.update_rotating_tables() def check_tables(result): eq_(len(settings.message_tables), 2) eq_(settings.current_month, get_month().month) d.addCallback(check_tables) d.addBoth(lambda x: e.callback(True)) return e
def test_update_rotating_tables_month_end(self): today = datetime.date.today() next_month = today.month + 1 next_year = today.year if next_month > 12: # pragma: nocover next_month = 1 next_year += 1 tomorrow = datetime.datetime(year=next_year, month=next_month, day=1) AutopushSettings._tomorrow = Mock() AutopushSettings._tomorrow.return_value = tomorrow settings = AutopushSettings( hostname="example.com", resolve_hostname=True) # shift off tomorrow's table. tomorrow_table = sorted(settings.message_tables.keys())[-1] settings.message_tables.pop(tomorrow_table) # Get the deferred back d = settings.update_rotating_tables() def check_tables(result): eq_(len(settings.message_tables), 3) eq_(sorted(settings.message_tables.keys())[-1], tomorrow_table) d.addCallback(check_tables) return d
def test_update_not_needed(self): settings = AutopushSettings( hostname="google.com", resolve_hostname=True) # Erase the tables it has on init, and move current month back one settings.message_tables = {} # Get the deferred back d = settings.update_rotating_tables() def check_tables(result): eq_(len(settings.message_tables), 0) d.addCallback(check_tables) return d
def test_update_not_needed(self): settings = AutopushSettings( hostname="google.com", resolve_hostname=True) # Erase the tables it has on init, and move current month back one settings.message_tables = {} # Get the deferred back d = settings.update_rotating_tables() def check_tables(result): eq_(len(settings.message_tables), 0) d.addCallback(check_tables) return d
def test_update_rotating_tables_month_end(self): """Test that rotating adds next months table This test is intended to ensure that if the next day is a new month, then update_rotating_tables realizes this and add's the new table to the message_tables. A pre-requisite is that today cannot be the last day of the current month. Therefore, we first sub in _tomorrow to ensure it always appears as next month, and then remove the new table create_initial_tables made so we can observe update_rotating_tables add the new one. Note that sorting message table keys to find the last month does *not work* since the month digit is not zero-padded. """ today = datetime.date.today() next_month = today.month + 1 next_year = today.year if next_month > 12: # pragma: nocover next_month = 1 next_year += 1 tomorrow = datetime.datetime(year=next_year, month=next_month, day=1) AutopushSettings._tomorrow = Mock() AutopushSettings._tomorrow.return_value = tomorrow settings = AutopushSettings(hostname="example.com", resolve_hostname=True) # We should have 3 tables, one for next/this/last month eq_(len(settings.message_tables), 3) # Grab next month's table name and remove it next_month = get_rotating_message_table(settings._message_prefix, delta=1) settings.message_tables.pop(next_month.table_name) # Get the deferred back d = settings.update_rotating_tables() def check_tables(result): eq_(len(settings.message_tables), 3) ok_(next_month.table_name in settings.message_tables) d.addCallback(check_tables) return d
def test_update_rotating_tables(self): from autopush.db import get_month settings = AutopushSettings( hostname="example.com", resolve_hostname=True) # Erase the tables it has on init, and move current month back one last_month = get_month(-1) settings.current_month = last_month.month settings.message_tables = {} # Get the deferred back d = settings.update_rotating_tables() def check_tables(result): eq_(len(settings.message_tables), 1) d.addCallback(check_tables) return d
def test_update_rotating_tables(self): from autopush.db import get_month settings = AutopushSettings( hostname="example.com", resolve_hostname=True) # Erase the tables it has on init, and move current month back one last_month = get_month(-1) settings.current_month = last_month.month settings.message_tables = {} # Get the deferred back d = settings.update_rotating_tables() def check_tables(result): eq_(len(settings.message_tables), 1) d.addCallback(check_tables) return d
def test_update_rotating_tables_no_such_table(self, mock_date): from autopush.db import get_month mock_date.date.today.return_value = get_month(-7) settings = AutopushSettings( hostname="google.com", resolve_hostname=True) # Drop the table created during the creation of autopush settings settings.message.table.delete() # Erase the tables it has on init, and move current month back one last_month = get_month(-1) settings.current_month = last_month.month settings.message_tables = {} # Get the deferred back d = settings.update_rotating_tables() def check_tables(result): eq_(len(settings.message_tables), 0) d.addCallback(check_tables) return d