コード例 #1
0
    def test_instantiate_with_username_and_password_noindex(self):

        # Try to ceate client instance with username and password

        with self.assertRaises(HandleSyntaxError):
            inst = EUDATHandleClient.instantiate_with_username_and_password(
                'someurl', 'johndoe', 'passywordy')
コード例 #2
0
    def test_instantiate_with_username_and_password_noindex(self):

        # Try to ceate client instance with username and password

        with self.assertRaises(HandleSyntaxError):
            inst = EUDATHandleClient.instantiate_with_username_and_password(
                'someurl', 'johndoe', 'passywordy')
コード例 #3
0
    def test_instantiate_with_username_and_wrong_password(self):
        """Test instantiation of client: No exception if password wrong."""

        # Create client instance with username and password
        inst = EUDATHandleClient.instantiate_with_username_and_password(
            self.url, self.user, self.randompassword, HTTPS_verify=self.https_verify
        )
        self.assertIsInstance(inst, EUDATHandleClient)
コード例 #4
0
    def setUp(self):

        REQUESTLOGGER.info("\n"+60*"*"+"\nsetUp of EUDATHandleClientWriteaccessTestCase")

        self.inst = EUDATHandleClient.instantiate_with_username_and_password(
            self.url,
            self.user,
            self.password,
            HTTPS_verify=self.https_verify)

        authstring = b2handle.utilhandle.create_authentication_string(self.user, self.password)
        self.headers = {
            'Content-Type': 'application/json',
            'Authorization': 'Basic '+authstring
        }

        list_of_all_entries = [
            {
                "index":111,
                "type": "TEST1",
                "data":{
                    "format":"string",
                    "value":"val1"
                }
            },
            {
                "index":2222,
                "type": "TEST2",
                "data":{
                    "format":"string",
                    "value":"val2"
                }
            },
            {
                "index":333,
                "type": "TEST3",
                "data":{
                    "format":"string",
                    "value":"val3"
                }
            },
            {
                "index":4,
                "type": "TEST4",
                "data":{
                    "format":"string",
                    "value":"val4"
                }
            },
        ]

        testhandle = self.handle
        url = self.connector.make_handle_URL(testhandle)
        veri = self.https_verify
        head = self.headers
        data = json.dumps({'values':list_of_all_entries})
        resp = requests.put(url, data=data, headers=head, verify=veri)
        log_request_response_to_file('PUT', self.handle, url, head, veri, resp)
コード例 #5
0
    def test_instantiate_with_username_and_password_inexistentuser(self, getpatch):
        
        # Define the replacement for the patched method:
        mock_response = MockResponse(notfound=True)
        getpatch.return_value = mock_response

        with self.assertRaises(HandleNotFoundException):
            inst = EUDATHandleClient.instantiate_with_username_and_password(
                'http://someurl', '100:john/doe', 'passywordy')
コード例 #6
0
    def setUp(self):

        REQUESTLOGGER.info("\n" + 60 * "*" +
                           "\nsetUp of EUDATHandleClientWriteaccessTestCase")

        self.inst = EUDATHandleClient.instantiate_with_username_and_password(
            self.url, self.user, self.password, HTTPS_verify=self.https_verify)

        authstring = self.inst.create_authentication_string(
            self.user, self.password)
        self.headers = {
            'Content-Type': 'application/json',
            'Authorization': 'Basic ' + authstring
        }

        list_of_all_entries = [
            {
                "index": 111,
                "type": "test1",
                "data": {
                    "format": "string",
                    "value": "val1"
                }
            },
            {
                "index": 2222,
                "type": "test2",
                "data": {
                    "format": "string",
                    "value": "val2"
                }
            },
            {
                "index": 333,
                "type": "test3",
                "data": {
                    "format": "string",
                    "value": "val3"
                }
            },
            {
                "index": 4,
                "type": "test4",
                "data": {
                    "format": "string",
                    "value": "val4"
                }
            },
        ]

        testhandle = self.handle
        url = self.inst.make_handle_URL(testhandle)
        veri = self.https_verify
        head = self.headers
        data = json.dumps({'values': list_of_all_entries})
        resp = requests.put(url, data=data, headers=head, verify=veri)
        log_request_response_to_file('PUT', self.handle, url, head, veri, resp)
