Skip to content

Commit

Permalink
First test. Tests manage_resume method, responsible for Edit/Paste Re…
Browse files Browse the repository at this point in the history
…sume
nicobrenner committed Mar 14, 2024
1 parent 7e4659f commit 5c6822a
Showing 2 changed files with 62 additions and 9 deletions.
13 changes: 4 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -27,21 +27,16 @@ Note: If you want to add another source of job listings, [go to this issue](http
## Updates

* Building in public:
* Was checking out the super cool [ancv](https://github.com/alexpovel/ancv), a tool for building a really cool ascii version of your resume on the terminal! 🤗 (love the joke with the Venn diagram) I wanted to check it out and ended up writing a prompt for their `README` to help with getting some json data out of a resume (which is very similar to what Command Jobs does under the hood as well). Here's the video:
* Just wrote the first test! 😅 And it's in no small part thanks to Agentic's [Glide](https://glide.agenticlabs.com/task/IqHd0RV), which they recently launched ([see announcement here](https://news.ycombinator.com/item?id=39682183)). I was about to switch from ncurses to [python-prompt-toolkit](https://github.com/prompt-toolkit/python-prompt-toolkit), and failing that from python to Go, so I could build Command Jobs using [Bubble Tea](https://github.com/charmbracelet/bubbletea) 🤩😍🤤

* [![Trying ancv](https://cdn.loom.com/sessions/thumbnails/08fe5707eb0e46349ec55be6b2b446aa-with-play.gif)](https://www.loom.com/share/08fe5707eb0e46349ec55be6b2b446aa)
* [![First test with Glide](https://cdn.loom.com/sessions/thumbnails/afd0733ac8dd477cbeea63c8ea6cb363-with-play.gif)](https://www.loom.com/share/afd0733ac8dd477cbeea63c8ea6cb363)

* Check out the amazing [ancv](https://github.com/alexpovel/ancv), a tool for building a really cool ascii version of your resume on the terminal! 🤗 (love the joke with the Venn diagram). Will need to integrate it as a library with Command Jobs

* Tried out [ShellGPT](https://github.com/mattvr/ShellGPT) and made a small PR to highlight its chat interface in the `README`. It's a pretty cool tool to use GPT from the terminal
* Tried out [ShellGPT](https://github.com/mattvr/ShellGPT) and made a small PR to highlight its chat interface in the `README`. It's a pretty cool tool to use GPT from the terminal. Next I want to try coding a bit with [aider](https://github.com/paul-gauthier/aider)

* [![ShellGPT](https://cdn.loom.com/sessions/thumbnails/7f415a53cb404cb0a059a9a065addce8-with-play.gif)](https://www.loom.com/share/7f415a53cb404cb0a059a9a065addce8)


* Finally was able to close out [#12](https://github.com/nicobrenner/commandjobs/issues/12) follow along as I resolve it in the video below

* [![Fixing #12](https://cdn.loom.com/sessions/thumbnails/9ff310f1a7534b2793b3ed366e9859ac-with-play.gif)](https://www.loom.com/share/9ff310f1a7534b2793b3ed366e9859ac)


* Decided to try to build this project as openly as possible, in that spirit, I just recorded a coding session in which I go through the process of trying to resolve a bug ([issue #12](https://github.com/nicobrenner/commandjobs/issues/12)), and finding 3 other bugs instead!

If you are just getting started with coding, it's also a pretty good overview of a basic software project management. In the video I show the whole workflow of not only writing code, but also managing an environment, dealing with errors, documenting the process in Github, managing git and branches, commiting, pushing and merging code, updating documentation (like now), and sharing/promoting
58 changes: 58 additions & 0 deletions src/test_menu.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import os
import unittest
from unittest.mock import patch, MagicMock
from menu import MenuApp

class TestManageResume(unittest.TestCase):
@patch('menu.curses')
@patch('menu.os.getenv')

def test_manage_resume(self, mock_getenv, mock_curses):
# Mock environment variables
mock_getenv.side_effect = lambda x: {'OPENAI_API_KEY': 'test_key', 'BASE_RESUME_PATH': 'temp_base_resume.txt', 'DB_PATH': 'test_db.db', 'HN_START_URL': 'test_url', 'COMMANDJOBS_LISTINGS_PER_BATCH': '10', 'OPENAI_GPT_MODEL': 'gpt-3.5'}.get(x, None)

# Mock stdscr object
mock_stdscr = MagicMock()
mock_curses.initscr.return_value = mock_stdscr
mock_stdscr.getmaxyx.return_value = (200, 200) # Example values for a terminal size

# Mock user input sequence for getch and get_wch
test_resume_text = ''
with open('config/base_resume.sample', 'r') as file:
test_resume_text = file.read()

# This is testing when the resume file doesn't exist
# Remove test resume file, to make sure it doesn't exist
temp_test_resume_path = os.getenv('BASE_RESUME_PATH')
if os.path.exists(temp_test_resume_path):
os.remove(temp_test_resume_path)

# Presses Enter (10) to go into Paste Resume option
mock_stdscr.getch.side_effect = [10]

# And then paste the resume text + Esc ('\x1b'), to save the resume
mock_stdscr.get_wch.side_effect = list(test_resume_text) + ['\x1b']

# Initialize Menu with mocked stdscr and logger
logger = MagicMock()
with patch.object(MenuApp, 'run', return_value=None):
menu = MenuApp(mock_stdscr, logger)

# Simulate calling capture_text_with_scrolling
exit_message = menu.manage_resume(mock_stdscr)

# Verify we got a success message
self.assertEqual(exit_message, f'Resume saved to {temp_test_resume_path}')

# Verify the text was saved to base_resume.txt
with open('base_resume.txt', 'r') as file:
saved_text = file.read()

self.assertEqual(saved_text, test_resume_text)

# Remove temp test resume file
if os.path.exists(temp_test_resume_path):
os.remove(temp_test_resume_path)

if __name__ == '__main__':
unittest.main()

0 comments on commit 5c6822a

Please sign in to comment.