Rework AseertEqual params order in freezer-api

from (got, expected) to (expected, got)

Change-Id: Id4ec8f561ce707fbbb60ae49bf5ad95d22ecd223
Close-Bug: #1259292
changes/82/564482/2
Oleksiy Petrenko 5 years ago
parent 206321471c
commit 67e5953c1c
  1. 30
      freezer_api/tests/unit/test_actions.py
  2. 22
      freezer_api/tests/unit/test_backups.py
  3. 22
      freezer_api/tests/unit/test_clients.py
  4. 16
      freezer_api/tests/unit/test_context.py
  5. 102
      freezer_api/tests/unit/test_elastic.py
  6. 2
      freezer_api/tests/unit/test_homedoc.py
  7. 50
      freezer_api/tests/unit/test_jobs.py
  8. 56
      freezer_api/tests/unit/test_sessions.py
  9. 20
      freezer_api/tests/unit/test_utils.py
  10. 4
      freezer_api/tests/unit/test_versions.py

@ -43,8 +43,8 @@ class TestActionsCollectionResource(common.FreezerBaseTestCase):
expected_result = {'actions': []}
self.resource.on_get(self.mock_req, self.mock_req)
result = self.mock_req.body
self.assertEqual(result, expected_result)
self.assertEqual(self.mock_req.status, falcon.HTTP_200)
self.assertEqual(expected_result, result)
self.assertEqual(falcon.HTTP_200, self.mock_req.status)
def test_on_get_return_correct_list(self):
self.mock_db.search_action.return_value = [common.get_fake_action_0(),
@ -53,8 +53,8 @@ class TestActionsCollectionResource(common.FreezerBaseTestCase):
common.get_fake_action_1()]}
self.resource.on_get(self.mock_req, self.mock_req)
result = self.mock_req.body
self.assertEqual(result, expected_result)
self.assertEqual(self.mock_req.status, falcon.HTTP_200)
self.assertEqual(expected_result, result)
self.assertEqual(falcon.HTTP_200, self.mock_req.status)
def test_on_post_raises_when_missing_body(self):
self.mock_db.add_action.return_value = common.fake_action_0[
@ -68,8 +68,8 @@ class TestActionsCollectionResource(common.FreezerBaseTestCase):
self.mock_db.add_action.return_value = 'pjiofrdslaikfunr'
expected_result = {'action_id': 'pjiofrdslaikfunr'}
self.resource.on_post(self.mock_req, self.mock_req)
self.assertEqual(self.mock_req.status, falcon.HTTP_201)
self.assertEqual(self.mock_req.body, expected_result)
self.assertEqual(falcon.HTTP_201, self.mock_req.status)
self.assertEqual(expected_result, self.mock_req.body)
class TestActionsResource(common.FreezerBaseTestCase):
@ -94,23 +94,23 @@ class TestActionsResource(common.FreezerBaseTestCase):
self.resource.on_get(self.mock_req, self.mock_req,
common.fake_action_0['action_id'])
self.assertIsNone(self.mock_req.body)
self.assertEqual(self.mock_req.status, falcon.HTTP_404)
self.assertEqual(falcon.HTTP_404, self.mock_req.status)
def test_on_get_return_correct_data(self):
self.mock_db.get_action.return_value = common.get_fake_action_0()
self.resource.on_get(self.mock_req, self.mock_req,
common.fake_action_0['action_id'])
result = self.mock_req.body
self.assertEqual(result, common.get_fake_action_0())
self.assertEqual(self.mock_req.status, falcon.HTTP_200)
self.assertEqual(common.get_fake_action_0(), result)
self.assertEqual(falcon.HTTP_200, self.mock_req.status)
def test_on_delete_removes_proper_data(self):
self.resource.on_delete(self.mock_req, self.mock_req,
common.fake_action_0['action_id'])
result = self.mock_req.body
expected_result = {'action_id': common.fake_action_0['action_id']}
self.assertEqual(self.mock_req.status, falcon.HTTP_204)
self.assertEqual(result, expected_result)
self.assertEqual(falcon.HTTP_204, self.mock_req.status)
self.assertEqual(expected_result, result)
def test_on_patch_ok_with_some_fields(self):
new_version = random.randint(0, 99)
@ -130,9 +130,9 @@ class TestActionsResource(common.FreezerBaseTestCase):
user_id=common.fake_action_0['user_id'],
action_id=common.fake_action_0['action_id'],
patch_doc=patch_doc)
self.assertEqual(self.mock_req.status, falcon.HTTP_200)
self.assertEqual(falcon.HTTP_200, self.mock_req.status)
result = self.mock_req.body
self.assertEqual(result, expected_result)
self.assertEqual(expected_result, result)
def test_on_post_ok(self):
new_version = random.randint(0, 99)
@ -144,8 +144,8 @@ class TestActionsResource(common.FreezerBaseTestCase):
self.resource.on_post(self.mock_req, self.mock_req,
common.fake_action_0['action_id'])
self.assertEqual(self.mock_req.status, falcon.HTTP_201)
self.assertEqual(self.mock_req.body, expected_result)
self.assertEqual(falcon.HTTP_201, self.mock_req.status)
self.assertEqual(expected_result, self.mock_req.body)
def test_on_post_raises_when_db_replace_action_raises(self):
self.mock_db.replace_action.side_effect = exceptions.AccessForbidden(

@ -43,8 +43,8 @@ class TestBackupsCollectionResource(common.FreezerBaseTestCase):
expected_result = {'backups': []}
self.resource.on_get(self.mock_req, self.mock_req)
result = self.mock_req.body
self.assertEqual(result, expected_result)
self.assertEqual(self.mock_req.status, falcon.HTTP_200)
self.assertEqual(expected_result, result)
self.assertEqual(falcon.HTTP_200, self.mock_req.status)
def test_on_get_return_correct_list(self):
self.mock_db.search_backup.return_value = [
@ -52,8 +52,8 @@ class TestBackupsCollectionResource(common.FreezerBaseTestCase):
expected_result = {'backups': [common.fake_data_0_backup_metadata]}
self.resource.on_get(self.mock_req, self.mock_req)
result = self.mock_req.body
self.assertEqual(result, expected_result)
self.assertEqual(self.mock_req.status, falcon.HTTP_200)
self.assertEqual(expected_result, result)
self.assertEqual(falcon.HTTP_200, self.mock_req.status)
def test_on_post_raises_when_missing_body(self):
self.mock_db.add_backup.return_value = [
@ -70,8 +70,8 @@ class TestBackupsCollectionResource(common.FreezerBaseTestCase):
expected_result = {
'backup_id': common.fake_data_0_wrapped_backup_metadata[
'backup_id']}
self.assertEqual(self.mock_req.body, expected_result)
self.assertEqual(self.mock_req.status, falcon.HTTP_201)
self.assertEqual(expected_result, self.mock_req.body)
self.assertEqual(falcon.HTTP_201, self.mock_req.status)
class TestBackupsResource(common.FreezerBaseTestCase):
@ -95,7 +95,7 @@ class TestBackupsResource(common.FreezerBaseTestCase):
common.fake_data_0_wrapped_backup_metadata[
'backup_id'])
self.assertIsNone(self.mock_req.body)
self.assertEqual(self.mock_req.status, falcon.HTTP_404)
self.assertEqual(falcon.HTTP_404, self.mock_req.status)
def test_on_get_return_correct_data(self):
self.mock_db.get_backup.return_value = [
@ -105,13 +105,13 @@ class TestBackupsResource(common.FreezerBaseTestCase):
common.fake_data_0_wrapped_backup_metadata[
'backup_id'])
result = self.mock_req.body
self.assertEqual(result, expected_result)
self.assertEqual(self.mock_req.status, falcon.HTTP_200)
self.assertEqual(expected_result, result)
self.assertEqual(falcon.HTTP_200, self.mock_req.status)
def test_on_delete_removes_proper_data(self):
self.resource.on_delete(self.mock_req, self.mock_req,
common.fake_data_0_backup_id)
result = self.mock_req.body
expected_result = {'backup_id': common.fake_data_0_backup_id}
self.assertEqual(self.mock_req.status, falcon.HTTP_204)
self.assertEqual(result, expected_result)
self.assertEqual(falcon.HTTP_204, self.mock_req.status)
self.assertEqual(expected_result, result)

@ -38,8 +38,8 @@ class TestClientsCollectionResource(common.FreezerBaseTestCase):
expected_result = {'clients': []}
self.resource.on_get(self.mock_req, self.mock_req)
result = self.mock_req.body
self.assertEqual(result, expected_result)
self.assertEqual(self.mock_req.status, falcon.HTTP_200)
self.assertEqual(expected_result, result)
self.assertEqual(falcon.HTTP_200, self.mock_req.status)
def test_on_get_return_correct_list(self):
self.mock_db.get_client.return_value = [common.fake_client_entry_0,
@ -48,8 +48,8 @@ class TestClientsCollectionResource(common.FreezerBaseTestCase):
common.fake_client_entry_1]}
self.resource.on_get(self.mock_req, self.mock_req)
result = self.mock_req.body
self.assertEqual(result, expected_result)
self.assertEqual(self.mock_req.status, falcon.HTTP_200)
self.assertEqual(expected_result, result)
self.assertEqual(falcon.HTTP_200, self.mock_req.status)
def test_on_post_raises_when_missing_body(self):
self.mock_db.add_client.return_value = common.fake_client_info_0[
@ -63,8 +63,8 @@ class TestClientsCollectionResource(common.FreezerBaseTestCase):
'client_id']
expected_result = {'client_id': common.fake_client_info_0['client_id']}
self.resource.on_post(self.mock_req, self.mock_req)
self.assertEqual(self.mock_req.status, falcon.HTTP_201)
self.assertEqual(self.mock_req.body, expected_result)
self.assertEqual(falcon.HTTP_201, self.mock_req.status)
self.assertEqual(expected_result, self.mock_req.body)
class TestClientsResource(common.FreezerBaseTestCase):
@ -89,7 +89,7 @@ class TestClientsResource(common.FreezerBaseTestCase):
self.resource.on_get(self.mock_req, self.mock_req,
common.fake_client_info_0['client_id'])
self.assertIsNone(self.mock_req.body)
self.assertEqual(self.mock_req.status, falcon.HTTP_404)
self.assertEqual(falcon.HTTP_404, self.mock_req.status)
def test_on_get_return_correct_data(self):
self.mock_db.get_client.return_value = [common.fake_client_entry_0]
@ -97,13 +97,13 @@ class TestClientsResource(common.FreezerBaseTestCase):
self.resource.on_get(self.mock_req, self.mock_req,
common.fake_client_info_0['client_id'])
result = self.mock_req.body
self.assertEqual(result, expected_result)
self.assertEqual(self.mock_req.status, falcon.HTTP_200)
self.assertEqual(expected_result, result)
self.assertEqual(falcon.HTTP_200, self.mock_req.status)
def test_on_delete_removes_proper_data(self):
self.resource.on_delete(self.mock_req, self.mock_req,
common.fake_client_info_0['client_id'])
result = self.mock_req.body
expected_result = {'client_id': common.fake_client_info_0['client_id']}
self.assertEqual(self.mock_req.status, falcon.HTTP_204)
self.assertEqual(result, expected_result)
self.assertEqual(falcon.HTTP_204, self.mock_req.status)
self.assertEqual(expected_result, result)

@ -26,23 +26,23 @@ class TestFreezerContext(unittest.TestCase):
def test_not_admin(self):
ctxt = context.get_current()
self.assertEqual(ctxt.is_admin, False)
self.assertEqual(False, ctxt.is_admin)
def test_privileges_elevated(self):
self.ctxt = self.ctxt.elevated('yes')
self.assertEqual(self.ctxt.is_admin, True)
self.assertEqual(self.ctxt.show_deleted, 'yes')
self.assertTrue(self.ctxt.is_admin)
self.assertEqual('yes', self.ctxt.show_deleted)
def test_admin_context(self):
admin_ctxt = context.get_admin_context(show_deleted='yes')
self.assertEqual(admin_ctxt.is_admin, True)
self.assertEqual(admin_ctxt.show_deleted, 'yes')
self.assertTrue(admin_ctxt.is_admin)
self.assertEqual('yes', admin_ctxt.show_deleted)
def test_from_dict(self):
ctxt_dict = {'user': 'user02',
'tenant': 'tenant03',
'roles': ['_member', 'member']}
ctxt = context.FreezerContext.from_dict(ctxt_dict)
self.assertEqual(ctxt.is_admin, False)
self.assertEqual(ctxt.user, 'user02')
self.assertEqual(ctxt.tenant, ctxt_dict.get('tenant'))
self.assertFalse(ctxt.is_admin)
self.assertEqual('user02', ctxt.user)
self.assertEqual(ctxt_dict.get('tenant'), ctxt.tenant)

@ -64,13 +64,13 @@ class TypeManager(unittest.TestCase):
}
}
]
self.assertEqual(q, expected_q)
self.assertEqual(expected_q, q)
def test_get_ok(self):
self.mock_es.get.return_value = common.fake_job_0_elasticsearch_found
res = self.type_manager.get(user_id=common.fake_job_0_user_id,
doc_id=common.fake_job_0_job_id)
self.assertEqual(res, common.fake_job_0)
self.assertEqual(common.fake_job_0, res)
def test_get_raise_DocumentNotFound_when_doc_not_found(self):
self.mock_es.get.side_effect = elasticsearch.TransportError(
@ -130,7 +130,7 @@ class TypeManager(unittest.TestCase):
doc_type='base_doc_type',
size=19, from_=7,
body=expected_q)
self.assertEqual(res, [common.fake_data_0_backup_metadata])
self.assertEqual([common.fake_data_0_backup_metadata], res)
def test_search_raise_StorageEngineError_when_search_raises(self):
self.mock_es.search.side_effect = Exception('regular test failure')
@ -142,7 +142,7 @@ class TypeManager(unittest.TestCase):
self.mock_es.index.return_value = {'created': True, '_version': 15}
test_doc = {'test_key_412': 'test_value_412', '_version': 5}
res = self.type_manager.insert(doc=test_doc)
self.assertEqual(res, (True, 15))
self.assertEqual((True, 15), res)
self.mock_es.index.assert_called_with(index='freezer',
doc_type='base_doc_type',
body=test_doc, id=None)
@ -215,8 +215,9 @@ class TypeManager(unittest.TestCase):
}]}}
self.mock_es.search.return_value = ret_data
res = self.type_manager.delete(user_id='my_user_id', doc_id=doc_id)
self.assertEqual(res, 'cicciopassamilolio',
'invalid res {0}'.format(res))
self.assertEqual(
'cicciopassamilolio', res, 'invalid res {0}'.format(res)
)
class TestBackupManager(unittest.TestCase):
@ -288,7 +289,7 @@ class TestBackupManager(unittest.TestCase):
}
}
}
self.assertEqual(q, expected_q)
self.assertEqual(expected_q, q)
class ClientTypeManager(unittest.TestCase):
@ -345,7 +346,7 @@ class ClientTypeManager(unittest.TestCase):
}
}
}
self.assertEqual(q, expected_q)
self.assertEqual(expected_q, q)
class JobTypeManager(unittest.TestCase):
@ -395,7 +396,7 @@ class JobTypeManager(unittest.TestCase):
}
}
]}}}}}
self.assertEqual(q, expected_q)
self.assertEqual(expected_q, q)
def test_update_ok(self):
self.mock_es.update.return_value = {
@ -406,7 +407,7 @@ class JobTypeManager(unittest.TestCase):
}
res = self.job_manager.update(job_id=common.fake_job_0_job_id,
job_update_doc={'status': 'sleepy'})
self.assertEqual(res, 3)
self.assertEqual(3, res)
self.mock_es.update.assert_called_with(
index=self.job_manager.index,
doc_type=self.job_manager.doc_type,
@ -484,7 +485,7 @@ class ActionTypeManager(unittest.TestCase):
}
}
]}}}}}
self.assertEqual(q, expected_q)
self.assertEqual(expected_q, q)
def test_update_ok(self):
self.mock_es.update.return_value = {
@ -496,7 +497,7 @@ class ActionTypeManager(unittest.TestCase):
res = self.action_manager.update(action_id='poiuuiop7890',
action_update_doc={
'status': 'sleepy'})
self.assertEqual(res, 3)
self.assertEqual(3, res)
self.mock_es.update.assert_called_with(
index=self.action_manager.index,
doc_type=self.action_manager.doc_type,
@ -578,7 +579,7 @@ class SessionTypeManager(unittest.TestCase):
}
}
]}}}}}
self.assertEqual(q, expected_q)
self.assertEqual(expected_q, q)
def test_update_ok(self):
self.mock_es.update.return_value = {
@ -590,7 +591,7 @@ class SessionTypeManager(unittest.TestCase):
res = self.session_manager.update(session_id='poiuuiop7890',
session_update_doc={
'status': 'sleepy'})
self.assertEqual(res, 3)
self.assertEqual(3, res)
self.mock_es.update.assert_called_with(
index=self.session_manager.index,
doc_type=self.session_manager.doc_type,
@ -639,7 +640,7 @@ class TestElasticSearchEngine_backup(unittest.TestCase):
res = self.eng.get_backup(user_id=common.fake_data_0_user_id,
backup_id=common.fake_data_0_backup_id)
self.assertEqual(res, common.fake_data_0_wrapped_backup_metadata)
self.assertEqual(common.fake_data_0_wrapped_backup_metadata, res)
self.eng.backup_manager.get.assert_called_with(
common.fake_data_0_wrapped_backup_metadata['user_id'],
common.fake_data_0_wrapped_backup_metadata['backup_id']
@ -654,8 +655,12 @@ class TestElasticSearchEngine_backup(unittest.TestCase):
res = self.eng.search_backup(user_id=common.fake_data_0_user_id,
offset=3, limit=7,
search=my_search)
self.assertEqual(res, [common.fake_data_0_wrapped_backup_metadata,
common.fake_data_1_wrapped_backup_metadata])
self.assertEqual(
[
common.fake_data_0_wrapped_backup_metadata,
common.fake_data_1_wrapped_backup_metadata
], res
)
self.eng.backup_manager.search.assert_called_with(
common.fake_data_0_wrapped_backup_metadata['user_id'],
search=my_search,
@ -668,7 +673,7 @@ class TestElasticSearchEngine_backup(unittest.TestCase):
res = self.eng.search_backup(user_id=common.fake_data_0_user_id,
offset=3, limit=7,
search=my_search)
self.assertEqual(res, [])
self.assertEqual([], res)
self.eng.backup_manager.search.assert_called_with(
common.fake_data_0_wrapped_backup_metadata['user_id'],
search=my_search,
@ -713,7 +718,7 @@ class TestElasticSearchEngine_backup(unittest.TestCase):
)
res = self.eng.delete_backup(user_id=common.fake_data_0_user_id,
backup_id=common.fake_data_0_backup_id)
self.assertEqual(res, common.fake_data_0_backup_id)
self.assertEqual(common.fake_data_0_backup_id, res)
def test_delete_backup_raises_when_es_delete_raises(self):
self.eng.backup_manager.delete.side_effect = (
@ -745,7 +750,7 @@ class TestElasticSearchEngine_client(unittest.TestCase):
client_id=common.fake_client_info_0['client_id'],
offset=6, limit=15,
search=my_search)
self.assertEqual(res, [common.fake_client_entry_0])
self.assertEqual([common.fake_client_entry_0], res)
self.eng.client_manager.search.assert_called_with(
common.fake_client_entry_0['user_id'],
common.fake_client_info_0['client_id'],
@ -761,8 +766,11 @@ class TestElasticSearchEngine_client(unittest.TestCase):
user_id=common.fake_client_entry_0['user_id'],
offset=6, limit=15,
search=my_search)
self.assertEqual(res, [common.fake_client_entry_0,
common.fake_client_entry_1])
self.assertEqual(
[
common.fake_client_entry_0,
common.fake_client_entry_1
], res)
self.eng.client_manager.search.assert_called_with(
common.fake_client_entry_0['user_id'],
None,
@ -777,7 +785,7 @@ class TestElasticSearchEngine_client(unittest.TestCase):
user_id=common.fake_client_entry_0['user_id'],
offset=6, limit=15,
search=my_search)
self.assertEqual(res, [])
self.assertEqual([], res)
self.eng.client_manager.search.assert_called_with(
common.fake_client_entry_0['user_id'],
None,
@ -802,7 +810,7 @@ class TestElasticSearchEngine_client(unittest.TestCase):
self.eng.client_manager.search.return_value = []
res = self.eng.add_client(user_id=common.fake_data_0_user_id,
doc=common.fake_client_info_0)
self.assertEqual(res, common.fake_client_info_0['client_id'])
self.assertEqual(common.fake_client_info_0['client_id'], res)
self.eng.client_manager.search.assert_called_with(
common.fake_data_0_user_id,
common.fake_client_info_0['client_id'])
@ -823,7 +831,7 @@ class TestElasticSearchEngine_client(unittest.TestCase):
res = self.eng.delete_client(user_id=common.fake_data_0_user_id,
client_id=common.fake_client_info_0[
'client_id'])
self.assertEqual(res, common.fake_client_info_0['client_id'])
self.assertEqual(common.fake_client_info_0['client_id'], res)
def test_delete_client_raises_when_es_delete_raises(self):
self.eng.client_manager.delete.side_effect = (
@ -849,7 +857,7 @@ class TestElasticSearchEngine_job(unittest.TestCase):
self.eng.job_manager.get.return_value = common.get_fake_job_0()
res = self.eng.get_job(user_id=common.fake_client_entry_0['user_id'],
job_id=common.fake_client_info_0['client_id'])
self.assertEqual(res, common.fake_job_0)
self.assertEqual(common.fake_job_0, res)
self.eng.job_manager.get.assert_called_with(
common.fake_client_entry_0['user_id'],
common.fake_client_info_0['client_id'])
@ -871,7 +879,7 @@ class TestElasticSearchEngine_job(unittest.TestCase):
res = self.eng.search_job(user_id=common.fake_job_0['user_id'],
offset=6, limit=15,
search=my_search)
self.assertEqual(res, [common.fake_job_0, common.fake_job_0])
self.assertEqual([common.fake_job_0, common.fake_job_0], res)
self.eng.job_manager.search.assert_called_with(
common.fake_job_0['user_id'],
search=my_search,
@ -884,7 +892,7 @@ class TestElasticSearchEngine_job(unittest.TestCase):
res = self.eng.search_job(user_id=common.fake_job_0['user_id'],
offset=6, limit=15,
search=my_search)
self.assertEqual(res, [])
self.assertEqual([], res)
self.eng.job_manager.search.assert_called_with(
common.fake_job_0['user_id'],
search=my_search,
@ -896,7 +904,7 @@ class TestElasticSearchEngine_job(unittest.TestCase):
self.eng.job_manager.insert.return_value = (True, 1)
res = self.eng.add_job(user_id=common.fake_job_0_user_id,
doc=common.get_fake_job_0())
self.assertEqual(res, common.fake_job_0_job_id)
self.assertEqual(common.fake_job_0_job_id, res)
self.eng.job_manager.insert.assert_called_with(
common.fake_job_0, common.fake_job_0_job_id
)
@ -915,7 +923,7 @@ class TestElasticSearchEngine_job(unittest.TestCase):
self.eng.job_manager.delete.return_value = common.fake_job_0['job_id']
res = self.eng.delete_job(user_id=common.fake_job_0_user_id,
job_id=common.fake_job_0_job_id)
self.assertEqual(res, common.fake_job_0_job_id)
self.assertEqual(common.fake_job_0_job_id, res)
def test_delete_client_raises_StorageEngineError_when_es_delete_raises(
self):
@ -953,7 +961,7 @@ class TestElasticSearchEngine_job(unittest.TestCase):
res = self.eng.update_job(user_id=common.fake_job_0_user_id,
job_id=common.fake_job_0_job_id,
patch_doc=patch)
self.assertEqual(res, 11)
self.assertEqual(11, res)
def test_replace_job_raises_AccessForbidden_when_job_manager_raises(
self):
@ -972,7 +980,7 @@ class TestElasticSearchEngine_job(unittest.TestCase):
res = self.eng.replace_job(user_id=common.fake_job_0_user_id,
job_id=common.fake_job_0_job_id,
doc=common.get_fake_job_0())
self.assertEqual(res, 1)
self.assertEqual(1, res)
def test_replace_job_returns_version_1_when_doc_is_overwritten(self):
self.eng.job_manager.get.return_value = common.get_fake_job_0()
@ -980,7 +988,7 @@ class TestElasticSearchEngine_job(unittest.TestCase):
res = self.eng.replace_job(user_id=common.fake_job_0_user_id,
job_id=common.fake_job_0_job_id,
doc=common.get_fake_job_0())
self.assertEqual(res, 3)
self.assertEqual(3, res)
class TestElasticSearchEngine_action(unittest.TestCase):
@ -997,7 +1005,7 @@ class TestElasticSearchEngine_action(unittest.TestCase):
self.eng.action_manager.get.return_value = common.get_fake_action_0()
res = self.eng.get_action(user_id=common.fake_action_0['user_id'],
action_id=common.fake_action_0['action_id'])
self.assertEqual(res, common.fake_action_0)
self.assertEqual(common.fake_action_0, res)
self.eng.action_manager.get.assert_called_with(
common.fake_action_0['user_id'],
common.fake_action_0['action_id'])
@ -1019,7 +1027,7 @@ class TestElasticSearchEngine_action(unittest.TestCase):
res = self.eng.search_action(user_id=common.fake_action_0['user_id'],
offset=6, limit=15,
search=my_search)
self.assertEqual(res, [common.fake_action_0, common.fake_action_0])
self.assertEqual([common.fake_action_0, common.fake_action_0], res)
self.eng.action_manager.search.assert_called_with(
common.fake_action_0['user_id'],
search=my_search,
@ -1032,7 +1040,7 @@ class TestElasticSearchEngine_action(unittest.TestCase):
res = self.eng.search_action(user_id=common.fake_action_0['user_id'],
offset=6, limit=15,
search=my_search)
self.assertEqual(res, [])
self.assertEqual([], res)
self.eng.action_manager.search.assert_called_with(
common.fake_action_0['user_id'],
search=my_search,
@ -1044,7 +1052,7 @@ class TestElasticSearchEngine_action(unittest.TestCase):
self.eng.action_manager.insert.return_value = (True, 1)
res = self.eng.add_action(user_id=common.fake_action_0['user_id'],
doc=common.get_fake_action_0())
self.assertEqual(res, common.fake_action_0['action_id'])
self.assertEqual(common.fake_action_0['action_id'], res)
self.eng.action_manager.insert.assert_called_with(
common.fake_action_0, common.fake_action_0['action_id']
)
@ -1065,7 +1073,7 @@ class TestElasticSearchEngine_action(unittest.TestCase):
res = self.eng.delete_action(user_id=common.fake_action_0['action_id'],
action_id=common.fake_action_0[
'action_id'])
self.assertEqual(res, common.fake_action_0['action_id'])
self.assertEqual(common.fake_action_0['action_id'], res)
def test_delete_client_raises_StorageEngineError_when_es_delete_raises(
self):
@ -1106,7 +1114,7 @@ class TestElasticSearchEngine_action(unittest.TestCase):
action_id=common.fake_action_0[
'action_id'],
patch_doc=patch)
self.assertEqual(res, 11)
self.assertEqual(11, res)
def test_replace_action_raises_AccessForbidden_when_action_manager_raises(
self):
@ -1155,7 +1163,7 @@ class TestElasticSearchEngine_session(unittest.TestCase):
res = self.eng.get_session(user_id=common.fake_session_0['user_id'],
session_id=common.fake_session_0[
'session_id'])
self.assertEqual(res, common.fake_session_0)
self.assertEqual(common.fake_session_0, res)
self.eng.session_manager.get.assert_called_with(
common.fake_session_0['user_id'],
common.fake_session_0['session_id'])
@ -1178,7 +1186,7 @@ class TestElasticSearchEngine_session(unittest.TestCase):
res = self.eng.search_session(user_id=common.fake_session_0['user_id'],
offset=6, limit=15,
search=my_search)
self.assertEqual(res, [common.fake_session_0, common.fake_session_0])
self.assertEqual([common.fake_session_0, common.fake_session_0], res)
self.eng.session_manager.search.assert_called_with(
common.fake_session_0['user_id'],
search=my_search,
@ -1191,7 +1199,7 @@ class TestElasticSearchEngine_session(unittest.TestCase):
res = self.eng.search_session(user_id=common.fake_session_0['user_id'],
offset=6, limit=15,
search=my_search)
self.assertEqual(res, [])
self.assertEqual([], res)
self.eng.session_manager.search.assert_called_with(
common.fake_session_0['user_id'],
search=my_search,
@ -1203,7 +1211,7 @@ class TestElasticSearchEngine_session(unittest.TestCase):
self.eng.session_manager.insert.return_value = (True, 1)
res = self.eng.add_session(user_id=common.fake_session_0['user_id'],
doc=common.get_fake_session_0())
self.assertEqual(res, common.fake_session_0['session_id'])
self.assertEqual(common.fake_session_0['session_id'], res)
self.eng.session_manager.insert.assert_called_with(
common.fake_session_0,
common.fake_session_0['session_id'])
@ -1224,7 +1232,7 @@ class TestElasticSearchEngine_session(unittest.TestCase):
res = self.eng.delete_session(
user_id=common.fake_session_0['session_id'],
session_id=common.fake_session_0['session_id'])
self.assertEqual(res, common.fake_session_0['session_id'])
self.assertEqual(common.fake_session_0['session_id'], res)
def test_delete_client_raises_StorageEngineError_when_es_delete_raises(
self):
@ -1265,7 +1273,7 @@ class TestElasticSearchEngine_session(unittest.TestCase):
user_id=common.fake_session_0['session_id'],
session_id=common.fake_session_0['session_id'],
patch_doc=patch)
self.assertEqual(res, 11)
self.assertEqual(11, res)
def test_replace_session_raises_AccessForbidden_when_session_manager_raise(
self):
@ -1285,7 +1293,7 @@ class TestElasticSearchEngine_session(unittest.TestCase):
user_id=common.fake_session_0['session_id'],
session_id=common.fake_session_0['session_id'],
doc=common.get_fake_session_0())
self.assertEqual(res, 1)
self.assertEqual(1, res)
def test_replace_session_returns_version_1_when_doc_is_overwritten(self):
self.eng.session_manager.get.return_value = common.get_fake_session_0()
@ -1294,4 +1302,4 @@ class TestElasticSearchEngine_session(unittest.TestCase):
user_id=common.fake_session_0['session_id'],
session_id=common.fake_session_0['session_id'],
doc=common.get_fake_session_0())
self.assertEqual(res, 3)
self.assertEqual(3, res)

@ -37,4 +37,4 @@ class TestHomedocResource(common.FreezerBaseTestCase):
result = json.loads(self.req.data.decode('utf-8'))
print("TEST HOME DOC RESULT: {}".format(result))
expected_result = v1.homedoc.HOME_DOC
self.assertEqual(result, expected_result)
self.assertEqual(expected_result, result)

@ -37,7 +37,7 @@ class TestJobsBaseResource(common.FreezerBaseTestCase):
def test_get_action_returns_found_action(self):
self.mock_db.get_action.return_value = 'awesome_result'
result = self.resource.get_action('user-id', 'action-id')
self.assertEqual(result, 'awesome_result')
self.assertEqual('awesome_result', result)
def test_get_action_returns_none_when_action_not_found(self):
self.mock_db.get_action.side_effect = exceptions.DocumentNotFound(
@ -147,8 +147,8 @@ class TestJobsCollectionResource(common.FreezerBaseTestCase):
expected_result = {'jobs': []}
self.resource.on_get(self.mock_req, self.mock_req)
result = self.mock_req.body
self.assertEqual(result, expected_result)
self.assertEqual(self.mock_req.status, falcon.HTTP_200)
self.assertEqual(expected_result, result)
self.assertEqual(falcon.HTTP_200, self.mock_req.status)
def test_on_get_return_correct_list(self):
self.mock_db.search_job.return_value = [common.get_fake_job_0(),
@ -157,8 +157,8 @@ class TestJobsCollectionResource(common.FreezerBaseTestCase):
'jobs': [common.get_fake_job_0(), common.get_fake_job_1()]}
self.resource.on_get(self.mock_req, self.mock_req)
result = self.mock_req.body
self.assertEqual(result, expected_result)
self.assertEqual(self.mock_req.status, falcon.HTTP_200)
self.assertEqual(expected_result, result)
self.assertEqual(falcon.HTTP_200, self.mock_req.status)
def test_on_post_inserts_correct_data(self):
job = common.get_fake_job_0()
@ -166,8 +166,8 @@ class TestJobsCollectionResource(common.FreezerBaseTestCase):
self.mock_db.add_job.return_value = 'pjiofrdslaikfunr'
expected_result = {'job_id': 'pjiofrdslaikfunr'}
self.resource.on_post(self.mock_req, self.mock_req)
self.assertEqual(self.mock_req.status, falcon.HTTP_201)
self.assertEqual(self.mock_req.body, expected_result)
self.assertEqual(falcon.HTTP_201, self.mock_req.status)
self.assertEqual(expected_result, self.mock_req.body)
class TestJobsResource(common.FreezerBaseTestCase):
@ -190,23 +190,23 @@ class TestJobsResource(common.FreezerBaseTestCase):
self.resource.on_get(self.mock_req, self.mock_req,
common.fake_job_0_job_id)
self.assertIsNone(self.mock_req.body)
self.assertEqual(self.mock_req.status, falcon.HTTP_404)
self.assertEqual(falcon.HTTP_404, self.mock_req.status)
def test_on_get_return_correct_data(self):
self.mock_db.get_job.return_value = common.get_fake_job_0()
self.resource.on_get(self.mock_req, self.mock_req,
common.fake_job_0_job_id)
result = self.mock_req.body
self.assertEqual(result, common.get_fake_job_0())
self.assertEqual(self.mock_req.status, falcon.HTTP_200)
self.assertEqual(common.get_fake_job_0(), result)
self.assertEqual(falcon.HTTP_200, self.mock_req.status)
def test_on_delete_removes_proper_data(self):
self.resource.on_delete(self.mock_req, self.mock_req,
common.fake_job_0_job_id)
result = self.mock_req.body
expected_result = {'job_id': common.fake_job_0_job_id}
self.assertEqual(self.mock_req.status, falcon.HTTP_204)
self.assertEqual(result, expected_result)
self.assertEqual(falcon.HTTP_204, self.mock_req.status)
self.assertEqual(expected_result, result)
def test_on_patch_ok_with_some_fields(self):
new_version = random.randint(0, 99)
@ -224,9 +224,9 @@ class TestJobsResource(common.FreezerBaseTestCase):
user_id=common.fake_job_0_user_id,
job_id=common.fake_job_0_job_id,
patch_doc=patch_doc)
self.assertEqual(self.mock_req.status, falcon.HTTP_200)
self.assertEqual(falcon.HTTP_200, self.mock_req.status)
result = self.mock_req.body
self.assertEqual(result, expected_result)
self.assertEqual(expected_result, result)
def test_on_post_ok(self):
new_version = random.randint(0, 99)
@ -238,8 +238,8 @@ class TestJobsResource(common.FreezerBaseTestCase):
self.resource.on_post(self.mock_req, self.mock_req,
common.fake_job_0_job_id)
self.assertEqual(self.mock_req.status, falcon.HTTP_201)
self.assertEqual(self.mock_req.body, expected_result)
self.assertEqual(falcon.HTTP_201, self.mock_req.status)
self.assertEqual(expected_result, self.mock_req.body)
def test_on_post_raises_when_db_replace_job_raises(self):
self.mock_db.replace_job.side_effect = exceptions.AccessForbidden(
@ -288,8 +288,8 @@ class TestJobsEvent(common.FreezerBaseTestCase):
self.mock_json_body.return_value = event
expected_result = {'result': 'success'}
self.resource.on_post(self.mock_req, self.mock_req, 'my_job_id')
self.assertEqual(self.mock_req.status, falcon.HTTP_202)
self.assertEqual(self.mock_req.body, expected_result)
self.assertEqual(falcon.HTTP_202, self.mock_req.status)
self.assertEqual(expected_result, self.mock_req.body)
class TestJobs(common.FreezerBaseTestCase):
@ -304,8 +304,8 @@ class TestJobs(common.FreezerBaseTestCase):
job_schedule['event'] = event
job = v1_jobs.Job({'job_schedule': job_schedule})
res = job.start()
self.assertEqual(res, response)
self.assertEqual(job.need_update, need_update)
self.assertEqual(response, res)
self.assertEqual(need_update, job.need_update)
def _test_job_stop(self, status, event, response, need_update):
job_schedule = {}
@ -315,8 +315,8 @@ class TestJobs(common.FreezerBaseTestCase):
job_schedule['event'] = event
job = v1_jobs.Job({'job_schedule': job_schedule})
res = job.stop()
self.assertEqual(res, response)
self.assertEqual(job.need_update, need_update)
self.assertEqual(response, res)
self.assertEqual(need_update, job.need_update)
def _test_job_abort(self, status, event, response, need_update):
job_schedule = {}
@ -326,8 +326,8 @@ class TestJobs(common.FreezerBaseTestCase):
job_schedule['event'] = event
job = v1_jobs.Job({'job_schedule': job_schedule})
res = job.abort()
self.assertEqual(res, response)
self.assertEqual(job.need_update, need_update)
self.assertEqual(response, res)
self.assertEqual(need_update, job.need_update)
def test_start_scheduled_unstarted_job(self):
self._test_job_start(status='scheduled',
@ -567,4 +567,4 @@ class TestJobs(common.FreezerBaseTestCase):
'job_schedule': {}
}
job = v1_jobs.Job(job_doc)
self.assertEqual(job.doc, expected_job_doc)
self.assertEqual(expected_job_doc, job.doc)

@ -45,8 +45,8 @@ class TestSessionsCollectionResource(common.FreezerBaseTestCase):
expected_result = {'sessions': []}
self.resource.on_get(self.mock_req, self.mock_req)
result = self.mock_req.body
self.assertEqual(result, expected_result)
self.assertEqual(self.mock_req.status, falcon.HTTP_200)
self.assertEqual(expected_result, result)
self.assertEqual(falcon.HTTP_200, self.mock_req.status)
def test_on_get_return_correct_list(self):
self.mock_db.search_session.return_value = [
@ -55,8 +55,8 @@ class TestSessionsCollectionResource(common.FreezerBaseTestCase):
common.get_fake_session_1()]}
self.resource.on_get(self.mock_req, self.mock_req)
result = self.mock_req.body
self.assertEqual(result, expected_result)
self.assertEqual(self.mock_req.status, falcon.HTTP_200)
self.assertEqual(expected_result, result)
self.assertEqual(falcon.HTTP_200, self.mock_req.status)
def test_on_post_raises_when_missing_body(self):
self.mock_db.add_session.return_value = common.fake_session_0[
@ -70,8 +70,8 @@ class TestSessionsCollectionResource(common.FreezerBaseTestCase):
self.mock_db.add_session.return_value = 'pjiofrdslaikfunr'
expected_result = {'session_id': 'pjiofrdslaikfunr'}
self.resource.on_post(self.mock_req, self.mock_req)
self.assertEqual(self.mock_req.status, falcon.HTTP_201)
self.assertEqual(self.mock_req.body, expected_result)
self.assertEqual(falcon.HTTP_201, self.mock_req.status)
self.assertEqual(expected_result, self.mock_req.body)
class TestSessionsResource(common.FreezerBaseTestCase):
@ -97,23 +97,23 @@ class TestSessionsResource(common.FreezerBaseTestCase):
self.resource.on_get(self.mock_req, self.mock_req,
common.fake_session_0['session_id'])
self.assertIsNone(self.mock_req.body)
self.assertEqual(self.mock_req.status, falcon.HTTP_404)
self.assertEqual(falcon.HTTP_404, self.mock_req.status)
def test_on_get_return_correct_data(self):
self.mock_db.get_session.return_value = common.get_fake_session_0()
self.resource.on_get(self.mock_req, self.mock_req,
common.fake_session_0['session_id'])
result = self.mock_req.body
self.assertEqual(result, common.get_fake_session_0())
self.assertEqual(self.mock_req.status, falcon.HTTP_200)
self.assertEqual(common.get_fake_session_0(), result)
self.assertEqual(falcon.HTTP_200, self.mock_req.status)
def test_on_delete_removes_proper_data(self):
self.resource.on_delete(self.mock_req, self.mock_req,
common.fake_session_0['session_id'])
result = self.mock_req.body
expected_result = {'session_id': common.fake_session_0['session_id']}
self.assertEqual(self.mock_req.status, falcon.HTTP_204)
self.assertEqual(result, expected_result)
self.assertEqual(falcon.HTTP_204, self.mock_req.status)
self.assertEqual(expected_result, result)
def test_on_patch_ok_with_some_fields(self):
new_version = random.randint(0, 99)
@ -131,9 +131,9 @@ class TestSessionsResource(common.FreezerBaseTestCase):
user_id=common.fake_session_0['user_id'],
session_id=common.fake_session_0['session_id'],
patch_doc=patch_doc)
self.assertEqual(self.mock_req.status, falcon.HTTP_200)
self.assertEqual(falcon.HTTP_200, self.mock_req.status)
result = self.mock_req.body
self.assertEqual(result, expected_result)
self.assertEqual(expected_result, result)
def test_on_post_ok(self):
new_version = random.randint(0, 99)
@ -145,8 +145,8 @@ class TestSessionsResource(common.FreezerBaseTestCase):
self.resource.on_post(self.mock_req, self.mock_req,
common.fake_session_0['session_id'])
self.assertEqual(self.mock_req.status, falcon.HTTP_201)
self.assertEqual(self.mock_req.body, expected_result)
self.assertEqual(falcon.HTTP_201, self.mock_req.status)
self.assertEqual(expected_result, self.mock_req.body)
def test_on_post_raises_when_db_replace_session_raises(self):
self.mock_db.replace_session.side_effect = exceptions.AccessForbidden(
@ -197,8 +197,8 @@ class TestSessionsAction(common.FreezerBaseTestCase):
'session_tag': 6}
self.resource.on_post(self.mock_req, self.mock_req,
common.fake_session_0['session_id'])
self.assertEqual(self.mock_req.status, falcon.HTTP_202)
self.assertEqual(self.mock_req.body, expected_result)
self.assertEqual(falcon.HTTP_202, self.mock_req.status)
self.assertEqual(expected_result, self.mock_req.body)
def test_on_post_start_action_raises_BadDataFormat_when_job_not_in_session(
self):
@ -242,8 +242,8 @@ class TestSessionsAction(common.FreezerBaseTestCase):
'session_tag': 5}
self.resource.on_post(self.mock_req, self.mock_req,
common.fake_session_0['session_id'])
self.assertEqual(self.mock_req.status, falcon.HTTP_202)
self.assertEqual(self.mock_req.body, expected_result)
self.assertEqual(falcon.HTTP_202, self.mock_req.status)
self.assertEqual(expected_result, self.mock_req.body)
def test_on_post_end_action_raises_BadDataFormat_when_job_not_in_session(
self):
@ -293,8 +293,8 @@ class TestSessionsAction(common.FreezerBaseTestCase):
'session_tag': 5}
self.resource.on_post(self.mock_req, self.mock_req,
common.fake_session_0['session_id'])
self.assertEqual(self.mock_req.status, falcon.HTTP_202)
self.assertEqual(self.mock_req.body, expected_result)
self.assertEqual(falcon.HTTP_202, self.mock_req.status)
self.assertEqual(expected_result, self.mock_req.body)
@patch('freezer_api.api.v1.sessions.time')
def test_on_post_start_replies_holdoff_if_tag_would_increment(self,
@ -314,8 +314,8 @@ class TestSessionsAction(common.FreezerBaseTestCase):
'session_tag': 5}
self.resource.on_post(self.mock_req, self.mock_req,
common.fake_session_0['session_id'])
self.assertEqual(self.mock_req.status, falcon.HTTP_202)
self.assertEqual(self.mock_req.body, expected_result)
self.assertEqual(falcon.HTTP_202, self.mock_req.status)
self.assertEqual(expected_result, self.mock_req.body)
@patch('freezer_api.api.v1.sessions.time')
def test_on_post_start_outofholdoff_replies_outofsync_when_tag_too_low(
@ -335,8 +335,8 @@ class TestSessionsAction(common.FreezerBaseTestCase):
'session_tag': 5}
self.resource.on_post(self.mock_req, self.mock_req,
common.fake_session_0['session_id'])
self.assertEqual(self.mock_req.status, falcon.HTTP_202)
self.assertEqual(self.mock_req.body, expected_result)
self.assertEqual(falcon.HTTP_202, self.mock_req.status)
self.assertEqual(expected_result, self.mock_req.body)
class TestSessions(common.FreezerBaseTestCase):
@ -354,7 +354,7 @@ class TestSessions(common.FreezerBaseTestCase):
'job2': {'status': 'running',
'result': ''}}
res = self.session.get_job_overall_result()
self.assertEqual(res, 'running')
self.assertEqual('running', res)
def test_overall_result_fail(self):
self.session_doc['jobs'] = {'job1': {'status': 'completed',
@ -362,7 +362,7 @@ class TestSessions(common.FreezerBaseTestCase):
'job2': {'status': 'completed',
'result': 'fail'}}
res = self.session.get_job_overall_result()
self.assertEqual(res, 'fail')
self.assertEqual('fail', res)
def test_overall_result_success(self):
self.session_doc['jobs'] = {'job1': {'status': 'completed',
@ -370,7 +370,7 @@ class TestSessions(common.FreezerBaseTestCase):
'job2': {'status': 'completed',
'result': 'success'}}
res = self.session.get_job_overall_result()
self.assertEqual(res, 'success')
self.assertEqual('success', res)
class TestSessionsJobs(common.FreezerBaseTestCase):

@ -160,12 +160,12 @@ class TestJobDoc(unittest.TestCase):
job_doc = common.get_fake_job_0()
job_doc['job_schedule']['status'] = 'stop'
res_doc = utils.JobDoc.create(job_doc, 'dude')
self.assertEqual(res_doc['job_schedule']['time_created'], 1433611337)
self.assertEqual(res_doc['job_schedule']['time_started'], -1)
self.assertEqual(res_doc['job_schedule']['time_ended'], -1)
self.assertEqual(res_doc['job_schedule']['status'], 'stop')
self.assertEqual(res_doc['user_id'], 'dude')
self.assertEqual(res_doc['job_id'], 'hotforteacher')
self.assertEqual(1433611337, res_doc['job_schedule']['time_created'])
self.assertEqual(-1, res_doc['job_schedule']['time_started'])
self.assertEqual(-1, res_doc['job_schedule']['time_ended'])
self.assertEqual('stop', res_doc['job_schedule']['status'])
self.assertEqual('dude', res_doc['user_id'])
self.assertEqual('hotforteacher', res_doc['job_id'])
@patch('freezer_api.common.utils.uuid')
@patch('freezer_api.common.utils.time')
@ -229,8 +229,8 @@ class TestActionDoc(unittest.TestCase):
action_doc = common.get_fake_action_0()
action_doc.pop('action_id')
res_doc = utils.ActionDoc.create(action_doc, 'dude')
self.assertEqual(res_doc['user_id'], 'dude')
self.assertEqual(res_doc['action_id'], 'hotforteacher')
self.assertEqual('dude', res_doc['user_id'])
self.assertEqual('hotforteacher', res_doc['action_id'])
@patch('freezer_api.common.utils.uuid')
def test_create_raises_BadDataFormat_when_isvalid_fails(self, mock_uuid):
@ -290,8 +290,8 @@ class TestSessionDoc(unittest.TestCase):
mock_uuid.hex = 'hotforteacher'
session_doc = common.get_fake_session_0()
res_doc = utils.SessionDoc.create(session_doc, 'dude')
self.assertEqual(res_doc['user_id'], 'dude')
self.assertEqual(res_doc['session_id'], 'hotforteacher')
self.assertEqual('dude', res_doc['user_id'])
self.assertEqual('hotforteacher', res_doc['session_id'])
@patch('freezer_api.common.utils.uuid')
def test_create_raises_BadDataFormat_when_isvalid_fails(self, mock_uuid):

@ -36,6 +36,6 @@ class TestVersionResource(common.FreezerBaseTestCase):
def test_on_get_return_versions(self):
self.resource.on_get(self.req, self.req)
self.assertEqual(self.req.status, falcon.HTTP_300)
self.assertEqual(falcon.HTTP_300, self.req.status)
expected_result = json.dumps({'versions': [v2.VERSION]})
self.assertEqual(self.req.data, expected_result)
self.assertEqual(expected_result, self.req.data)

Loading…
Cancel
Save