Skip to content

Commit

Permalink
issue #142 - more acceptance test optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
jantman committed Nov 2, 2017
1 parent 1fa9f90 commit 3772dd9
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 177 deletions.
38 changes: 17 additions & 21 deletions biweeklybudget/tests/acceptance/flaskapp/views/test_fuel.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,9 @@ def test_05_vehicles(self, base_url, selenium):
@pytest.mark.acceptance
@pytest.mark.usefixtures('class_refresh_db', 'refreshdb', 'testflask')
@pytest.mark.incremental
class TestVehicleModal(AcceptanceHelper):
class TestModals(AcceptanceHelper):

def test_00_verify_db(self, testdb):
def test_00_vehicle_verify_db(self, testdb):
b = testdb.query(Vehicle).get(1)
assert b is not None
assert b.name == 'Veh1'
Expand All @@ -267,7 +267,7 @@ def test_00_verify_db(self, testdb):
assert b.name == 'Veh3Inactive'
assert b.is_active is False

def test_01_populate_modal(self, base_url, selenium):
def test_01_vehicle_populate_modal(self, base_url, selenium):
self.get(selenium, base_url + '/fuel')
link = selenium.find_element_by_xpath('//a[text()="Veh1"]')
self.wait_until_clickable(selenium, '//a[text()="Veh1"]', by='xpath')
Expand All @@ -281,7 +281,7 @@ def test_01_populate_modal(self, base_url, selenium):
'vehicle_frm_name').get_attribute('value') == 'Veh1'
assert selenium.find_element_by_id('vehicle_frm_active').is_selected()

def test_02_edit_modal_inactive(self, base_url, selenium):
def test_02_vehicle_edit_modal_inactive(self, base_url, selenium):
self.get(selenium, base_url + '/fuel')
link = selenium.find_element_by_xpath('//a[text()="Veh3Inactive"]')
self.wait_until_clickable(
Expand Down Expand Up @@ -339,13 +339,13 @@ def test_02_edit_modal_inactive(self, base_url, selenium):
]
]

def test_03_verify_db(self, testdb):
def test_03_vehicle_verify_db(self, testdb):
b = testdb.query(Vehicle).get(3)
assert b is not None
assert b.name == 'Veh3Edited'
assert b.is_active is True

def test_04_modal_add(self, base_url, selenium):
def test_04_vehicle_modal_add(self, base_url, selenium):
self.get(selenium, base_url + '/fuel')
link = selenium.find_element_by_id('btn-add-vehicle')
self.wait_until_clickable(selenium, 'btn-add-vehicle')
Expand Down Expand Up @@ -400,13 +400,7 @@ def test_04_modal_add(self, base_url, selenium):
]
]


@pytest.mark.acceptance
@pytest.mark.usefixtures('class_refresh_db', 'refreshdb', 'testflask')
@pytest.mark.incremental
class TestFuelLogModal(AcceptanceHelper):

def test_00_verify_db(self, testdb):
def test_10_fuel_verify_db(self, testdb):
ids = [
t.id for t in testdb.query(FuelFill).all()
]
Expand All @@ -418,7 +412,7 @@ def test_00_verify_db(self, testdb):
assert len(trans_ids) == 3
assert max(trans_ids) == 3

