Skip to content

Instantly share code, notes, and snippets.

View colinfwren's full-sized avatar

Colin Wren colinfwren

View GitHub Profile
@colinfwren
colinfwren / sample-test.py
Created February 10, 2018 22:04
Patching Odoo Registries - Sample Test
from openerp.tests.common import TransactionCase
class TestTheFoo(TransactionCase):
def setUp(self):
super(TestTheFoo, self).setUp()
self.module_reg = self.registry('my.odoo.module')
def test_01_call_a_module_method(self):
test_foo = self.module_reg.get_foo() # should return 'foo'
@colinfwren
colinfwren / setup-sample.py
Created February 10, 2018 22:06
Patching Odoo Registries - Setup Sample
def setUp(self):
cr, uid = self.cr, self.uid
super(TestTheFoo, self).setUp()
self.module_reg = self.registry('my.odoo.module')
self.user_reg = self.registry('res.user')
test_uid = self.user_reg.search(cr, uid, [['name', '=', 'Test User']])
if not test_uid
raise ValueError('Test User not found in database')
def test_01_call_a_module_method(self):
@colinfwren
colinfwren / patching-sample.py
Created February 10, 2018 22:07
Patching Odoo Registries - Patching
def res_user_read_mock(*args, **kwargs):
return [{'name': 'Test User'}]
def setUp(self):
super(TestTheFoo, self).setUp()
self.module_reg = self.registry('my.odoo.module')
self.user_reg = self.registry('res.user')
self.user_reg._patch_method('read', res_user_read_mock)
def tearDown(self):
@colinfwren
colinfwren / return-origin.py
Created February 10, 2018 22:08
Patching Odoo Registries - Returning Original Method in patch
def res_user_read_mock(*args, **kwargs):
return res_user_read_mock.origin(*args, **kwargs)
@colinfwren
colinfwren / args-in-patch.py
Created February 10, 2018 22:12
Patching Odoo Registries - Using Args and Kwargs
# v7 call Argument mapping = [class, cursor, user id, record id, fields to get]
def res_user_read_mock(*args, **kwargs):
# In this case we want record id or args[3]
if args[3] == 1:
return [{'name': 'Test User'}]
elif args[3] == 2:
return [{'name': 'Another User'}]
else:
return []
@colinfwren
colinfwren / patching-mocks.py
Created February 10, 2018 22:14
Patching Odoo Registries - Mocks
class TestTheFoo(TransactionCase):
calls_to_mock = []
def setUp():
super(TestTheFoo, self).setUp()
self.calls_to_mock = []
def res_user_read_mock(*args, **kwargs):
self.calls_to_mock.append({'args': args, 'kwargs': kwargs})
if len(self.calls_to_mock) > 2
@colinfwren
colinfwren / patching-run-times.md
Created February 10, 2018 22:15
Patching Odoo Registries - Run Times

Run One

Testing method Time to run test suite
SetUp 0.354s
Demo Data 0.025s
Patch Method 0.002s

Run Two

| Testing method | Time to run test suite |

@colinfwren
colinfwren / hardest-parts.md
Created February 10, 2018 22:39
Survey results - Hardest Part of the Process
Answer Score
Finding jobs that meet my needs 8
The interview 7
Dealing with tests/assignments set by potential employer 5
Filling out multi-page application forms 4
Dealing with recruiters 3
Getting and understanding feedback 3
Keeping track of the people I talk to at companies I apply for 3
Keeping my CV up to date 2
@colinfwren
colinfwren / sql_solutions.sql
Created February 23, 2018 00:34
SQL Technical Test Solutions
--Please note - I'm using PostgreSQL for these examples
-- Question 1: Write a query that returns the total number of api_requests where the status code was 200
SELECT
count(status_code)
FROM api_requests
WHERE status_code = 200;
-- Question 2: Write a query that gives the count, and average response_ms for every api_endpoint. Sorted by the average
-- I assumed here that ordering we'd be wanting to highlight the highest average
SELECT
@colinfwren
colinfwren / events.json
Created August 21, 2018 19:37
Example events
[
{
"startDate": "2018-08-01T21:00:00",
"endDate": "2018-09-01T21:00:00",
"name": "Raikou Research Breakthrough"
},
{
"startDate": "2018-08-09T01:00:00",
"endDate": "2018-08-23T01:00:00",
"name": "Nest Migration #59"