Esempio n. 1
0
def view_entries(bycat=None, target=None, datelast=None):
    """View entries."""
    if datelast:
        viewer = CardCatalog().load_entries(bycat=bycat,
                                            target=target,
                                            datelast=datelast)
    else:
        viewer = CardCatalog().load_entries(bycat=bycat, target=target)
    if viewer:
        view = len(viewer)
        view_num = 0
        while view_num < view:
            clear_screen()
            vts = viewer[view_num]['timestamp'].strftime('%A %B %d, %Y')
            print(vts)
            print('=' * len(vts))
            print("Recorded by: " + viewer[view_num]['user_name'])
            print("Task: " + viewer[view_num]['task_name'])
            print("Minutes: " + str(viewer[view_num]['task_minutes']))
            print("Additional Notes: " + viewer[view_num]['task_notes'])
            print('\n\n' + '=' * len(vts))
            print('N) Next entry')
            print('p) Previous entry')
            print('e) Edit entry')
            print('d) Delete entry')
            print('q) Return to menu')

            next_action = input('Action: \n[N/p/e/d/q]: ').lower().strip()
            if next_action == 'q':
                break
                # Break exits view loop, returns to main menu.
            elif next_action == 'e':
                edit_entry(viewer[view_num])
                break
            elif next_action == 'd':
                if input('Delete entry. Are you sure? y/N ').lower() == 'y':
                    CardCatalog().delete_entry(viewer[view_num])
                    break
                else:
                    view_num += 0
            elif next_action == 'p':
                if view_num > 0:
                    view_num -= 1
                else:
                    input("Can't go further than that. (Enter to continue.)")
            else:
                if view_num < view - 1:
                    view_num += 1
                else:
                    input("That's all we could find. (Enter to continue.)")
    else:
        print('No entries found.')
        press_enter()
        return
Esempio n. 2
0
def by_date():
    """Search by date."""
    clear_screen()
    if input('''
Please choose:
[L] For a list of dates with tasks entered.
[r] To type in a specific range of dates.
> ''').lower() == 'r':
        timeloop = 1
        while timeloop:
            clear_screen()
            target_range = input('''
Please enter date range in following format:
"MM/DD/YYYY-MM/DD/YYYY"
Range will find from midnight of first date, to midnight of the last date.
So, if you want to search New Year's Day 2018, type "01/01/2018-01/02/2018"
> ''')
            if CardCatalog().d_range_check(target_range):
                targets = target_range.split(sep='-')
                dateobj = CardCatalog().date_check(targets[0])
                dateobj1 = CardCatalog().date_check(targets[1])
                view_entries(bycat='date', target=dateobj, datelast=dateobj1)
                return
            else:
                invalid_input('date range string')
    else:
        clear_screen()
        datelog = CardCatalog().generate_datelog()
        if datelog:
            d_num = 0
            for fenix in datelog:
                print('{}: {}'.format(d_num, fenix.strftime("%A %B %d, %Y")))
                print('-' * 50)
                d_num += 1
            listloop = 1
            while listloop:
                snackfruit = input(
                    "Please type a number to select a date. \n> ")
                if CardCatalog().minute_check(snackfruit):
                    if int(snackfruit) >= 0 and int(snackfruit) < len(datelog):
                        view_entries(bycat='date',
                                     target=datelog[int(snackfruit)])
                        clear_screen()
                        return
                invalid_input('date selection')
        print('No entries found.')
        press_enter()
        return
Esempio n. 3
0
 def test_save_new_bad(self):
     sav = CardCatalog().save_new(
              43,
              22,
              'seventy-eight',
              False)
     self.assertFalse(sav)
Esempio n. 4
0
 def test_save_new_good(self):
     sav = CardCatalog().save_new(
              'Steven Universe',
              'Containing the Cluster',
              11,
              "I got you. You got this. We've all got eachother.")
     self.assertTrue(sav)
Esempio n. 5
0
 def test_acquire_target_dne(self):
     entry_dict = {'timestamp': datetime.datetime(2000, 1, 1, 1),
                   'user_name': 'Black Gold',
                   'task_name': 'Nameless',
                   'task_minutes': 999999,
                   'task_notes': "idk"}
     self.assertFalse(CardCatalog().acquire_target(entry_dict))