コード例 #7
0
    def test_instantiate_with_username_and_password_inexistentuser(
            self, getpatch):

        # Define the replacement for the patched method:
        mock_response = MockResponse(notfound=True)
        getpatch.return_value = mock_response

        with self.assertRaises(HandleNotFoundException):
            inst = EUDATHandleClient.instantiate_with_username_and_password(
                'http://someurl', '100:john/doe', 'passywordy')
コード例 #8
0
    def test_instantiate_with_username_and_password_wrongpw(self, getpatch):

        # Define the replacement for the patched method:
        mock_response = MockResponse(success=True)
        getpatch.return_value = mock_response

        inst = EUDATHandleClient.instantiate_with_username_and_password(
            'http://someurl', '100:my/testhandle', 'passywordy')

        self.assertIsInstance(inst, EUDATHandleClient)
コード例 #9
0
    def test_instantiate_with_username_and_wrong_password(self):
        """Test instantiation of client: No exception if password wrong."""

        # Create client instance with username and password
        inst = EUDATHandleClient.instantiate_with_username_and_password(
            self.url,
            self.user,
            self.randompassword,
            HTTPS_verify=self.https_verify)
        self.assertIsInstance(inst, EUDATHandleClient)
コード例 #10
0
    def test_instantiate_with_username_and_password_wrongpw(self, getpatch):
        

        # Define the replacement for the patched method:
        mock_response = MockResponse(success=True)
        getpatch.return_value = mock_response

        inst = EUDATHandleClient.instantiate_with_username_and_password(
                'http://someurl', '100:my/testhandle', 'passywordy')

        self.assertIsInstance(inst, EUDATHandleClient)
コード例 #11
0
    def test_instantiate_with_username_without_index_and_password(self):
        """Test instantiation of client: Exception if username has no index."""
        testusername_without_index = self.user.split(":")[1]

        # Run code to be tested + check exception:
        with self.assertRaises(HandleSyntaxError):

            # Create client instance with username and password
            inst = EUDATHandleClient.instantiate_with_username_and_password(
                self.url, testusername_without_index, self.randompassword, HTTPS_verify=self.https_verify
            )
コード例 #12
0
    def test_instantiate_with_nonexistent_username_and_password(self):
        """Test instantiation of client: Exception if username does not exist."""
        testusername_inexistent = "100:" + self.inexistent_handle

        # Run code to be tested + check exception:
        with self.assertRaises(HandleNotFoundException):

            # Create client instance with username and password
            inst = EUDATHandleClient.instantiate_with_username_and_password(
                self.url, testusername_inexistent, self.randompassword, HTTPS_verify=self.https_verify
            )
コード例 #13
0
    def create_required_test_handles(self):

        # Creating an instance that knows how to write:
        pw = self.testvalues['password']
        inst = EUDATHandleClient.instantiate_with_username_and_password(
            self.testvalues['handle_server_url_write'],
            self.user,
            pw,
            HTTPS_verify=self.https_verify)

        authstring = b2handle.utilhandle.create_authentication_string(
            self.user, pw)
        headers = {
            'Content-Type': 'application/json',
            'Authorization': 'Basic ' + authstring
        }

        list_of_all_entries = [{
            "index": 100,
            "type": "HS_ADMIN",
            "data": {
                "format": "admin",
                "value": {
                    "handle": "21.T14999/B2HANDLE_INTEGRATION_TESTS",
                    "index": 300,
                    "permissions": "011111110011"
                }
            }
        }, {
            "index": 111,
            "type": "TEST1",
            "data": "val1"
        }, {
            "index": 2222,
            "type": "TEST2",
            "data": "val2"
        }, {
            "index": 333,
            "type": "TEST3",
            "data": "val3"
        }, {
            "index": 4,
            "type": "TEST4",
            "data": "val4"
        }]

        testhandle = self.handle
        url = self.testvalues['handle_server_url_write'] + self.testvalues[
            'url_extension_REST_API'] + testhandle
        veri = self.https_verify
        head = headers
        data = json.dumps({'values': list_of_all_entries})
        resp = requests.put(url, data=data, headers=head, verify=veri)