def test_01_populate_modal(self, base_url, selenium):
def test_11_fuel_populate_modal(self, base_url, selenium):
self.get(selenium, base_url + '/fuel')
link = selenium.find_element_by_id('btn-add-fuel')
self.wait_until_clickable(selenium, 'btn-add-fuel')
Expand All @@ -428,7 +422,7 @@ def test_01_populate_modal(self, base_url, selenium):
assert title.text == 'Add Fuel Fill'
veh_sel = Select(selenium.find_element_by_id('fuel_frm_vehicle'))
opts = [[o.get_attribute('value'), o.text] for o in veh_sel.options]
assert opts == [['1', 'Veh1'], ['2', 'Veh2']]
assert opts == [['1', 'Veh1'], ['2', 'Veh2'], ['3', 'Veh3Edited']]
assert veh_sel.first_selected_option.get_attribute('value') == '1'
date = selenium.find_element_by_id('fuel_frm_date')
assert date.get_attribute(
Expand Down Expand Up @@ -489,7 +483,7 @@ def test_01_populate_modal(self, base_url, selenium):
notes = selenium.find_element_by_id('fuel_frm_notes')
assert notes.get_attribute('value') == ''

def test_02_add_no_trans(self, base_url, selenium):
def test_12_fuel_add_no_trans(self, base_url, selenium):
self.get(selenium, base_url + '/fuel')
link = selenium.find_element_by_id('btn-add-fuel')
self.wait_until_clickable(selenium, 'btn-add-fuel')
Expand Down Expand Up @@ -559,12 +553,12 @@ def test_02_add_no_trans(self, base_url, selenium):
table = selenium.find_element_by_id('table-fuel-log')
odo_reads = [y[2] for y in self.tbody2textlist(table)]
assert odo_reads == [
'1,011', '1,012', '1,001', '1,002', '1,123'
'1,011', '1,012', '1,013', '1,001', '1,002', '1,003', '1,123'
]
notif = selenium.find_element_by_id('last_mpg_notice')
assert notif.get_attribute('innerHTML') == 'Last fill MPG: 16.349'

def test_03_verify_db(self, testdb):
def test_13_fuel_verify_db(self, testdb):
ids = [
t.id for t in testdb.query(FuelFill).all()
]
Expand Down Expand Up @@ -592,7 +586,7 @@ def test_03_verify_db(self, testdb):
assert len(trans_ids) == 3
assert max(trans_ids) == 3

def test_04_add_with_trans(self, base_url, selenium):
def test_14_fuel_add_with_trans(self, base_url, selenium):
self.get(selenium, base_url + '/fuel')
link = selenium.find_element_by_id('btn-add-fuel')
self.wait_until_clickable(selenium, 'btn-add-fuel')
Expand Down Expand Up @@ -661,10 +655,12 @@ def test_04_add_with_trans(self, base_url, selenium):
table = selenium.find_element_by_id('table-fuel-log')
odo_reads = [y[2] for y in self.tbody2textlist(table)]
assert odo_reads == [
'1,011', '1,012', '1,001', '1,002', '1,256', '1,123'
'1,011', '1,012', '1,013',
'1,001', '1,002', '1,003',
'1,256', '1,123'
]

def test_05_verify_db(self, testdb):
def test_15_fuel_verify_db(self, testdb):
ids = [
t.id for t in testdb.query(FuelFill).all()
]
Expand Down
86 changes: 31 additions & 55 deletions biweeklybudget/tests/acceptance/flaskapp/views/test_scheduled.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,9 +365,9 @@ def test_1_modal_from_url(self, base_url, selenium):
@pytest.mark.acceptance
@pytest.mark.usefixtures('class_refresh_db', 'refreshdb', 'testflask')
@pytest.mark.incremental
class TestSchedTransDateInactive(AcceptanceHelper):
class TestSchedTransModal(AcceptanceHelper):

def test_0_verify_db(self, testdb):
def test_00_edit_date_inactive_verify_db(self, testdb):
t = testdb.query(ScheduledTransaction).get(4)
assert t is not None
assert t.description == 'ST4'
Expand All @@ -382,7 +382,7 @@ def test_0_verify_db(self, testdb):
assert t.notes == 'notesST4'
assert t.is_active is False

def test_1_modal_from_url(self, base_url, selenium):
def test_01_edit_date_inactive_modal_from_url(self, base_url, selenium):
self.baseurl = base_url
self.get(selenium, base_url + '/scheduled/4')
modal, title, body = self.get_modal_parts(selenium)
Expand Down Expand Up @@ -410,7 +410,7 @@ def test_1_modal_from_url(self, base_url, selenium):
assert selenium.find_element_by_id(
'sched_frm_active').is_selected() is False

def test_2_modal_edit(self, base_url, selenium):
def test_02_edit_date_inactive_modal_edit(self, base_url, selenium):
self.baseurl = base_url
self.get(selenium, base_url + '/scheduled/4')
modal, title, body = self.get_modal_parts(selenium)
Expand Down Expand Up @@ -451,7 +451,7 @@ def test_2_modal_edit(self, base_url, selenium):
assert texts[2][0] == 'yes'
assert texts[2][4] == 'ST4edited'

def test_3_verify_db(self, testdb):
def test_03_edit_date_inactive_verify_db(self, testdb):
t = testdb.query(ScheduledTransaction).get(4)
assert t is not None
assert t.description == 'ST4edited'
Expand All @@ -466,13 +466,7 @@ def test_3_verify_db(self, testdb):
assert t.notes == 'notesST4'
assert t.is_active is True


@pytest.mark.acceptance
@pytest.mark.usefixtures('class_refresh_db', 'refreshdb', 'testflask')
@pytest.mark.incremental
class TestSchedTransAddDate(AcceptanceHelper):

def test_1_modal_on_click(self, base_url, selenium):
def test_10_add_date_modal_on_click(self, base_url, selenium):
self.baseurl = base_url
self.get(selenium, base_url + '/scheduled')
link = selenium.find_element_by_id('btn_add_sched')
Expand Down Expand Up @@ -525,7 +519,7 @@ def test_1_modal_on_click(self, base_url, selenium):
texts = [y[4] for y in self.tbody2textlist(table)]
assert 'NewST7' in texts

def test_3_verify_db(self, testdb):
def test_13_add_date_verify_db(self, testdb):
t = testdb.query(ScheduledTransaction).get(7)
assert t is not None
assert t.description == 'NewST7'
Expand All @@ -539,13 +533,7 @@ def test_3_verify_db(self, testdb):
assert t.notes == 'foo bar baz'
assert t.is_active is True


@pytest.mark.acceptance
@pytest.mark.usefixtures('class_refresh_db', 'refreshdb', 'testflask')
@pytest.mark.incremental
class TestSchedTransAddMonthly(AcceptanceHelper):

def test_1_modal_on_click(self, base_url, selenium):
def test_21_add_monthly_modal_on_click(self, base_url, selenium):
self.baseurl = base_url
self.get(selenium, base_url + '/scheduled')
link = selenium.find_element_by_id('btn_add_sched')
Expand All @@ -554,7 +542,7 @@ def test_1_modal_on_click(self, base_url, selenium):
self.assert_modal_displayed(modal, title, body)
assert title.text == 'Add New Scheduled Transaction'
desc = body.find_element_by_id('sched_frm_description')
desc.send_keys('NewST7Monthly')
desc.send_keys('NewST8Monthly')
_type = body.find_element_by_id('sched_frm_type_monthly')
_type.click()
day_input = body.find_element_by_id('sched_frm_day_of_month')
Expand All @@ -578,20 +566,20 @@ def test_1_modal_on_click(self, base_url, selenium):
_, _, body = self.get_modal_parts(selenium)
x = body.find_elements_by_tag_name('div')[0]
assert 'alert-success' in x.get_attribute('class')
assert x.text.strip() == 'Successfully saved ScheduledTransaction 7 ' \
assert x.text.strip() == 'Successfully saved ScheduledTransaction 8 ' \
'in database.'
# dismiss the modal
selenium.find_element_by_id('modalCloseButton').click()
self.wait_for_jquery_done(selenium)
# test that updated budget was removed from the page
table = selenium.find_element_by_id('table-scheduled-txn')
texts = [y[4] for y in self.tbody2textlist(table)]
assert 'NewST7Monthly' in texts
assert 'NewST8Monthly' in texts

def test_3_verify_db(self, testdb):
t = testdb.query(ScheduledTransaction).get(7)
def test_23_add_monthly_verify_db(self, testdb):
t = testdb.query(ScheduledTransaction).get(8)
assert t is not None
assert t.description == 'NewST7Monthly'
assert t.description == 'NewST8Monthly'
assert t.num_per_period is None
assert t.date is None
assert t.day_of_month == 4
Expand All @@ -601,13 +589,7 @@ def test_3_verify_db(self, testdb):
assert t.notes == 'foo bar baz'
assert t.is_active is True


@pytest.mark.acceptance
@pytest.mark.usefixtures('class_refresh_db', 'refreshdb', 'testflask')
@pytest.mark.incremental
class TestSchedTransAddPerPeriod(AcceptanceHelper):

def test_1_modal_on_click(self, base_url, selenium):
def test_31_add_per_period_modal_on_click(self, base_url, selenium):
self.baseurl = base_url
self.get(selenium, base_url + '/scheduled')
link = selenium.find_element_by_id('btn_add_sched')
Expand All @@ -616,7 +598,7 @@ def test_1_modal_on_click(self, base_url, selenium):
self.assert_modal_displayed(modal, title, body)
assert title.text == 'Add New Scheduled Transaction'
desc = body.find_element_by_id('sched_frm_description')
desc.send_keys('NewST7PerPeriod')
desc.send_keys('NewST9PerPeriod')
_type = body.find_element_by_id('sched_frm_type_per_period')
_type.click()
date_input = body.find_element_by_id('sched_frm_num_per_period')
Expand All @@ -640,20 +622,20 @@ def test_1_modal_on_click(self, base_url, selenium):
_, _, body = self.get_modal_parts(selenium)
x = body.find_elements_by_tag_name('div')[0]
assert 'alert-success' in x.get_attribute('class')
assert x.text.strip() == 'Successfully saved ScheduledTransaction 7 ' \
assert x.text.strip() == 'Successfully saved ScheduledTransaction 9 ' \
'in database.'
# dismiss the modal
selenium.find_element_by_id('modalCloseButton').click()
self.wait_for_jquery_done(selenium)
# test that updated budget was removed from the page
table = selenium.find_element_by_id('table-scheduled-txn')
texts = [y[4] for y in self.tbody2textlist(table)]
assert 'NewST7PerPeriod' in texts
assert 'NewST9PerPeriod' in texts

def test_3_verify_db(self, testdb):
t = testdb.query(ScheduledTransaction).get(7)
def test_33_add_per_period_verify_db(self, testdb):
t = testdb.query(ScheduledTransaction).get(9)
assert t is not None
assert t.description == 'NewST7PerPeriod'
assert t.description == 'NewST9PerPeriod'
assert t.num_per_period == 2
assert t.date is None
assert t.day_of_month is None
Expand All @@ -663,13 +645,7 @@ def test_3_verify_db(self, testdb):
assert t.notes == 'foo bar baz'
assert t.is_active is True


@pytest.mark.acceptance
@pytest.mark.usefixtures('class_refresh_db', 'refreshdb', 'testflask')
@pytest.mark.incremental
class TestSchedTransAddIncome(AcceptanceHelper):

def test_1_modal_on_click(self, base_url, selenium):
def test_41_add_income_modal_on_click(self, base_url, selenium):
self.baseurl = base_url
self.get(selenium, base_url + '/scheduled')
link = selenium.find_element_by_id('btn_add_sched')
Expand All @@ -678,7 +654,7 @@ def test_1_modal_on_click(self, base_url, selenium):
self.assert_modal_displayed(modal, title, body)
assert title.text == 'Add New Scheduled Transaction'
desc = body.find_element_by_id('sched_frm_description')
desc.send_keys('NewST8PerPeriod')
desc.send_keys('NewST10PerPeriod')
_type = body.find_element_by_id('sched_frm_type_per_period')
_type.click()
date_input = body.find_element_by_id('sched_frm_num_per_period')
Expand All @@ -702,20 +678,20 @@ def test_1_modal_on_click(self, base_url, selenium):
_, _, body = self.get_modal_parts(selenium)
x = body.find_elements_by_tag_name('div')[0]
assert 'alert-success' in x.get_attribute('class')
assert x.text.strip() == 'Successfully saved ScheduledTransaction 7 ' \
assert x.text.strip() == 'Successfully saved ScheduledTransaction 10 ' \
'in database.'
# dismiss the modal
selenium.find_element_by_id('modalCloseButton').click()
self.wait_for_jquery_done(selenium)
# test that updated budget was removed from the page
table = selenium.find_element_by_id('table-scheduled-txn')
texts = [y[4] for y in self.tbody2textlist(table)]
assert 'NewST8PerPeriod' in texts
assert 'NewST10PerPeriod' in texts

def test_3_verify_db(self, testdb):
t = testdb.query(ScheduledTransaction).get(7)
def test_43_add_income_verify_db(self, testdb):
t = testdb.query(ScheduledTransaction).get(10)
assert t is not None
assert t.description == 'NewST8PerPeriod'
assert t.description == 'NewST10PerPeriod'
assert t.num_per_period == 1
assert t.date is None
assert t.day_of_month is None
Expand All @@ -725,7 +701,7 @@ def test_3_verify_db(self, testdb):
assert t.notes == 'foo bar baz'
assert t.is_active is True

def test_4_table(self, base_url, selenium):
def test_44_add_income_table(self, base_url, selenium):
self.baseurl = base_url
self.get(selenium, base_url + '/scheduled')
table = selenium.find_element_by_id('table-scheduled-txn')
Expand All @@ -736,12 +712,12 @@ def test_4_table(self, base_url, selenium):
'per period',
'1 per period',
'$123.45',
'NewST8PerPeriod',
'NewST10PerPeriod',
'BankOne (1)',
'Income (income) (7)'
]
assert elems[1][4].get_attribute('innerHTML') == '' \
'<a href="javascript:schedModal(7, mytable)">NewST8PerPeriod</a>'
'<a href="javascript:schedModal(10, mytable)">NewST10PerPeriod</a>'
assert elems[1][5].get_attribute('innerHTML') == '' \
'<a href="/accounts/1">BankOne (1)</a>'
assert elems[1][6].get_attribute('innerHTML') == '' \
Expand Down
Loading

0 comments on commit 3772dd9

Please sign in to comment.