Esempio n. 6
0
    def test_edit_entry_bad_then_good(self):
        with unittest.mock.patch('builtins.input',
                                 side_effect=['Spam',
                                              'fourtwo',
                                              '',
                                              '42',
                                              'Bey Day',
                                              '',
                                              '11/11/2011',
                                              'n',
                                              'y',
                                              '']):
            Entry.create(
                timestamp=datetime.datetime(2018, 1, 1, 1),
                user_name='Yellow Diamond',
                task_name='Stomp RQ',
                task_minutes=1,
                task_notes="mystery"
            )
            e_dict = {
                'user_name': 'Yellow Diamond',
                'task_name': 'Stomp RQ',
                'task_minutes': 1,
                'task_notes': "mystery",
                'timestamp': datetime.datetime(2018, 1, 1, 1)
            }

            self.assertIsNone(wlui.edit_entry(e_dict))
            CardCatalog().delete_entry(
                {'user_name': 'Yellow Diamond',
                 'task_name': 'Spam',
                 'task_minutes': 42,
                 'task_notes': "mystery",
                 'timestamp': datetime.datetime(2011, 11, 11, 1)}
            )
Esempio n. 7
0
 def test_delete_entry_dne(self):
     tde = CardCatalog().delete_entry(
         {'user_name': 'Rose-Quartz',
          'task_name': 'Defying Pink Diamond',
          'task_minutes': 9999999,
          'timestamp': datetime.datetime(2017, 5, 5, 5)}
     )
     self.assertFalse(tde)
Esempio n. 8
0
 def test_delete_entry(self):
     tde = CardCatalog().delete_entry(
         {'user_name': 'White Diamond',
          'task_name': 'Unknown',
          'task_minutes': 1200,
          'task_notes': "mystery",
          'timestamp': datetime.datetime(2018, 7, 2, 8)})
     self.assertTrue(tde)
Esempio n. 9
0
 def tearDown(self):
     CardCatalog().delete_entry(
         {'user_name': 'White Diamond',
          'task_name': 'Unknown',
          'task_minutes': 1200,
          'task_notes': "mystery",
          'timestamp': datetime.datetime(2018, 7, 2, 8)}
     )
Esempio n. 10
0
def add_entry():
    """Add new entry to work log."""
    clear_screen()
    name_adding = 1
    while name_adding:
        add_name = input('Please enter full name.\n> ')
        if CardCatalog().name_check(add_name):
            break
        else:
            invalid_input('first and last name string')
            continue

    task_adding = 1
    while task_adding:
        add_task = input('What task did you work on?\n> ')
        if isinstance(add_task, str):
            break
        else:
            invalid_input('task string somehow')
            continue

    minutes_adding = 1
    while minutes_adding:
        add_minutes = input('How many minutes were spent?\n> ')
        if CardCatalog().minute_check(add_minutes):
            break
        else:
            invalid_input('integer')
            continue

    add_notes = ''
    if input('Any notes? [y/N]').upper().strip() == "Y":
        print('Type notes here. Press "ctrl+d" when finished.')
        add_notes = sys.stdin.read().strip()

    clear_screen()
    print('Name: ' + add_name)
    print('Task: ' + add_task)
    print('Minutes: ' + add_minutes)
    print(CardCatalog().notes_out(add_notes))
    if input('Save entry? [Y/n]\n> ').lower() != 'n':
        CardCatalog().save_new(add_name, add_task, add_minutes, add_notes)
        press_enter()
        return
Esempio n. 11
0
def by_minutes():
    """Search by minutes spent on task."""
    clear_screen()
    minloop = 1
    while minloop:
        minnum = input('Please type an integer of minutes.')
        if CardCatalog().minute_check(minnum):
            view_entries(bycat='minutes', target=minnum)
            return
        else:
            invalid_input('integer')
            clear_screen()
Esempio n. 12
0
 def test_save_edit_good(self):
     e_dict = {'timestamp': datetime.datetime(2018, 7, 2, 8),
               'user_name': 'White Diamond',
               'task_name': 'Unknown',
               'task_minutes': 1200,
               'task_notes': "mystery"}
     updater = CardCatalog().acquire_target(e_dict)
     updater.task_name = 'Reknowned'
     updater.task_minutes = 21
     updater.task_notes = 'solved'
     updater.timestamp = datetime.datetime(2015, 6, 2, 8)
     saver = CardCatalog().save_edits(updater)
     self.assertTrue(saver)