コード例 #14
0
    def setUp(self):

        REQUESTLOGGER.info("\n"+60*"*"+"\nsetUp of EUDATHandleClientWriteaccess10320LOCTestCase")

        self.inst = EUDATHandleClient.instantiate_with_username_and_password(
            self.url,
            self.user,
            self.password,
            HTTPS_verify=self.https_verify)
        
        list_of_all_entries_with = [
            {
                "index":1,
                "type":"URL",
                "data":"www.url.foo"
            },
            {
                "index":2,
                "type":"10320/LOC",
                "data":{
                    "format":"string",
                    "value":"<locations><location href = 'http://first.foo' /><location href = 'http://second.foo' /></locations> "
                }
            }
        ]

        list_of_all_entries_without = [
            {
                "index":1,
                "type":"URL",
                "data":"www.url.foo"
            }
        ]

        authstring = self.inst.create_authentication_string(self.user, self.password)
        head = {
            'Content-Type': 'application/json',
            'Authorization': 'Basic '+authstring
        }
        veri = self.https_verify

        testhandle = self.handle_withloc
        url = self.inst.make_handle_URL(testhandle)
        data = json.dumps({'values':list_of_all_entries_with})
        resp = requests.put(url, data=data, headers=head, verify=veri)
        log_request_response_to_file('PUT', testhandle, url, head, veri, resp)

        testhandle = self.handle_withoutloc
        url = self.inst.make_handle_URL(testhandle)
        data = json.dumps({'values':list_of_all_entries_without})
        requests.put(url, data=data, headers=head, verify=veri)
        log_request_response_to_file('PUT', testhandle, url, head, veri, resp)
コード例 #15
0
    def setUp(self):

        REQUESTLOGGER.info("\n"+60*"*"+"\nsetUp of EUDATHandleClientWriteaccess10320LOCTestCase")

        self.inst = EUDATHandleClient.instantiate_with_username_and_password(
            self.url,
            self.user,
            self.password,
            HTTPS_verify=self.https_verify)
        
        list_of_all_entries_with = [
            {
                "index":1,
                "type":"URL",
                "data":"www.url.foo"
            },
            {
                "index":2,
                "type":"10320/LOC",
                "data":{
                    "format":"string",
                    "value":"<locations><location href = 'http://first.foo' /><location href = 'http://second.foo' /></locations> "
                }
            }
        ]

        list_of_all_entries_without = [
            {
                "index":1,
                "type":"URL",
                "data":"www.url.foo"
            }
        ]

        authstring = b2handle.utilhandle.create_authentication_string(self.user, self.password)
        head = {
            'Content-Type': 'application/json',
            'Authorization': 'Basic '+authstring
        }
        veri = self.https_verify

        testhandle = self.handle_withloc
        url = self.connector.make_handle_URL(testhandle)
        data = json.dumps({'values':list_of_all_entries_with})
        resp = requests.put(url, data=data, headers=head, verify=veri)
        log_request_response_to_file('PUT', testhandle, url, head, veri, resp)

        testhandle = self.handle_withoutloc
        url = self.connector.make_handle_URL(testhandle)
        data = json.dumps({'values':list_of_all_entries_without})
        requests.put(url, data=data, headers=head, verify=veri)
        log_request_response_to_file('PUT', testhandle, url, head, veri, resp)
コード例 #16
0
    def test_instantiate_with_nonexistent_username_and_password(self):
        """Test instantiation of client: Exception if username does not exist."""
        testusername_inexistent = '100:' + self.inexistent_handle

        # Run code to be tested + check exception:
        with self.assertRaises(HandleNotFoundException):

            # Create client instance with username and password
            inst = EUDATHandleClient.instantiate_with_username_and_password(
                self.url,
                testusername_inexistent,
                self.randompassword,
                HTTPS_verify=self.https_verify)
コード例 #17
0
    def test_instantiate_with_username_without_index_and_password(self):
        """Test instantiation of client: Exception if username has no index."""
        testusername_without_index = self.user.split(':')[1]

        # Run code to be tested + check exception:
        with self.assertRaises(HandleSyntaxError):

            # Create client instance with username and password
            inst = EUDATHandleClient.instantiate_with_username_and_password(
                self.url,
                testusername_without_index,
                self.randompassword,
                HTTPS_verify=self.https_verify)
