Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
RPSJR committed Nov 24, 2023
1 parent ceedfa5 commit 3ac6afc
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
2 changes: 2 additions & 0 deletions fleet_vehicle_ownership/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from . import test_owner

from . import test_partner
46 changes: 46 additions & 0 deletions fleet_vehicle_ownership/tests/test_partner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
from odoo.tests import common


class TestResPartner(common.TransactionCase):

def setUp(self):
super(TestResPartner, self).setUp()

# Create necessary test data here, such as a partner and vehicles
self.partner = self.env['res.partner'].create({
'name': 'Lewis Hamilton',
})
self.vehicle1 = self.env['fleet.vehicle'].create({
'name': 'W14',
'owner_id': self.partner.id,
})
self.vehicle2 = self.env['fleet.vehicle'].create({
'name': 'W13',
'owner_id': self.partner.id,
})

def test_compute_vehicle_count(self):
# Check if the vehicle count is computed correctly
self.partner._compute_vehicle_count()
self.assertEqual(self.partner.vehicle_count, 2, "Vehicle count is incorrect")

def test_action_view_vehicles(self):
# Check if action_view_vehicles method returns the correct action
action = self.partner.action_view_vehicles()

# Assert that the action is correctly configured
self.assertEqual(action['res_model'], 'fleet.vehicle', "Incorrect res_model in action")
self.assertEqual(action['name'], 'Vehicles', "Incorrect name in action")

# Test when there is more than one vehicle
self.partner.vehicle_count = 2
action = self.partner.action_view_vehicles()
self.assertTrue(action['domain'], [("id", "in", self.partner.vehicle_ids.ids)],
"Incorrect domain when multiple vehicles")

# Test when there is only one vehicle
self.partner.vehicle_count = 1
action = self.partner.action_view_vehicles()
self.assertEqual(action['views'], [(self.env.ref("fleet.fleet_vehicle_view_form").id, "form")],
"Incorrect views when only one vehicle")
self.assertEqual(action['res_id'], self.partner.vehicle_ids.ids[0], "Incorrect res_id when only one vehicle")

0 comments on commit 3ac6afc

Please sign in to comment.