示例#1
0
    def test_sync_git_notes_with_airtable_log_file_contains_responses(self):
        current_month, current_year = util.current_time()
        file_path = f'{current_year}/{current_month}/notes/'

        try:
            self.airtable.create_record('Notes', {
                'Name': 'test_record',
                'Notes': 'new contents',
                'Test': True
            })

            self.git.create_file(file_path,
                                 'test_file.txt',
                                 'initial',
                                 TEST_BRANCH_NAME,
                                 'unit testing',
                                 author='Unit Tester')

            self.sync.sync_current_git_notes_with_airtable(
                'Notes', 'Unit Testing', TEST_BRANCH_NAME)

            files = self.git.get_files(file_path + LOG_FILE_DIRECTORY,
                                       TEST_BRANCH_NAME)

            self.assertIn('test_record', files[0]['data'])
            self.assertIn('test_file', files[0]['data'])
        finally:
            self.git.delete_all_files_in_directory(file_path,
                                                   'unit testing teardown',
                                                   TEST_BRANCH_NAME)
            records = self.airtable.retrieve_all_records_in_view(
                'Notes', 'Unit Testing')
            self.airtable.delete_records('Notes', [r['id'] for r in records])
示例#2
0
    def test_sync_git_notes_with_airtable_new_notes_created_in_git(self):
        current_month, current_year = util.current_time()
        file_path = f'{current_year}/{current_month}/notes/'

        try:
            self.airtable.create_record('Notes', {
                'Name': 'test_record',
                'Notes': 'contents',
                'Test': True
            })

            self.sync.sync_current_git_notes_with_airtable(
                'Notes', 'Unit Testing', TEST_BRANCH_NAME)

            all_files = self.git.get_files(file_path, TEST_BRANCH_NAME)
            files = [
                f for f in all_files
                if f['path'] + '/' != file_path + LOG_FILE_DIRECTORY
            ]

            self.assertEqual(1, len(files))
            self.assertEqual('contents', files[0]['data'])
        finally:
            self.git.delete_all_files_in_directory(file_path,
                                                   'unit testing teardown',
                                                   TEST_BRANCH_NAME)
            records = self.airtable.retrieve_all_records_in_view(
                'Notes', 'Unit Testing')
            self.airtable.delete_records('Notes', [r['id'] for r in records])
示例#3
0
    def test_sync_git_notes_with_airtable_new_git_notes_created_in_at(self):
        current_month, current_year = util.current_time()
        file_path = f'{current_year}/{current_month}/notes/'

        try:
            self.git.create_file(file_path,
                                 'test_record.txt',
                                 'initial',
                                 TEST_BRANCH_NAME,
                                 'unit testing',
                                 author='Unit Tester')

            self.sync.sync_current_git_notes_with_airtable(
                'Notes', 'Unit Testing', TEST_BRANCH_NAME)

            records = self.airtable.retrieve_all_records_in_view(
                'Notes', 'Unit Testing')

            self.assertEqual(1, len(records))
            self.assertEqual('initial', records[0]['fields']['Notes'])
        finally:
            self.git.delete_all_files_in_directory(file_path,
                                                   'unit testing teardown',
                                                   TEST_BRANCH_NAME)
            records = self.airtable.retrieve_all_records_in_view(
                'Notes', 'Unit Testing')
            self.airtable.delete_records('Notes', [r['id'] for r in records])
示例#4
0
    def sync_current_git_notes_with_airtable(self, table_name, table_view,
                                             branch):
        current_month, current_year = util.current_time()
        file_path = f'{current_year}/{current_month}/notes/'

        try:
            self._l(
                self.import_git_directory_to_at_table(file_path, table_name,
                                                      table_view, branch))
            self._l(
                self.commit_at_table_to_git_directory(
                    table_name, table_view, file_path, branch,
                    'Syncing notes with '
                    'airtable'))
        except Exception as e:
            self._l(e)
        finally:
            self._git.create_file(file_path + 'automation-logs/',
                                  'log.txt',
                                  '\n\n'.join(self._log),
                                  branch,
                                  'automation-log',
                                  author=GITHUB_AUTHOR_NAME)
    def test_current_time_has_current_month(self):
        current_month = datetime.now().strftime("%B")
        m, y = util.current_time()

        self.assertEqual(current_month, m)
    def get_todays_past_logs(payload=None, socket=None):
        repo = GitRepo(MCL_REPO_NAME)
        month, _ = current_time()
        day = datetime.today().day
        day_leading = datetime.today().strftime("%d")
        month_leading = datetime.today().strftime("%m")
        year_leading = datetime.today().strftime("%y")

        '2016/personal/{month}/journal/{day}.txt'
        '2017/personal/{month}/journal/{day}.txt'
        '2018/{month}/log/0{day}.txt'  # leading zeroes
        '2019/{month}/log/{year}-{month}-{day}.txt'  # leading zeroes

        logs = []

        try:
            sixteen = repo.get_file('2016/personal/' + month + '/journal/',
                                    str(day) + '.txt')
            logs.append({
                'text': sixteen['data'],
                'path': sixteen['path'],
                'year': 2016
            })
        except Exception:
            logs.append({
                'text': 'No log from 2016.\n\n',
                'path': '',
                'year': 2016
            })

        try:
            seventeen = repo.get_file('2017/personal/' + month + '/journal/',
                                      str(day) + '.txt')
            logs.append({
                'text': seventeen['data'],
                'path': seventeen['path'],
                'year': 2017
            })
        except Exception:
            logs.append({
                'text': 'No log from 2017.\n\n',
                'path': '',
                'year': 2017
            })

        try:
            path, name = '2018/' + month + '/log/', str(day_leading) + '.txt'
            print(path, name)
            eighteen = repo.get_file(path, name)
            logs.append({
                'text': eighteen['data'],
                'path': eighteen['path'],
                'year': 2018
            })
        except Exception:
            logs.append({
                'text': 'No log from 2018.\n\n',
                'path': '',
                'year': 2018
            })

        try:
            path, name = '2019/' + month + '/log/', '2019' + '-' + month_leading + '-' + str(
                day_leading) + '.txt'
            print(path, name)
            nineteen = repo.get_file(path, name)
            logs.append({
                'text': nineteen['data'],
                'path': nineteen['path'],
                'year': 2019
            })
        except Exception as e:
            logs.append({
                'text': 'No log from 2019.\n\n',
                'path': '',
                'year': 2019
            })

        socket.send_json({
            'type': 'GET_TODAYS_PAST_LOGS_SUCCESS',
            'logs': logs
        })