-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revive and clean up repocleaner tests (#2468)
* Update the tests * Revive tests - Fix the tests - Put common code in a common place - Move tests related files in `tests` * Update README.md * extract the ccdb-test url to test_utils organize imports move tests data to tests directory * Update requirements.txt
- Loading branch information
1 parent
1cda518
commit 036bc2f
Showing
15 changed files
with
239 additions
and
318 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
certifi==2024.2.2 | ||
chardet==5.2.0 | ||
charset-normalizer==3.3.2 | ||
dryable==1.2.0 | ||
idna==3.7 | ||
psutil==6.1.0 | ||
python-consul==1.1.0 | ||
PyYAML==6.0.1 | ||
requests==2.31.0 | ||
responses==0.25.0 | ||
six==1.16.0 | ||
urllib3==2.2.1 |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,48 @@ | ||
import logging | ||
import unittest | ||
import requests | ||
from typing import List | ||
|
||
import responses | ||
|
||
from Ccdb import Ccdb, ObjectVersion | ||
from rules import production | ||
from qcrepocleaner.Ccdb import Ccdb, ObjectVersion | ||
from tests.test_utils import CCDB_TEST_URL | ||
|
||
|
||
class TestCcdb(unittest.TestCase): | ||
|
||
def setUp(self): | ||
with open('../qcrepocleaner/objectsList.json') as f: # will close() when we leave this block | ||
with open('objectsList.json') as f: # will close() when we leave this block | ||
self.content_objectslist = f.read() | ||
with open('../versionsList.json') as f: # will close() when we leave this block | ||
with open('versionsList.json') as f: # will close() when we leave this block | ||
self.content_versionslist = f.read() | ||
self.ccdb = Ccdb('http://ccdb-test.cern.ch:8080') | ||
self.ccdb = Ccdb(CCDB_TEST_URL) | ||
logging.getLogger().setLevel(logging.DEBUG) | ||
|
||
@responses.activate | ||
def test_getObjectsList(self): | ||
# Prepare mock response | ||
responses.add(responses.GET, 'http://ccdb-test.cern.ch:8080/latest/.*', | ||
responses.add(responses.GET, CCDB_TEST_URL + '/latest/.*', | ||
self.content_objectslist, status=200) | ||
# get list of objects | ||
objectsList = self.ccdb.getObjectsList() | ||
print(f"{objectsList}") | ||
self.assertEqual(len(objectsList), 3) | ||
self.assertEqual(objectsList[0], 'Test') | ||
self.assertEqual(objectsList[1], 'ITSQcTask/ChipStaveCheck') | ||
objects_list = self.ccdb.getObjectsList() | ||
print(f"{objects_list}") | ||
self.assertEqual(len(objects_list), 3) | ||
self.assertEqual(objects_list[0], 'Test') | ||
self.assertEqual(objects_list[1], 'ITSQcTask/ChipStaveCheck') | ||
|
||
@responses.activate | ||
def test_getVersionsList(self): | ||
# Prepare mock response | ||
object_path='asdfasdf/example' | ||
responses.add(responses.GET, 'http://ccdb-test.cern.ch:8080/browse/'+object_path, | ||
responses.add(responses.GET, CCDB_TEST_URL + '/browse/'+object_path, | ||
self.content_versionslist, status=200) | ||
# get versions for object | ||
versionsList: List[ObjectVersion] = self.ccdb.getVersionsList(object_path) | ||
print(f"{versionsList}") | ||
self.assertEqual(len(versionsList), 2) | ||
self.assertEqual(versionsList[0].path, object_path) | ||
self.assertEqual(versionsList[1].path, object_path) | ||
self.assertEqual(versionsList[1].metadata["custom"], "34") | ||
versions_list: List[ObjectVersion] = self.ccdb.getVersionsList(object_path) | ||
print(f"{versions_list}") | ||
self.assertEqual(len(versions_list), 2) | ||
self.assertEqual(versions_list[0].path, object_path) | ||
self.assertEqual(versions_list[1].path, object_path) | ||
self.assertEqual(versions_list[1].metadata["custom"], "34") | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |
Oops, something went wrong.