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)
Esempio n. 2
0
    def test_register_handle(self):
        """Test registering a new handle with various types of values."""
        log_new_test_case("test_register_handle")

        # Test variables
        testhandle = self.newhandle
        additional_URLs = ['http://bar.bar', 'http://foo.foo']

        # Run code to be tested:
        log_start_test_code()
        handle_returned = self.inst.register_handle(
            testhandle,
            location='http://foo.bar',
            checksum='123456',
            additional_URLs=additional_URLs,
            foo='foo',
            bar='bar')
        log_end_test_code()

        # Check desired effects on handle:
        # Check if content was written ok:
        rec = self.inst.retrieve_handle_record_json(testhandle)
        val1 = self.inst.get_value_from_handle(testhandle, 'bar', rec)
        val2 = self.inst.get_value_from_handle(testhandle, 'foo', rec)
        val3 = self.inst.get_value_from_handle(testhandle, 'URL', rec)
        val4 = self.inst.get_value_from_handle(testhandle, 'checksum', rec)
        contained1 = self.inst.is_URL_contained_in_10320LOC(
            testhandle, 'http://bar.bar', rec)
        contained2 = self.inst.is_URL_contained_in_10320LOC(
            testhandle, 'http://foo.foo', rec)

        self.assertEqual(
            handle_returned, testhandle,
            'The handle returned by the create-method was not the one passed to it.'
        )
        self.assertEqual(val1, 'bar', 'The value "bar" was not inserted.')
        self.assertEqual(val2, 'foo', 'The value "foo" was not inserted.')
        self.assertEqual(val3, 'http://foo.bar',
                         'The value "http://foo.bar" was not inserted.')
        self.assertEqual(val4, '123456',
                         'The value "123456" was not inserted.')
        self.assertTrue(contained1,
                        'A specified additional URL was not inserted.')
        self.assertTrue(contained2,
                        'A specified additional URL was not inserted.')

        # Delete again (and check if was deleted):
        handle = self.newhandle
        url = self.inst.make_handle_URL(self.newhandle)
        head = self.headers
        veri = self.https_verify
        resp = requests.delete(url, headers=head, verify=veri)
        log_request_response_to_file('DELETE', handle, url, head, veri, resp)
        rec = self.inst.retrieve_handle_record_json(self.newhandle)

        self.assertEqual(resp.status_code, 200,
                         'Deleting did not return a HTTP 200 code.')
        self.assertIsNone(rec, 'The deleted record should return None.')
