Robottelo: Compare entire object instead of single fields when cloning entities

Created on 11 Nov 2016  路  12Comments  路  Source: SatelliteQE/robottelo

from #3982

tests/foreman/api/test_hostgroup.py
+        hostgroup_cloned = entities.HostGroup(
+            id=hostgroup.id
+        ).clone(data={'name': hostgroup_cloned_name})
+        self.assertEqual(hostgroup_cloned['name'], hostgroup_cloned_name)

@omaciel
omaciel 17 hours ago SatelliteQE member
This has nothing to do with this PR but... can we file an issue to improve this test by asserting that the entire object is equal to the cloned one? Checking that only the name matches assumes that everything else also matches and I don't think we should make assumptions.

@rochacbruno
rochacbruno 16 hours ago SatelliteQE member
IT can be done since we merge the PR which adds the to_json method, so we can override the __eq__ making that special method to compare the set of two entities values as in Host(id=1) == Host(id=1) -> True
https://github.com/SatelliteQE/nailgun/issues/335

6.3 enhancement

All 12 comments

Nailgun now can compare cloned entities so we can start changing self.assertEqual(hostgroup_cloned['name'], hostgroup_cloned_name) to self.assertEqual(hostgroup_cloned, hostgroup_cloned) and other similar tests.

@rochacbruno just be aware that other branches of Robottelo (i.e. 6.1.z, 6.2.z) most likely use an older version of NailGun, which won't have the new __eq__ method, so new tests using this new process for assertions or comparisons won't easily be cherry picked to older branches.

@omaciel good catch! @renzon maybe we can include that logic on other nailgun branches?

I am going to cherry pick it.

The nailgun commit is being cherry picked in https://github.com/SatelliteQE/nailgun/pull/353. It leaves us to determine what all should be updated on robottelo side. It probably goes well beyond test_hostgroup, as the majority of api tests uses some kind of name comparison.

@pondrejk every test where we used the .clone is a candidate

@rochacbruno @omaciel: I cherry picked to 6.2.z nailgun branch. While doing this I realized there is no 6.1.z branch for nailgun project. Should we create it? Also important notice that robottello 6.1.z seems to be pinned nailgun version from pypi: https://github.com/SatelliteQE/robottelo/blob/6.1.z/requirements-freeze.txt#L25

@renzon @omaciel it would be nice if we create a branch for 6.1 since we need to cherry pick some features. But this branch may be based on this tag https://github.com/SatelliteQE/nailgun/releases/tag/0.28.0 which is the latest PyPI release being used by 6.1 build.

@rochacbruno thanks for a tip, so a checklist for me is:

  • [ ] test_contentview.py -- 2 tests
  • [x] test_template.py -- 1 test
  • [x] test_hostgroup.py -- 1 test

@rochacbruno let's create the branch and update all required files (travis, setup, requirements, etc) then.

@omaciel @renzon 6.1.z created in nailgun https://github.com/SatelliteQE/nailgun/tree/6.1.z

@rochacbruno: going to make sure __eq__ also on this version

Was this page helpful?
0 / 5 - 0 ratings