コード例 #18
0
    def create_required_test_handles(self):

        # Creating an instance that knows how to write:
        pw = self.testvalues['password']
        inst = EUDATHandleClient.instantiate_with_username_and_password(
            self.testvalues['handle_server_url_write'],
            self.user,
            pw,
            HTTPS_verify=self.https_verify)

        authstring = self.inst.create_authentication_string(self.user, pw)
        headers = {
            'Content-Type': 'application/json',
            'Authorization': 'Basic '+authstring
        }

        list_of_all_entries = [
            {
                "index":111,
                "type":"test1",
                "data":"val1"
            },
            {
                "index":2222,
                "type":"test2",
                "data":"val2"
            },
            {
                "index":333,
                "type":"test3",
                "data":"val3"
            },
            {
                "index":4,
                "type":"test4",
                "data":"val4"
            }
        ]

        testhandle = self.handle
        url = inst.make_handle_URL(testhandle)
        veri = self.https_verify
        head = headers
        data = json.dumps({'values':list_of_all_entries})
        resp = requests.put(url, data=data, headers=head, verify=veri)
コード例 #19
0
    def create_required_test_handles(self):

        # Creating an instance that knows how to write:
        pw = self.testvalues['password']
        inst = EUDATHandleClient.instantiate_with_username_and_password(
            self.testvalues['handle_server_url_write'],
            self.user,
            pw,
            HTTPS_verify=self.https_verify)

        authstring = self.inst.create_authentication_string(self.user, pw)
        headers = {
            'Content-Type': 'application/json',
            'Authorization': 'Basic ' + authstring
        }

        list_of_all_entries = [{
            "index": 111,
            "type": "test1",
            "data": "val1"
        }, {
            "index": 2222,
            "type": "test2",
            "data": "val2"
        }, {
            "index": 333,
            "type": "test3",
            "data": "val3"
        }, {
            "index": 4,
            "type": "test4",
            "data": "val4"
        }]

        testhandle = self.handle
        url = inst.make_handle_URL(testhandle)
        veri = self.https_verify
        head = headers
        data = json.dumps({'values': list_of_all_entries})
        resp = requests.put(url, data=data, headers=head, verify=veri)
コード例 #20
0
    def setUp(self):

        REQUESTLOGGER.info("\n" + 60 * "*" +
                           "\nsetUp of EUDATHandleClientWriteaccessTestCase")

        self.inst = EUDATHandleClient.instantiate_with_username_and_password(
            self.url,
            self.user,
            self.password,
            HTTPS_verify=self.https_verify,
            handleowner=self.user)

        authstring = b2handle.utilhandle.create_authentication_string(
            self.user, self.password)
        self.headers = {
            'Content-Type': 'application/json',
            'Authorization': 'Basic ' + authstring
        }

        list_of_all_entries = [
            {
                "index": 100,
                "type": "HS_ADMIN",
                "data": {
                    "format": "admin",
                    "value": {
                        "handle": "21.T14999/B2HANDLE_INTEGRATION_TESTS",
                        "index": 300,
                        "permissions": "011111110011"
                    }
                }
            },
            {
                "index": 111,
                "type": "TEST1",
                "data": {
                    "format": "string",
                    "value": "val1"
                }
            },
            {
                "index": 2222,
                "type": "TEST2",
                "data": {
                    "format": "string",
                    "value": "val2"
                }
            },
            {
                "index": 333,
                "type": "TEST3",
                "data": {
                    "format": "string",
                    "value": "val3"
                }
            },
            {
                "index": 4,
                "type": "TEST4",
                "data": {
                    "format": "string",
                    "value": "val4"
                }
            },
        ]

        testhandle = self.handle
        url = self.connector.make_handle_URL(testhandle)
        veri = self.https_verify
        head = self.headers
        data = json.dumps({'values': list_of_all_entries})
        resp = requests.put(url, data=data, headers=head, verify=veri)
        log_request_response_to_file('PUT', self.handle, url, head, veri, resp)