Esempio n. 3
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)
Esempio n. 4
0
    def test_generate_and_register_handle(self):
        """Test generating and registering a new handle with various types of values."""
        log_new_test_case("test_generate_and_register_handle")

        # Test variables
        additional_URLs = ['http://bar.bar', 'http://foo.foo']
        prefix = self.prefix

        # Run code to be tested:
        log_start_test_code()
        handle_returned = self.inst.generate_and_register_handle(
            prefix=prefix,
            location='http://foo.bar',
            checksum='123456',
            additional_URLs=additional_URLs,
            foo='foo',
            bar='bar')
        log_end_test_code()

        # Check desired effects on handle:
        rec = self.inst.retrieve_handle_record_json(handle_returned)
        val1 = self.inst.get_value_from_handle(handle_returned, 'bar', rec)
        val2 = self.inst.get_value_from_handle(handle_returned, 'foo', rec)
        val3 = self.inst.get_value_from_handle(handle_returned, 'URL', rec)
        val4 = self.inst.get_value_from_handle(handle_returned, 'checksum',
                                               rec)
        contained1 = self.inst.is_URL_contained_in_10320LOC(
            handle_returned, 'http://bar.bar', rec)
        contained2 = self.inst.is_URL_contained_in_10320LOC(
            handle_returned, 'http://foo.foo', rec)

        self.assertEqual(val1, 'bar', 'The value "bar" was not inserted.')
        self.assertEqual(val2, 'foo', 'The value "foo" was not inserted.')
        self.assertEqual(val3, 'http://foo.bar',
                         'The value "http://foo.bar" was not inserted.')
        self.assertEqual(val4, '123456',
                         'The value "123456" was not inserted.')
        self.assertTrue(contained1,
                        'A specified additional URL was not inserted.')
        self.assertTrue(contained2,
                        'A specified additional URL was not inserted.')
        self.assertIn(
            prefix, handle_returned,
            'The returned handle does not contain the given prefix.')

        # Delete again (and check if was deleted):
        url = self.inst.make_handle_URL(handle_returned)
        head = self.headers
        veri = self.https_verify
        resp = requests.delete(url, headers=head, verify=veri)
        log_request_response_to_file('DELETE', handle_returned, url, head,
                                     veri, resp)
        rec = self.inst.retrieve_handle_record_json(handle_returned)

        self.assertEqual(resp.status_code, 200,
                         'Deleting did not return a HTTP 200 code.')
        self.assertIsNone(rec, 'The deleted record should return None.')
    def test_register_handle(self):
        """Test registering a new handle with various types of values."""
        log_new_test_case("test_register_handle")

        # Test variables
        testhandle = self.newhandle
        additional_URLs = ['http://bar.bar', 'http://foo.foo']

        # Run code to be tested:
        log_start_test_code()
        handle_returned = self.inst.register_handle(testhandle,
                                                    location='http://foo.bar',
                                                    checksum='123456',
                                                    additional_URLs=additional_URLs,
                                                    FOO='foo',
                                                    BAR='bar')
        log_end_test_code()

        # Check desired effects on handle:
        # Check if content was written ok:
        rec = self.inst.retrieve_handle_record_json(testhandle)
        val1 = self.inst.get_value_from_handle(testhandle, 'BAR', rec)
        val2 = self.inst.get_value_from_handle(testhandle, 'FOO', rec)
        val3 = self.inst.get_value_from_handle(testhandle, 'URL', rec)
        val4 = self.inst.get_value_from_handle(testhandle, 'CHECKSUM', rec)
        contained1 = self.inst.is_URL_contained_in_10320LOC(testhandle, 'http://bar.bar', rec)
        contained2 = self.inst.is_URL_contained_in_10320LOC(testhandle, 'http://foo.foo', rec)

        self.assertEqual(handle_returned, testhandle,
            'The handle returned by the create-method was not the one passed to it.')
        self.assertEqual(val1, 'bar',
            'The value "bar" was not inserted.')
        self.assertEqual(val2, 'foo',
            'The value "foo" was not inserted.')
        self.assertEqual(val3, 'http://foo.bar',
            'The value "http://foo.bar" was not inserted.')
        self.assertEqual(val4, '123456',
            'The value "123456" was not inserted.')
        self.assertTrue(contained1,
            'A specified additional URL was not inserted.')
        self.assertTrue(contained2,
            'A specified additional URL was not inserted.')

        # Delete again (and check if was deleted):
        handle = self.newhandle
        url = self.connector.make_handle_URL(self.newhandle)
        head = self.headers
        veri = self.https_verify
        resp = requests.delete(url, headers=head, verify=veri)
        log_request_response_to_file('DELETE', handle, url, head, veri, resp)
        rec = self.inst.retrieve_handle_record_json(self.newhandle)

        self.assertEqual(resp.status_code, 200,
            'Deleting did not return a HTTP 200 code.')
        self.assertIsNone(rec,
            'The deleted record should return None.')
    def test_modify_handle_value_corrupted(self):
        """Test exception when trying to modify corrupted handle record."""
        log_new_test_case("test_modify_handle_value_corrupted")

        # Test variables
        testhandle = self.handle
        head = self.headers
        url = self.connector.make_handle_URL(testhandle)
        # Create corrupted record:
        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": "TEST2",
                "data":{
                    "format":"string",
                    "value":"val3"
                }
            },
            {
                "index":4,
                "type": "TEST4",
                "data":{
                    "format":"string",
                    "value":"val4"
                }
            }
        ]
        data = json.dumps({'values':list_of_all_entries})
        veri = self.https_verify
        resp = requests.put(url, data=data, headers=head, verify=veri)
        log_request_response_to_file('PUT', testhandle, url, head, veri, resp, data)

        # Run code to be tested + check exception:
        log_start_test_code()
        with self.assertRaises(BrokenHandleRecordException):
            self.inst.modify_handle_value(testhandle,
                                          TEST4='new4',
                                          TEST2='new2',
                                          TEST3='new3')
        log_end_test_code()
    def test_generate_and_register_handle(self):
        """Test generating and registering a new handle with various types of values."""
        log_new_test_case("test_generate_and_register_handle")

        # Test variables
        additional_URLs = ['http://bar.bar', 'http://foo.foo']
        prefix = self.prefix

        # Run code to be tested:
        log_start_test_code()
        handle_returned = self.inst.generate_and_register_handle(prefix=prefix,
                                                    location='http://foo.bar',
                                                    checksum='123456',
                                                    additional_URLs=additional_URLs,
                                                    foo='foo',
                                                    bar='bar')
        log_end_test_code()

        # Check desired effects on handle:
        rec = self.inst.retrieve_handle_record_json(handle_returned)
        val1 = self.inst.get_value_from_handle(handle_returned, 'bar', rec)
        val2 = self.inst.get_value_from_handle(handle_returned, 'foo', rec)
        val3 = self.inst.get_value_from_handle(handle_returned, 'URL', rec)
        val4 = self.inst.get_value_from_handle(handle_returned, 'checksum', rec)
        contained1 = self.inst.is_URL_contained_in_10320LOC(handle_returned, 'http://bar.bar', rec)
        contained2 = self.inst.is_URL_contained_in_10320LOC(handle_returned, 'http://foo.foo', rec)

        self.assertEqual(val1, 'bar',
            'The value "bar" was not inserted.')
        self.assertEqual(val2, 'foo',
            'The value "foo" was not inserted.')
        self.assertEqual(val3, 'http://foo.bar',
            'The value "http://foo.bar" was not inserted.')
        self.assertEqual(val4, '123456',
            'The value "123456" was not inserted.')
        self.assertTrue(contained1,
            'A specified additional URL was not inserted.')
        self.assertTrue(contained2,
            'A specified additional URL was not inserted.')
        self.assertIn(prefix, handle_returned,
            'The returned handle does not contain the given prefix.')

        # Delete again (and check if was deleted):
        url = self.inst.make_handle_URL(handle_returned)
        head = self.headers
        veri = self.https_verify
        resp = requests.delete(url, headers=head, verify=veri)
        log_request_response_to_file('DELETE', handle_returned, url, head, veri, resp)
        rec = self.inst.retrieve_handle_record_json(handle_returned)

        self.assertEqual(resp.status_code, 200,
            'Deleting did not return a HTTP 200 code.')
        self.assertIsNone(rec,
            'The deleted record should return None.')
