def test_add_account_via_patch_fail2(self): self.session.post.return_value.status_code = ( requests.codes.METHOD_NOT_ALLOWED) self.session.patch.return_value.status_code = ( requests.codes.BAD_REQUEST) user, pwd, uri = accounts.add_account(self.sut, self.session) self.assertIsNone(uri)
def test_add_account_no_collection(self, mock_logging_error): self.sut.set_nav_prop_uri('Accounts', None) user, pwd, uri = accounts.add_account(self.sut, self.session) self.assertIsNone(user) self.assertIsNone(uri) self.assertEqual(mock_logging_error.call_count, 1) args = mock_logging_error.call_args[0] self.assertIn('No accounts collection found', args[0])
def test_add_account_via_patch_pass(self): self.session.post.return_value.status_code = ( requests.codes.METHOD_NOT_ALLOWED) self.session.patch.return_value.status_code = requests.codes.OK user, pwd, uri = accounts.add_account(self.sut, self.session) self.assertEqual(len(user), 8) self.assertTrue(user.startswith('rfpv')) self.assertEqual(uri, self.account_uri3)
def create_account(sut: SystemUnderTest, session, request_type=RequestType.NORMAL): # Create test account user, password, new_acct_uri = acct.add_account(sut, session, request_type=request_type) return user, password, new_acct_uri
def test_add_account_pass(self): new_uri = '/redfish/v1/AccountService/Accounts/4' self.session.post.return_value.status_code = requests.codes.CREATED self.session.post.return_value.headers = { 'Location': self.sut.rhost + new_uri } user, pwd, uri = accounts.add_account(self.sut, self.session) self.assertEqual(len(user), 8) self.assertTrue(user.startswith('rfpv')) self.assertEqual(uri, new_uri)
def test_add_account_collection_get_fail(self, mock_logging_error): add_response(self.sut, self.accounts_uri, json={}, status_code=requests.codes.NOT_FOUND) user, pwd, uri = accounts.add_account(self.sut, self.session) self.assertIsNone(user) self.assertIsNone(uri) self.assertEqual(mock_logging_error.call_count, 1) args = mock_logging_error.call_args[0] self.assertIn('Accounts collection could not be read', args[0])
def test_add_account_via_patch_enable(self): etag = '0123456789abcdef' self.session.get.return_value.status_code = requests.codes.OK self.session.get.return_value.ok = True self.session.get.return_value.json.return_value = {'Enabled': False} self.session.get.return_value.headers = {'ETag': etag} self.session.post.return_value.status_code = ( requests.codes.METHOD_NOT_ALLOWED) self.session.patch.return_value.status_code = requests.codes.OK user, pwd, uri = accounts.add_account(self.sut, self.session) self.session.patch.assert_called_with(self.sut.rhost + self.account_uri3, json={'Enabled': True}, headers={'If-Match': etag})
def test_add_account_via_patch_fail1(self, mock_logging_error): payload = {'UserName': '******', 'Enabled': True} add_response(self.sut, self.account_uri3, json=payload, res_type=ResourceType.MANAGER_ACCOUNT) self.session.post.return_value.status_code = ( requests.codes.METHOD_NOT_ALLOWED) self.session.patch.return_value.status_code = requests.codes.OK user, pwd, uri = accounts.add_account(self.sut, self.session) self.assertIsNone(user) self.assertIsNone(uri) self.assertEqual(mock_logging_error.call_count, 1) args = mock_logging_error.call_args[0] self.assertIn('No empty account slot found', args[0])
def test_add_account_collection_allow_header_no_post(self): payload = { 'Members': [{ '@odata.id': self.account_uri1 }, { '@odata.id': self.account_uri2 }, { '@odata.id': self.account_uri3 }] } headers = {'Allow': 'GET'} add_response(self.sut, self.accounts_uri, json=payload, headers=headers) self.session.patch.return_value.status_code = requests.codes.OK user, pwd, uri = accounts.add_account(self.sut, self.session) self.assertEqual(len(user), 8) self.assertTrue(user.startswith('rfpv')) self.assertEqual(uri, self.account_uri3)
def test_add_account_collection_allow_header_post(self): payload = { 'Members': [{ '@odata.id': self.account_uri1 }, { '@odata.id': self.account_uri2 }, { '@odata.id': self.account_uri3 }] } headers = {'Allow': 'GET, POST'} add_response(self.sut, self.accounts_uri, json=payload, headers=headers) new_uri = '/redfish/v1/AccountService/Accounts/4' self.session.post.return_value.status_code = requests.codes.CREATED self.session.post.return_value.headers = { 'Location': self.sut.rhost + new_uri } user, pwd, uri = accounts.add_account(self.sut, self.session) self.assertEqual(len(user), 8) self.assertTrue(user.startswith('rfpv')) self.assertEqual(uri, new_uri)