Exemplo n.º 1
0
    def test_update_to_registration_updated_date(self):
        def mock_input():
            return 'y'
        def mock_get_commit(unused_self, unused_sha):
            return github.Commit.Commit(
                requester='', headers='',
                attributes={
                    'commit': {'committer': {'date': '2016-11-15T3:41:01Z'}}},
                completed='')
        input_swap = self.swap(python_utils, 'INPUT', mock_input)
        get_commit_swap = self.swap(
            github.Repository.Repository, 'get_commit', mock_get_commit)

        temp_feconf_path = tempfile.NamedTemporaryFile().name
        feconf_text = (
            '# When the site terms were last updated, in UTC.\n'
            'REGISTRATION_PAGE_LAST_UPDATED_UTC = '
            'datetime.datetime(2015, 10, 14, 2, 40, 0)\n'
            '# Format of string for dashboard statistics logs.\n'
            '# NOTE TO DEVELOPERS: This format should not be changed, '
            'since it is used in\n'
            '# the existing storage models for UserStatsModel.\n'
            'DASHBOARD_STATS_DATETIME_STRING_FORMAT = \'%Y-%m-%d\'\n')
        expected_feconf_text = feconf_text.replace(
            'datetime.datetime(2015, 10, 14, 2, 40, 0)',
            'datetime.datetime(2016, 11, 15, 3, 41, 1)')
        with python_utils.open_file(temp_feconf_path, 'w') as f:
            f.write(feconf_text)

        with self.getpass_swap, self.get_org_swap, self.get_repo_swap:
            with self.open_tab_swap, input_swap, get_commit_swap:
                update_configs.check_updates_to_terms_of_service(
                    temp_feconf_path, 'test-token')
        with python_utils.open_file(temp_feconf_path, 'r') as f:
            self.assertEqual(f.read(), expected_feconf_text)
Exemplo n.º 2
0
 def test_invalid_user_input(self):
     print_msgs = []
     def mock_input():
         if print_msgs:
             return 'n'
         else:
             return 'invalid'
     def mock_print(msg):
         if 'Invalid Input' in msg:
             print_msgs.append(msg)
     input_swap = self.swap(python_utils, 'INPUT', mock_input)
     print_swap = self.swap(python_utils, 'PRINT', mock_print)
     with self.getpass_swap, self.get_org_swap, self.get_repo_swap:
         with self.open_tab_swap, input_swap, print_swap:
             update_configs.check_updates_to_terms_of_service('test-token')
     self.assertEqual(
         print_msgs, ['Invalid Input: invalid. Please enter yes or no.'])
Exemplo n.º 3
0
 def test_invalid_user_input(self):
     print_msgs = []
     def mock_input():
         if print_msgs:
             return 'n'
         else:
             return 'invalid'
     def mock_print(msg):
         if 'Invalid Input' in msg:
             print_msgs.append(msg)
     input_swap = self.swap(builtins, 'input', mock_input)
     print_swap = self.swap(builtins, 'print', mock_print)
     with self.getpass_swap, self.get_org_swap, self.get_repo_swap:
         with self.open_tab_swap, input_swap, print_swap:
             update_configs.check_updates_to_terms_of_service(
                 MOCK_LOCAL_FECONF_PATH, 'test-token')
     self.assertEqual(
         print_msgs, ['Invalid Input: invalid. Please enter yes or no.'])