Esempio n. 8
0
    def test_modify_handle_value_corrupted(self):
        """Test exception when trying to modify corrupted handle record."""
        log_new_test_case("test_modify_handle_value_corrupted")

        # Test variables
        testhandle = self.handle
        head = self.headers
        url = self.inst.make_handle_URL(testhandle)
        # Create corrupted record:
        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": "test2",
            "data": {
                "format": "string",
                "value": "val3"
            }
        }, {
            "index": 4,
            "type": "test4",
            "data": {
                "format": "string",
                "value": "val4"
            }
        }]
        data = json.dumps({'values': list_of_all_entries})
        veri = self.https_verify
        resp = requests.put(url, data=data, headers=head, verify=veri)
        log_request_response_to_file('PUT', testhandle, url, head, veri, resp,
                                     data)

        # Run code to be tested + check exception:
        log_start_test_code()
        with self.assertRaises(BrokenHandleRecordException):
            self.inst.modify_handle_value(testhandle,
                                          test4='new4',
                                          test2='new2',
                                          test3='new3')
        log_end_test_code()
    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)
Esempio n. 10
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)
    def tearDown(self):

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

        testhandle = self.handle_withloc
        url = self.connector.make_handle_URL(testhandle)
        resp = requests.delete(url, headers=head, verify=veri)
        log_request_response_to_file('DELETE', testhandle, url, head, veri, resp)

        testhandle = self.handle_withoutloc
        url = self.connector.make_handle_URL(testhandle)
        requests.delete(url, headers=head, verify=veri)
        log_request_response_to_file('DELETE', testhandle, url, head, veri, resp)
Esempio n. 12
0
    def tearDown(self):

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

        testhandle = self.handle_withloc
        url = self.inst.make_handle_URL(testhandle)
        resp = requests.delete(url, headers=head, verify=veri)
        log_request_response_to_file('DELETE', testhandle, url, head, veri, resp)

        testhandle = self.handle_withoutloc
        url = self.inst.make_handle_URL(testhandle)
        requests.delete(url, headers=head, verify=veri)
        log_request_response_to_file('DELETE', testhandle, url, head, veri, resp)