Esempio n. 13
0
 def test_acquire_target(self):
     entry_dict = {'timestamp': datetime.datetime(2018, 7, 2, 8),
                   'user_name': 'White Diamond',
                   'task_name': 'Unknown',
                   'task_minutes': 1200,
                   'task_notes': "mystery"}
     spam = CardCatalog().acquire_target(entry_dict)
     egg = Entry.get(
             Entry.user_name == 'White Diamond',
             Entry.task_name == 'Unknown',
             Entry.task_minutes == 1200,
             Entry.timestamp == datetime.datetime(2018, 7, 2, 8),
             Entry.task_notes == "mystery"
     )
     self.assertEqual(spam, egg)
Esempio n. 14
0
 def test_by_staff_fol(self, mock_ve):
     with unittest.mock.patch('builtins.input',
                              side_effect=['n',
                                           'Yellow',
                                           0]):
         Entry.create(
             timestamp=datetime.datetime(2018, 1, 1, 1),
             user_name='Yellow Diamond',
             task_name='Stomp RQ',
             task_minutes=1,
             task_notes="mystery"
         )
         wlui.by_staff()
         mock_ve.assert_called_with(bycat='name', target='Yellow Diamond')
         CardCatalog().delete_entry(
             {'user_name': 'Yellow Diamond',
              'task_name': 'Stomp RQ',
              'task_minutes': 1,
              'task_notes': "mystery",
              'timestamp': datetime.datetime(2018, 1, 1, 1)}
         )
Esempio n. 15
0
 def test_notes_out_else(self):
     self.assertEqual(CardCatalog().notes_out('notes'), 'Notes: notes')
Esempio n. 16
0
 def test_minute_check_bad(self):
     self.assertFalse(CardCatalog().minute_check('ten'))
Esempio n. 17
0
 def test_minute_check_good(self):
     self.assertTrue(CardCatalog().minute_check('10'))
Esempio n. 18
0
 def test_date_check_bad(self):
     feebird = CardCatalog().date_check('15/35/99999')
     self.assertFalse(feebird)
Esempio n. 19
0
 def test_date_check(self):
     feebird = CardCatalog().date_check('01/01/2018')
     self.assertIsInstance(feebird, datetime.datetime)
Esempio n. 20
0
 def test_load_entries_byname(self):
     loaded = CardCatalog().load_entries(
             bycat='name', target='White Diamond')
     self.assertIsInstance(loaded, list)
Esempio n. 21
0
 def test_generate_roster(self):
     stafflist = CardCatalog().generate_roster()
     self.assertIsInstance(stafflist, list)
Esempio n. 22
0
 def test_save_edit_error(self):
     saver = CardCatalog().save_edits('Not an entry')
     self.assertFalse(saver)
Esempio n. 23
0
 def test_load_entries(self):
     loaded = CardCatalog().load_entries()
     self.assertIsInstance(loaded, list)
Esempio n. 24
0
 def test_load_entries_bymin(self):
     loaded = CardCatalog().load_entries(
             bycat='minutes', target=1200)
     self.assertIsInstance(loaded, list)
Esempio n. 25
0
 def test_load_entries_byterm(self):
     loaded = CardCatalog().load_entries(
             bycat='term', target='mystery')
     self.assertIsInstance(loaded, list)
Esempio n. 26
0
 def test_notes_out_empty(self):
     self.assertIsNone(CardCatalog().notes_out(''))
Esempio n. 27
0
 def test_notes_out_elif(self):
     stone = '-' * 50
     self.assertEqual(CardCatalog().notes_out(stone),
                      'Notes: ' + stone + '. . . ')
Esempio n. 28
0
 def test_name_check_good(self):
     self.assertTrue(CardCatalog().name_check('Steven Universe'))
Esempio n. 29
0
 def test_generate_datelog(self):
     cale = CardCatalog().generate_roster()
     self.assertIsInstance(cale, list)
Esempio n. 30
0
 def test_name_check_bad(self):
     self.assertFalse(CardCatalog().name_check('Beyonce'))