def test_QueryBackAllTicketsOfType(self): setup = self.setupTenantsTicketTypesAndTickets() resultJSON = self.queryForTickets( tenantName=setup["tenants"][0]["tenantJSON"]["Name"], ticketTypeID=setup["tenants"][0]["ticketTypes"][1] ["createTicketTypeResult"]["id"], queryString=None) self.assertEqual(len(resultJSON), 6, msg="Wrong number of tickets returned") issuedTicketIDS = [] for curCreationRes in setup["tenants"][0]["ticketTypes"][1][ "ticketCreationProcessResult"]["results"]: issuedTicketIDS.append(curCreationRes["ticketGUID"]) queriedTicketIDS = [] for curResult in resultJSON: queriedTicketIDS.append(curResult["id"]) python_Testing_Utilities.assertObjectsEqual( unittestTestCaseClass=self, first=issuedTicketIDS, second=queriedTicketIDS, msg="Different tickets queried back", ignoredRootKeys=[])
def test_GetTicketOfDisabledTicketType(self): testTime1 = datetime.datetime.now(pytz.timezone("UTC")) appObj.setTestingDateTime(testTime1) setup = self.setupTenantsTicketTypesAndTickets() tenantUsedInTest = setup["tenants"][0] tenantName = tenantUsedInTest["tenantJSON"]["Name"] ticketTypeUsedInTest=tenantUsedInTest["ticketTypes"][1] ticketTypeID=tenantUsedInTest["ticketTypes"][1]["createTicketTypeResult"]["id"] ticketTypeName=tenantUsedInTest["ticketTypes"][1]["createTicketTypeResult"]["ticketTypeName"] ticketUsedInTest=tenantUsedInTest["ticketTypes"][1]["ticketCreationProcessResult"]["results"][1] ticketGUID=tenantUsedInTest["ticketTypes"][1]["ticketCreationProcessResult"]["results"][1]["ticketGUID"] ticketForeignKey=tenantUsedInTest["ticketTypes"][1]["ticketCreationProcessResult"]["results"][1]["foreignKey"] ticketTypeUsedInTest["createTicketTypeResult"] = self.setEnabledForTicketType(ticketType=ticketTypeUsedInTest["createTicketTypeResult"], newValue=False) result = self.testClient.get( self.loginAPIPrefix + '/' + tenantName + '/tickets/' + ticketGUID, headers={"Origin": TestHelperSuperClass.httpOrigin} ) self.assertEqual(result.status_code, 200) resultJSON = json.loads(result.get_data(as_text=True)) expectedResult = { "ticketType": copy.deepcopy(ticketTypeUsedInTest["createTicketTypeResult"]), "isUsable": "INVALID", "expiry": (testTime1 + datetime.timedelta(hours=int(ticketTypeUsedInTest["createTicketTypeResult"]["issueDuration"]))).isoformat() } python_Testing_Utilities.assertObjectsEqual( unittestTestCaseClass=self, first=resultJSON, second=expectedResult, msg="Didn't get expected result", ignoredRootKeys=[] )
def test_createValidTicketType(self): testTime = datetime.datetime.now(pytz.timezone("UTC")) appObj.setTestingDateTime(testTime) resultJSON = self.createTicketType(constants.masterTenantName) expectedResult = copy.deepcopy( ticketManagerTestCommon.validTicketTypeDict) expectedResult["id"] = resultJSON["id"] expectedResult[object_store_abstraction.RepositoryObjBaseClass. getMetadataElementKey()] = { "creationDateTime": testTime.isoformat(), "lastUpdateDateTime": testTime.isoformat(), "objectKey": resultJSON["id"], "objectVersion": "1" } python_Testing_Utilities.assertObjectsEqual( unittestTestCaseClass=self, first=resultJSON, second=expectedResult, msg="JSON of created Ticket Type is not the same", ignoredRootKeys=[]) self.assertJSONStringsEqualWithIgnoredKeys( resultJSON, expectedResult, [], msg='JSON of created Ticket Type is not the same') #Not get the ticket type we just created and make sure it matches resultJSON2 = self.getTicketType(constants.masterTenantName, resultJSON["id"]) self.assertJSONStringsEqualWithIgnoredKeys(resultJSON2, expectedResult, [], msg='Get retrevial failed')
def test_infoEndpoint(self): #call rsults as /api/public/info/serverinfo apiResultTMP = self.assertInfoAPIResult( methodFN=self.testClient.get, url="/serverinfo", session=None, data=None ) self.assertEqual(apiResultTMP.status_code, 200) apiResult = json.loads(apiResultTMP.get_data(as_text=True)) expectedRes = { 'Server': { 'APIAPP_APIDOCSURL': '_', 'Version': 'TEST-3.3.3', 'APIAPP_FRONTENDURL': TestHelperSuperClass.env['APIAPP_FRONTENDURL'] }, 'Derived': { } } python_Testing_Utilities.assertObjectsEqual( unittestTestCaseClass=self, first=apiResult, second=expectedRes, msg="Server Info return wrong", ignoredRootKeys=[] )
def test_assertObjectsEqual(self): # basic check that we can call and keys are ignored obj1 = {"A": "a"} obj2 = {"A": "a", "id": "dddd"} undertest.assertObjectsEqual(unittestTestCaseClass=self, first=obj1, second=obj2, msg="Failed", ignoredRootKeys=["id"])
def test_createSingleValidTicket(self): testTime1 = datetime.datetime.now(pytz.timezone("UTC")) appObj.setTestingDateTime(testTime1) testTicketTypeName = "TestType001" setupData = self.setupNewTenantAndTicketType(tenantData=TestHelperSuperClass.tenantWithNoAuthProviders, ticketTypeName=testTicketTypeName) testTime2 = datetime.datetime.now(pytz.timezone("UTC")) appObj.setTestingDateTime(testTime2) resultJSON = self.callBatchProcess( tenantName=setupData["ticketTypeNewTanent"]["tenantName"], ticketTypeID=setupData["ticketTypeNewTanent"]["id"], foreignKeyList= [ "*****@*****.**" ], foreignKeyDupAction= "ReissueAllActive", checkAndParseResponse = True ) self.checkExpectedResults(resultJSON=resultJSON, keysExpected=[ "*****@*****.**" ], issued=1, reissued=0, skipped=0, msg="None") ticketsJSON = self.queryForTickets( tenantName=setupData["ticketTypeNewTanent"]["tenantName"], ticketTypeID=setupData["ticketTypeNewTanent"]["id"], queryString="*****@*****.**" ) self.assertEqual(len(ticketsJSON), 1, msg="Should have found a single ticket") expectedTicketJSON = { "id": resultJSON["results"][0]["ticketGUID"], "typeGUID": setupData["ticketTypeNewTanent"]["id"], "expiry": (testTime2 + datetime.timedelta(hours=int(setupData["ticketTypeNewTanent"]["issueDuration"]))).isoformat(), "foreignKey": "*****@*****.**", "usedDate": None, "useWithUserID": None, "reissueRequestedDate": None, "reissuedTicketID": None, "disabled": False, object_store_abstraction.RepositoryObjBaseClass.getMetadataElementKey(): { "creationDateTime": testTime2.isoformat(), "lastUpdateDateTime": testTime2.isoformat(), "objectKey": resultJSON["results"][0]["ticketGUID"], "objectVersion": "1" }, "usableState": "US_USABLEIFTICKETTYPEISENABLED" } python_Testing_Utilities.assertObjectsEqual( unittestTestCaseClass=self, first=ticketsJSON[0], second=expectedTicketJSON, msg="JSON of created Ticket is not what was expected", ignoredRootKeys=[] )
def test_createSingleValidTicketTwiceAndCheckWeHaveTwoTickets(self): testTime1 = datetime.datetime.now(pytz.timezone("UTC")) appObj.setTestingDateTime(testTime1) testTicketTypeName = "TestType001" setupData = self.setupNewTenantAndTicketType(tenantData=TestHelperSuperClass.tenantWithNoAuthProviders, ticketTypeName=testTicketTypeName) foreignKeyList001 = ["*****@*****.**"] foreignKeyList002 = ["*****@*****.**"] testTime2 = datetime.datetime.now(pytz.timezone("UTC")) appObj.setTestingDateTime(testTime2) resultJSON = self.callBatchProcess( tenantName=setupData["ticketTypeNewTanent"]["tenantName"], ticketTypeID=setupData["ticketTypeNewTanent"]["id"], foreignKeyList= foreignKeyList001, foreignKeyDupAction= "ReissueAllActive", checkAndParseResponse = True ) self.checkExpectedResults(resultJSON=resultJSON, keysExpected=foreignKeyList001, issued=1, reissued=0, skipped=0, msg="None") testTime3 = datetime.datetime.now(pytz.timezone("UTC")) appObj.setTestingDateTime(testTime2) resultJSON = self.callBatchProcess( tenantName=setupData["ticketTypeNewTanent"]["tenantName"], ticketTypeID=setupData["ticketTypeNewTanent"]["id"], foreignKeyList= foreignKeyList002, foreignKeyDupAction= "ReissueAllActive", checkAndParseResponse = True ) self.checkExpectedResults(resultJSON=resultJSON, keysExpected=foreignKeyList002, issued=1, reissued=0, skipped=0, msg="None") ticketsJSON = self.queryForTickets( tenantName=setupData["ticketTypeNewTanent"]["tenantName"], ticketTypeID=setupData["ticketTypeNewTanent"]["id"], queryString=None ) self.assertEqual(len(ticketsJSON), 2, msg="Should have found two tickets") allKeys = [] for curTicket in ticketsJSON: allKeys.append(curTicket["foreignKey"]) python_Testing_Utilities.assertObjectsEqual( unittestTestCaseClass=self, first=allKeys, second=foreignKeyList001 + foreignKeyList002, msg="JSON of created Ticket is not what was expected", ignoredRootKeys=[] )
def test_CreateAPIKeyandQueryBack(self): # Create APIKey and query back works # Query back API key dosen't contain apikey setupData = self.setup() user = setupData["users"][0] apiKeyDataToUse = user["APIKeyCreationResults"][0]["res"]["apikeydata"] retrievedAPIKeyJSON = self.getAPIKey( tenant=apiKeyDataToUse["tenantName"], userAuthToken=user["userAuthToken"], apiKeyID=apiKeyDataToUse["id"]) python_Testing_Utilities.assertObjectsEqual( unittestTestCaseClass=self, first=retrievedAPIKeyJSON, second=user["APIKeyCreationResults"][0]["res"]["apikeydata"], msg="Didn't get expected result", ignoredRootKeys=[])
def test_assertObjectsEqualBytes(self): # check bytes objects obj1 = b"abc" obj2 = b"abc" obj3 = b"def" undertest.assertObjectsEqual(unittestTestCaseClass=self, first=obj1, second=obj2, msg="Failed", ignoredRootKeys=[]) try: undertest.assertObjectsEqual(unittestTestCaseClass=self, first=obj1, second=obj3, msg="Failed", ignoredRootKeys=[]) except AssertionError: gotExp = True self.assertTrue(gotExp, msg="AssertionError not raised")
def test_updateTicketType(self): testTime1 = datetime.datetime.now(pytz.timezone("UTC")) appObj.setTestingDateTime(testTime1) setupData = self.setupTestTicketsInTwoTenants() testTime2 = datetime.datetime.now(pytz.timezone("UTC")) appObj.setTestingDateTime(testTime2) changed = copy.deepcopy(setupData["okTicketResultJSON"][1]) changed["ticketTypeName"] = "okTicketResultJSONUPDATED" resultJSON = self.updateTicketType( ticketTypeID=setupData["okTicketResultJSON"][1]["id"], ticketTypeTenant=constants.masterTenantName, newDict=changed) expectedResult = copy.deepcopy(changed) expectedResult["id"] = resultJSON["id"] expectedResult[object_store_abstraction.RepositoryObjBaseClass. getMetadataElementKey()] = { "creationDateTime": testTime1.isoformat(), "lastUpdateDateTime": testTime2.isoformat(), "objectKey": resultJSON["id"], "objectVersion": "2" #We expect an updated object } python_Testing_Utilities.assertObjectsEqual( unittestTestCaseClass=self, first=resultJSON, second=expectedResult, msg="JSON of created Ticket Type is not the same", ignoredRootKeys=[]) #Not get the ticket type we just created and make sure it matches resultJSON2 = self.getTicketType( constants.masterTenantName, setupData["okTicketResultJSON"][1]["id"]) self.assertJSONStringsEqualWithIgnoredKeys( resultJSON2, expectedResult, [], msg='Get retrevial mismatch')
def test_queryBackSingleDisabledTicket(self): testTime1 = datetime.datetime.now(pytz.timezone("UTC")) appObj.setTestingDateTime(testTime1) setup = self.setupTenantsTicketTypesAndTickets() ticketTypeToQueryBack = setup["tenants"][0]["ticketTypes"][1] ticketToDisable = ticketTypeToQueryBack["ticketCreationProcessResult"][ "results"][4] disabledTicketID = ticketToDisable["ticketGUID"] disabledForeignKey = ticketToDisable["foreignKey"] #We need to find the object version number for this ticket resultJSON = self.queryForTickets( tenantName=setup["tenants"][0]["tenantJSON"]["Name"], ticketTypeID=setup["tenants"][0]["ticketTypes"][1] ["createTicketTypeResult"]["id"], queryString=disabledForeignKey) self.assertEqual(len(resultJSON), 1, msg="Wrong number of tickets returned") self.assertEqual(resultJSON[0]["id"], disabledTicketID) self.assertEqual(resultJSON[0]["foreignKey"], disabledForeignKey) testTime2 = datetime.datetime.now(pytz.timezone("UTC")) appObj.setTestingDateTime(testTime2) disabledObjectVersion = resultJSON[0][ object_store_abstraction.RepositoryObjBaseClass. getMetadataElementKey()]["objectVersion"] disableResultJSON = self.disableTicket( tenantName=ticketTypeToQueryBack["createTicketTypeResult"] ["tenantName"], ticketTypeID=ticketTypeToQueryBack["createTicketTypeResult"]["id"], ticketID=disabledTicketID, objectVersionNumber=disabledObjectVersion, checkAndParseResponse=True) expectedDisableResult = { "response": "OK", "message": "OK", "results": [{ "ticketGUID": disabledTicketID, "response": "OK", "message": "OK" }] } python_Testing_Utilities.assertObjectsEqual( unittestTestCaseClass=self, first=disableResultJSON, second=expectedDisableResult, msg="Disable basic result wrong", ignoredRootKeys=["results"]) self.assertEqual(len(disableResultJSON["results"]), 1) python_Testing_Utilities.assertObjectsEqual( unittestTestCaseClass=self, first=disableResultJSON["results"][0], second=expectedDisableResult["results"][0], msg="Disable result wrong", ignoredRootKeys=[]) #5 tickets should not be disabled, one has is. ## Query back the 5 not disabled resultJSON = self.queryForTickets( tenantName=setup["tenants"][0]["tenantJSON"]["Name"], ticketTypeID=setup["tenants"][0]["ticketTypes"][1] ["createTicketTypeResult"]["id"], queryString="US_USABLEIFTICKETTYPEISENABLED") self.assertEqual(len(resultJSON), 5, msg="Wrong number of tickets returned") #Query back the one disabled resultJSON = self.queryForTickets( tenantName=setup["tenants"][0]["tenantJSON"]["Name"], ticketTypeID=setup["tenants"][0]["ticketTypes"][1] ["createTicketTypeResult"]["id"], queryString="US_DISABLED") self.assertEqual(len(resultJSON), 1, msg="Wrong number of tickets returned") self.assertEqual(resultJSON[0]["id"], disabledTicketID) self.assertEqual(resultJSON[0]["foreignKey"], disabledForeignKey)
def test_createSameSingleValidTicketTwiceAndCheckWeHaveOneTicket_inReissueMode(self): testTime1 = datetime.datetime.now(pytz.timezone("UTC")) appObj.setTestingDateTime(testTime1) testTicketTypeName = "TestType001" setupData = self.setupNewTenantAndTicketType(tenantData=TestHelperSuperClass.tenantWithNoAuthProviders, ticketTypeName=testTicketTypeName) foreignKeyList001 = ["*****@*****.**"] testTime2 = datetime.datetime.now(pytz.timezone("UTC")) appObj.setTestingDateTime(testTime2) resultJSON = self.callBatchProcess( tenantName=setupData["ticketTypeNewTanent"]["tenantName"], ticketTypeID=setupData["ticketTypeNewTanent"]["id"], foreignKeyList= foreignKeyList001, foreignKeyDupAction= "ReissueAllActive", checkAndParseResponse = True ) self.checkExpectedResults(resultJSON=resultJSON, keysExpected=foreignKeyList001, issued=1, reissued=0, skipped=0, msg="None") origTicketID = resultJSON["results"][0]["ticketGUID"] testTime3 = datetime.datetime.now(pytz.timezone("UTC")) appObj.setTestingDateTime(testTime2) resultJSON = self.callBatchProcess( tenantName=setupData["ticketTypeNewTanent"]["tenantName"], ticketTypeID=setupData["ticketTypeNewTanent"]["id"], foreignKeyList= foreignKeyList001, foreignKeyDupAction= "ReissueAllActive", checkAndParseResponse = True ) self.checkExpectedResults(resultJSON=resultJSON, keysExpected=foreignKeyList001, issued=0, reissued=1, skipped=0, msg="None") reissuedTicketID = resultJSON["results"][0]["ticketGUID"] ticketsJSON = self.queryForTickets( tenantName=setupData["ticketTypeNewTanent"]["tenantName"], ticketTypeID=setupData["ticketTypeNewTanent"]["id"], queryString=None # results in all being returned ) self.assertEqual(len(ticketsJSON), 2, msg="Should have found two tickets because previous and new") allKeys = [] for curTicket in ticketsJSON: allKeys.append(curTicket["foreignKey"]) python_Testing_Utilities.assertObjectsEqual( unittestTestCaseClass=self, first=allKeys, second=foreignKeyList001 + foreignKeyList001, msg="JSON of created Ticket is not what was expected", ignoredRootKeys=[] ) #Make sure old ticket has new tickets reissueID origTicket = None for curTicket in ticketsJSON: if curTicket["id"] == origTicketID: if origTicket is not None: self.assertTrue(False, msg="There should not be mutiple orig tickets in query result") origTicket = curTicket self.assertEqual(origTicket["reissuedTicketID"], reissuedTicketID, msg="Reissued ID not set on original ticket") #TODO And transfer to another file # dest