Exemplo n.º 1
0
    def test_exchange_additional_URL_normal(self):
        """Test replacing an URL."""
        log_new_test_case("test_exchange_additional_URL_normal")

        # Test variables
        testhandle = self.handle_withloc
        old = 'http://first.foo'
        new = 'http://newfirst.foo'

        # Precondition: URL must be included.
        handlerecord_json = self.inst.retrieve_handle_record_json(testhandle)
        contained = self.inst.is_URL_contained_in_10320LOC(testhandle, old, handlerecord_json)
        self.assertTrue(contained,
            'Precondition for test failed! The URL should be present at the start'
            ' of the test: '+str(handlerecord_json))

        # Run the code to be tested:
        log_start_test_code()
        self.inst.exchange_additional_URL(testhandle, old, new)
        log_end_test_code()

        # Check desired effects on handle:
        contained = self.inst.is_URL_contained_in_10320LOC(testhandle, new)
        self.assertTrue(contained,
            'After replacing an URL, the replacement was not there.')
Exemplo n.º 2
0
    def test_delete_handle_value_several_entries(self):
        """Test deleting several entries from a record."""
        log_new_test_case("test_delete_handle_value_several_entries")

        # Test variables
        testhandle = self.handle

        # Run code to be tested:
        log_start_test_code()
        self.inst.delete_handle_value(testhandle, ['test1', 'test2'])
        log_end_test_code()

        # Check desired effects on handle:
        rec = self.inst.retrieve_handle_record_json(testhandle)
        val1 = self.inst.get_value_from_handle(testhandle, 'test1', rec)
        val2 = self.inst.get_value_from_handle(testhandle, 'test2', rec)
        indices1 = self.inst.get_handlerecord_indices_for_key(
            'test1', rec['values'])
        indices2 = self.inst.get_handlerecord_indices_for_key(
            'test2', rec['values'])

        self.assertIsNone(val1,
                          'The value for the deleted entry should be None.')
        self.assertIsNone(val2,
                          'The value for the deleted entry should be None.')
        self.assertEqual(len(indices1), 0,
                         'There should be no index for the deleted entry.')
        self.assertEqual(len(indices2), 0,
                         'There should be no index for the deleted entry.')
    def test_modify_handle_value_several(self):
        """Test modifying several existing handle values."""
        log_new_test_case("test_modify_handle_value_several")

        # Test variables
        testhandle = self.handle

        # Run code to be tested:
        log_start_test_code()
        self.inst.modify_handle_value(testhandle,
                                      test4='new4',
                                      test2='new2',
                                      test3='new3')
        log_end_test_code()

        # Check desired effects on handle:
        # check if three values were modified:
        rec = self.inst.retrieve_handle_record_json(testhandle)
        val2 = self.inst.get_value_from_handle(testhandle, 'test2', rec)
        val3 = self.inst.get_value_from_handle(testhandle, 'test3', rec)
        val4 = self.inst.get_value_from_handle(testhandle, 'test4', rec)
        self.assertEqual(val2, 'new2',
            'The value of "test2" was not changed to "new2".')
        self.assertEqual(val3, 'new3',
            'The value of "test3" was not changed to "new3".')
        self.assertEqual(val4, 'new4',
            'The value of "test4" was not changed to "new4".')

        # check if one value remained unchanged:
        val1 = self.inst.get_value_from_handle(testhandle, 'test1', rec)
        self.assertEqual(val1, 'val1',
            'The value of "test1" should still be "val1".')
    def test_add_additional_URL_alreadythere(self):
        """Test adding an URL that is already there."""
        log_new_test_case("test_add_additional_URL_alreadythere")

        # Test variables
        testhandle = self.handle_withloc
        url = 'http://first.foo'

        # Precondition: URL is already contained:
        record_before = self.inst.retrieve_handle_record_json(testhandle)
        contained = self.inst.is_URL_contained_in_10320LOC(testhandle, url, record_before)
        self.assertTrue(contained,
            'Test precondition failed: URL not there: '+str(record_before))

        # Run code to be tested:
        log_start_test_code()
        self.inst.add_additional_URL(testhandle, url)
        log_end_test_code()

        # Check desired effects on handle:
        # i.e. check if something has changed
        record_after  = self.inst.retrieve_handle_record_json(testhandle)
        self.assertEqual(record_before, record_after,
                        'After adding the same URL again, '
                        'the record was not equal.\n'
                        'Before:\n'+str(record_before)+'\n'
                        'After:\n'+str(record_after))
    def test_delete_handle_value_several_entries(self):
        """Test deleting several entries from a record."""
        log_new_test_case("test_delete_handle_value_several_entries")

        # Test variables
        testhandle = self.handle

        # Run code to be tested:
        log_start_test_code()
        self.inst.delete_handle_value(testhandle, ['TEST1', 'TEST2'])
        log_end_test_code()

        # Check desired effects on handle:
        rec = self.inst.retrieve_handle_record_json(testhandle)
        val1 = self.inst.get_value_from_handle(testhandle, 'TEST1', rec)
        val2 = self.inst.get_value_from_handle(testhandle, 'TEST2', rec)
        indices1 = self.inst.get_handlerecord_indices_for_key('TEST1', rec['values'])
        indices2 = self.inst.get_handlerecord_indices_for_key('TEST2', rec['values'])

        self.assertIsNone(val1,
            'The value for the deleted entry should be None.')
        self.assertIsNone(val2,
            'The value for the deleted entry should be None.')
        self.assertEqual(len(indices1), 0,
            'There should be no index for the deleted entry.')
        self.assertEqual(len(indices2), 0,
            'There should be no index for the deleted entry.')
    def test_remove_additional_URL_several(self):
        """Test removing all URL at the same time, which should remove the whole 10320/LOC attribute."""
        log_new_test_case("test_remove_additional_URL_several")

        # Test variables
        testhandle = self.handle_withloc
        url1 =  'http://first.foo'
        url2 = 'http://second.foo'

        # Run code to be tested:
        log_start_test_code()
        self.inst.remove_additional_URL(testhandle, url1, url2)
        log_end_test_code()

        # Check desired effects on handle:
        # Check if empty:
        isempty = self.inst.is_10320LOC_empty(testhandle)
        self.assertTrue(isempty,
            'After removing all URLs from 10320/LOC, it is not empty.')
        # Check if still exists:
        rec = self.inst.retrieve_handle_record_json(testhandle)
        val = self.inst.get_value_from_handle(testhandle, '10320/LOC', rec)
        indices = self.inst.get_handlerecord_indices_for_key('10320/LOC', rec['values'])
        self.assertIsNone(val,
            'After removing all URLs from 10320/LOC, the value is not None.')
        self.assertEqual(len(indices), 0,
            'After removing all URLs from 10320/LOC, the entry still exists.')
    def test_modify_handle_value_one(self):
        """Test modifying one existing handle value."""
        log_new_test_case("test_modify_handle_value_one")

        # Test variables
        testhandle = self.handle

        # Run code to be tested:
        log_start_test_code()
        self.inst.modify_handle_value(testhandle, TEST4='newvalue')
        log_end_test_code()

        # Check desired effects on handle:
        # check if one was modified:
        rec = self.inst.retrieve_handle_record_json(testhandle)
        val = self.inst.get_value_from_handle(testhandle, 'TEST4', rec)
        self.assertEqual(val, 'newvalue',
            'The value did not change.')

        # check if others still there:
        val1 = self.inst.get_value_from_handle(testhandle, 'TEST1', rec)
        val2 = self.inst.get_value_from_handle(testhandle, 'TEST2', rec)
        self.assertEqual(val1, 'val1',
            'The value of "TEST1" should still be "val1".')
        self.assertEqual(val2, 'val2',
            'The value of "TEST2" should still be "val2".')
Exemplo n.º 8
0
    def test_modify_handle_value_one(self):
        """Test modifying one existing handle value."""
        log_new_test_case("test_modify_handle_value_one")

        # Test variables
        testhandle = self.handle

        # Run code to be tested:
        log_start_test_code()
        self.inst.modify_handle_value(testhandle, test4='newvalue')
        log_end_test_code()

        # Check desired effects on handle:
        # check if one was modified:
        rec = self.inst.retrieve_handle_record_json(testhandle)
        val = self.inst.get_value_from_handle(testhandle, 'test4', rec)
        self.assertEqual(val, 'newvalue', 'The value did not change.')

        # check if others still there:
        val1 = self.inst.get_value_from_handle(testhandle, 'test1', rec)
        val2 = self.inst.get_value_from_handle(testhandle, 'test2', rec)
        self.assertEqual(val1, 'val1',
                         'The value of "test1" should still be "val1".')
        self.assertEqual(val2, 'val2',
                         'The value of "test2" should still be "val2".')
    def test_exchange_additional_URL_normal(self):
        """Test replacing an URL."""
        log_new_test_case("test_exchange_additional_URL_normal")

        # Test variables
        testhandle = self.handle_withloc
        old = 'http://first.foo'
        new = 'http://newfirst.foo'

        # Precondition: URL must be included.
        handlerecord_json = self.inst.retrieve_handle_record_json(testhandle)
        contained = self.inst.is_URL_contained_in_10320LOC(testhandle, old, handlerecord_json)
        self.assertTrue(contained,
            'Precondition for test failed! The URL should be present at the start'
            ' of the test: '+str(handlerecord_json))

        # Run the code to be tested:
        log_start_test_code()
        self.inst.exchange_additional_URL(testhandle, old, new)
        log_end_test_code()

        # Check desired effects on handle:
        contained = self.inst.is_URL_contained_in_10320LOC(testhandle, new)
        self.assertTrue(contained,
            'After replacing an URL, the replacement was not there.')
    def test_modify_handle_value_several_inexistent(self):
        """Test modifying several existing handle values, one of them inexistent."""
        log_new_test_case("test_modify_handle_value_several_inexistent")
        
        # Test variables
        testhandle = self.handle

        # Run code to be tested:
        log_start_test_code()
        self.inst.modify_handle_value(testhandle,
                                      TEST4='new4',
                                      TEST2='new2',
                                      TEST100='new100')
        log_end_test_code()

        # Check desired effects on handle:
        # check if three values were modified:
        rec = self.inst.retrieve_handle_record_json(testhandle)
        val2   = self.inst.get_value_from_handle(testhandle, 'TEST2', rec)
        val100 = self.inst.get_value_from_handle(testhandle, 'TEST100', rec)
        val4   = self.inst.get_value_from_handle(testhandle, 'TEST4', rec)
        self.assertEqual(val100, 'new100',
            'The value of "TEST100" was not created and set to "new100".')
        self.assertEqual(val2, 'new2',
            'The value of "TEST2" was not changed to "new2".')
        self.assertEqual(val4, 'new4',
            'The value of "TEST4" was not changed to "new4".')

        # check if one value remained unchanged:
        val1 = self.inst.get_value_from_handle(testhandle, 'TEST1', rec)
        self.assertEqual(val1, 'val1',
            'The value of "TEST1" should still be "val1".')
Exemplo n.º 11
0
    def test_remove_additional_URL_several(self):
        """Test removing all URL at the same time, which should remove the whole 10320/LOC attribute."""
        log_new_test_case("test_remove_additional_URL_several")

        # Test variables
        testhandle = self.handle_withloc
        url1 =  'http://first.foo'
        url2 = 'http://second.foo'

        # Run code to be tested:
        log_start_test_code()
        self.inst.remove_additional_URL(testhandle, url1, url2)
        log_end_test_code()

        # Check desired effects on handle:
        # Check if empty:
        isempty = self.inst.is_10320LOC_empty(testhandle)
        self.assertTrue(isempty,
            'After removing all URLs from 10320/LOC, it is not empty.')
        # Check if still exists:
        rec = self.inst.retrieve_handle_record_json(testhandle)
        val = self.inst.get_value_from_handle(testhandle, '10320/LOC', rec)
        indices = self.inst.get_handlerecord_indices_for_key('10320/LOC', rec['values'])
        self.assertIsNone(val,
            'After removing all URLs from 10320/LOC, the value is not None.')
        self.assertEqual(len(indices), 0,
            'After removing all URLs from 10320/LOC, the entry still exists.')
Exemplo n.º 12
0
    def test_modify_handle_value_several_inexistent(self):
        """Test modifying several existing handle values, one of them inexistent."""
        log_new_test_case("test_modify_handle_value_several_inexistent")

        # Test variables
        testhandle = self.handle

        # Run code to be tested:
        log_start_test_code()
        self.inst.modify_handle_value(testhandle,
                                      test4='new4',
                                      test2='new2',
                                      test100='new100')
        log_end_test_code()

        # Check desired effects on handle:
        # check if three values were modified:
        rec = self.inst.retrieve_handle_record_json(testhandle)
        val2 = self.inst.get_value_from_handle(testhandle, 'test2', rec)
        val100 = self.inst.get_value_from_handle(testhandle, 'test100', rec)
        val4 = self.inst.get_value_from_handle(testhandle, 'test4', rec)
        self.assertEqual(
            val100, 'new100',
            'The value of "test100" was not created and set to "new100".')
        self.assertEqual(val2, 'new2',
                         'The value of "test2" was not changed to "new2".')
        self.assertEqual(val4, 'new4',
                         'The value of "test4" was not changed to "new4".')

        # check if one value remained unchanged:
        val1 = self.inst.get_value_from_handle(testhandle, 'test1', rec)
        self.assertEqual(val1, 'val1',
                         'The value of "test1" should still be "val1".')
Exemplo n.º 13
0
    def test_add_additional_URL_alreadythere(self):
        """Test adding an URL that is already there."""
        log_new_test_case("test_add_additional_URL_alreadythere")

        # Test variables
        testhandle = self.handle_withloc
        url = 'http://first.foo'

        # Precondition: URL is already contained:
        record_before = self.inst.retrieve_handle_record_json(testhandle)
        contained = self.inst.is_URL_contained_in_10320LOC(testhandle, url, record_before)
        self.assertTrue(contained,
            'Test precondition failed: URL not there: '+str(record_before))

        # Run code to be tested:
        log_start_test_code()
        self.inst.add_additional_URL(testhandle, url)
        log_end_test_code()

        # Check desired effects on handle:
        # i.e. check if something has changed
        record_after  = self.inst.retrieve_handle_record_json(testhandle)
        self.assertEqual(record_before, record_after,
                        'After adding the same URL again, '
                        'the record was not equal.\n'
                        'Before:\n'+str(record_before)+'\n'
                        'After:\n'+str(record_after))
Exemplo n.º 14
0
    def test_add_additional_URL_several(self):
        """Test adding several (3) additional URLs."""
        log_new_test_case("test_add_additional_URL_several")

        # Test variables
        testhandle = self.handle_withloc
        url1 = 'http://one'
        url2 = 'http://two'
        url3 = 'http://three'
        
        # Run code to be tested:
        log_start_test_code()
        self.inst.add_additional_URL(testhandle, url1, url2, url3)
        log_end_test_code()

        # Check desired effects on handle:
        contained1 = self.inst.is_URL_contained_in_10320LOC(testhandle, url1)
        contained2 = self.inst.is_URL_contained_in_10320LOC(testhandle, url2)
        contained3 = self.inst.is_URL_contained_in_10320LOC(testhandle, url3)
        self.assertTrue(contained1,
            'The first added URL was not added.')
        self.assertTrue(contained2,
            'The second added URL was not added.')
        self.assertTrue(contained3,
            'The third added URL was not added.')
    def test_search_handle_prefixfilter(self):
        """Test filtering for prefixes."""
        log_new_test_case("test_search_handle_prefixfilter")

        prefix1 = self.prefix_inexistent
        prefix2 = self.handle.split('/')[0]

        log_start_test_code()
        val1 = self.inst.search_handle(URL='*dkrz*', prefix=prefix1)
        log_end_test_code()
        log_start_test_code()
        val2 = self.inst.search_handle(URL='*dkrz*', prefix=prefix2)
        log_end_test_code()

        # Check desired outcome:
        self.assertEqual(type(val1),type([]),
            'Searching did not return a list, but: '+str(val1)+', type: '+str(type(val1)))
        for item in val1:
            self.assertEqual(item.split('/')[0], prefix1,
                'This search result has the wrong prefix: '+item+', should be '+prefix1)

        self.assertEqual(type(val2),type([]),
            'Searching did not return a list, but: '+str(val1)+', type: '+str(type(val1)))
        for item in val2:
            self.assertEqual(item.split('/')[0], prefix2,
                'This search result has the wrong prefix: '+item+', should be '+prefix2)
    def test_add_additional_URL_several(self):
        """Test adding several (3) additional URLs."""
        log_new_test_case("test_add_additional_URL_several")

        # Test variables
        testhandle = self.handle_withloc
        url1 = 'http://one'
        url2 = 'http://two'
        url3 = 'http://three'
        
        # Run code to be tested:
        log_start_test_code()
        self.inst.add_additional_URL(testhandle, url1, url2, url3)
        log_end_test_code()

        # Check desired effects on handle:
        contained1 = self.inst.is_URL_contained_in_10320LOC(testhandle, url1)
        contained2 = self.inst.is_URL_contained_in_10320LOC(testhandle, url2)
        contained3 = self.inst.is_URL_contained_in_10320LOC(testhandle, url3)
        self.assertTrue(contained1,
            'The first added URL was not added.')
        self.assertTrue(contained2,
            'The second added URL was not added.')
        self.assertTrue(contained3,
            'The third added URL was not added.')
Exemplo n.º 17
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.')
Exemplo n.º 18
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_search_handle_for_url_and_CHECKSUM(self):
        """Test searching for url and checksum with wildcards."""
        log_new_test_case("test_search_handle_for_url_and_CHECKSUM")

        log_start_test_code()
        with self.assertRaises(ReverseLookupException):
            val1 = self.inst.search_handle('*dkrz*', CHECKSUM='*123*')
            log_end_test_code()
            log_start_test_code()
            val2 = self.inst.search_handle(URL='*dkrz*', CHECKSUM='*123*')
        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.')
    def test_delete_handle_too_many_args(self):
        """Test deleting an entire record, but we pass more arguments to the method."""
        log_new_test_case("test_delete_handle_too_many_args")

        # Test variables
        testhandle = self.handle

        # Run code to be tested + check exception:
        log_start_test_code()
        with self.assertRaises(TypeError):
            self.inst.delete_handle(testhandle, 'TEST1')
        log_end_test_code()
    def test_modify_handle_value_HS_ADMIN(self):
        """Test exception when trying to modify HS_ADMIN."""
        log_new_test_case("test_modify_handle_value_HS_ADMIN")

        # Test variables
        testhandle = self.handle

        # Run code to be tested + check exception:
        log_start_test_code()
        with self.assertRaises(IllegalOperationException):
            self.inst.modify_handle_value(testhandle, HS_ADMIN='please let me in!')
        log_end_test_code()
Exemplo n.º 25
0
    def test_delete_handle_too_many_args(self):
        """Test deleting an entire record, but we pass more arguments to the method."""
        log_new_test_case("test_delete_handle_too_many_args")

        # Test variables
        testhandle = self.handle

        # Run code to be tested + check exception:
        log_start_test_code()
        with self.assertRaises(TypeError):
            self.inst.delete_handle(testhandle, 'test1')
        log_end_test_code()
Exemplo n.º 26
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()
Exemplo n.º 27
0
    def test_add_additional_URL_to_inexistent_handle(self):
        """Test exception if handle does not exist."""
        log_new_test_case("test_add_additional_URL_to_inexistent_handle")

        # Test variables
        testhandle = self.inexistent_handle
        url = 'http://foo.foo'

        # Run code to be tested + check exception:
        log_start_test_code()
        with self.assertRaises(HandleNotFoundException):
            self.inst.add_additional_URL(testhandle, url)
        log_end_test_code()
Exemplo n.º 28
0
    def test_remove_additional_URL_inexistent_handle(self):
        """Test normal removal of additional URL from an inexistent handle."""
        log_new_test_case("test_remove_additional_URL_inexistent_handle")

        # Test variables
        testhandle = self.inexistent_handle
        url = 'http://first.foo'

        # Run code to be tested + check exception:
        log_start_test_code()
        with self.assertRaises(HandleNotFoundException):
            self.inst.remove_additional_URL(testhandle, url)
        log_end_test_code()
    def test_remove_additional_URL_inexistent_handle(self):
        """Test normal removal of additional URL from an inexistent handle."""
        log_new_test_case("test_remove_additional_URL_inexistent_handle")

        # Test variables
        testhandle = self.inexistent_handle
        url = 'http://first.foo'

        # Run code to be tested + check exception:
        log_start_test_code()
        with self.assertRaises(HandleNotFoundException):
            self.inst.remove_additional_URL(testhandle, url)
        log_end_test_code()
    def test_add_additional_URL_to_inexistent_handle(self):
        """Test exception if handle does not exist."""
        log_new_test_case("test_add_additional_URL_to_inexistent_handle")

        # Test variables
        testhandle = self.inexistent_handle
        url = 'http://foo.foo'

        # Run code to be tested + check exception:
        log_start_test_code()
        with self.assertRaises(HandleNotFoundException):
            self.inst.add_additional_URL(testhandle, url)
        log_end_test_code()
Exemplo n.º 31
0
    def test_modify_handle_value_HS_ADMIN(self):
        """Test exception when trying to modify HS_ADMIN."""
        log_new_test_case("test_modify_handle_value_HS_ADMIN")

        # Test variables
        testhandle = self.handle

        # Run code to be tested + check exception:
        log_start_test_code()
        with self.assertRaises(IllegalOperationException):
            self.inst.modify_handle_value(testhandle,
                                          HS_ADMIN='please let me in!')
        log_end_test_code()
    def test_modify_handle_value_without_authentication(self):
        """Test if exception when not authenticated."""
        log_new_test_case("test_modify_handle_value_without_authentication")

        # Test variables
        testhandle = self.handle
        inst_readonly = EUDATHandleClient(self.url, HTTPS_verify=self.https_verify)

        # Run code to be tested + check exception:
        log_start_test_code()
        with self.assertRaises(HandleAuthenticationError):
            inst_readonly.modify_handle_value(testhandle, foo='bar')
        log_end_test_code()
    def test_search_handle_emptylist(self):
        """Test empty search result."""
        log_new_test_case("test_search_handle_emptylist")

        log_start_test_code()
        val = self.inst.search_handle(URL=self.url_inexistent)
        log_end_test_code()

        # Check desired outcome:
        self.assertEqual(type(val),type([]),
            'Searching did not return a list, but: '+str(val)+', type: '+str(type(val)))
        self.assertEqual(len(val),0,
            'Searching did not return an empty list, but: '+str(val))
Exemplo n.º 34
0
    def test_modify_handle_value_without_authentication(self):
        """Test if exception when not authenticated."""
        log_new_test_case("test_modify_handle_value_without_authentication")

        # Test variables
        testhandle = self.handle
        inst_readonly = EUDATHandleClient(self.url,
                                          HTTPS_verify=self.https_verify)

        # Run code to be tested + check exception:
        log_start_test_code()
        with self.assertRaises(HandleAuthenticationError):
            inst_readonly.modify_handle_value(testhandle, foo='bar')
        log_end_test_code()
    def test_search_handle(self):
        """Test searching for handles with any url (server should return list of handles)."""
        log_new_test_case("test_search_handle")

        log_start_test_code()
        val = self.inst.search_handle(URL='*')
        log_end_test_code()

        # Check desired outcome:
        self.assertEqual(type(val),type([]),
            'Searching did not return a list, but: '+str(val))
        self.assertTrue(len(val) > 0,
            'Searching did not return any handles!')
        self.assertTrue(self.inst.check_handle_syntax(val[0]),
            'Searching returned handles with a wrong syntax, e.g.: '+str(val[0]))
    def test_delete_handle_inexistent(self):
        """Test deleting an inexistent handle."""
        log_new_test_case("test_delete_handle_inexistent")

        # Test variables
        testhandle = self.inexistent_handle
        
        # Run code to be tested:
        log_start_test_code()
        resp = self.inst.delete_handle(self.inexistent_handle)
        log_end_test_code()

        # Check desired effects on handle:
        self.assertIsNone(resp,
            'Response (when deleting inexistent handle) should be None, but is: '+str(resp))
Exemplo n.º 37
0
    def test_delete_handle_inexistent(self):
        """Test deleting an inexistent handle."""
        log_new_test_case("test_delete_handle_inexistent")

        # Test variables
        testhandle = self.inexistent_handle

        # Run code to be tested:
        log_start_test_code()
        resp = self.inst.delete_handle(self.inexistent_handle)
        log_end_test_code()

        # Check desired effects on handle:
        self.assertIsNone(
            resp,
            'Response (when deleting inexistent handle) should be None, but is: '
            + str(resp))
    def test_search_handle_for_url(self):
        """Test searching for url with wildcards."""
        log_new_test_case("test_search_handle_for_url")

        log_start_test_code()
        val1 = self.inst.search_handle(URL='*dkrz*')
        log_end_test_code()
        log_start_test_code()
        val2 = self.inst.search_handle('*dkrz*')
        log_end_test_code()

        # Check desired outcome:
        self.assertEqual(type(val1),type([]),
            'Searching did not return a list, but: '+str(val1)+', type: '+str(type(val1)))
        self.assertEqual(val1, val2,
            'Searching with or without keyword did not return the same result:'+\
            '\nwith keyword: '+str(val1)+'\nwithout: '+str(val2))
    def test_add_additional_URL_another(self):
        """Test adding an additional URL."""
        log_new_test_case("test_add_additional_URL_another")

        # Test variables:
        testhandle = self.handle_withloc
        url = 'http://third.foo'
        
        # Run code to be tested:
        log_start_test_code()
        self.inst.add_additional_URL(testhandle, url)
        log_end_test_code()

        # Check desired effects on handle:
        contained = self.inst.is_URL_contained_in_10320LOC(testhandle, url)
        self.assertTrue(contained,
            'The URL was not added.')
    def test_delete_handle_normal(self):
        """Test deleting an entire record."""
        log_new_test_case("test_delete_handle_normal")

        # Test variables
        testhandle = self.handle
        
        # Run code to be tested:
        log_start_test_code()
        resp = self.inst.delete_handle(testhandle)
        log_end_test_code()

        # Check desired effects on handle:
        # Check if handle really deleted:
        rec = self.inst.retrieve_handle_record_json(testhandle)
        self.assertIsNone(rec,
            'Record should be None after deletion, but is: '+str(resp))
Exemplo n.º 41
0
    def test_remove_additional_URL(self):
        """Test normal removal of additional URL from 10320/LOC."""
        log_new_test_case("test_remove_additional_URL")

        # Test variables
        testhandle = self.handle_withloc
        url = 'http://first.foo'

        # Run code to be tested:
        log_start_test_code()
        self.inst.remove_additional_URL(testhandle, url)
        log_end_test_code()

        # Check desired effects on handle:
        contained = self.inst.is_URL_contained_in_10320LOC(testhandle, url)
        self.assertFalse(contained,
            'After removal, the URL was still there.')
Exemplo n.º 42
0
    def test_add_additional_URL_first(self):
        """Test adding the first additional URL'(created the 10320/LOC entry)."""
        log_new_test_case("test_add_additional_URL_first")

        # Test variables
        testhandle = self.handle_withoutloc
        url = 'http://first.foo'

        # Run code to be tested:
        log_start_test_code()
        self.inst.add_additional_URL(testhandle, url)
        log_end_test_code()

        # Check desired effects on handle:
        contained = self.inst.is_URL_contained_in_10320LOC(testhandle, url)
        self.assertTrue(contained,
            'The (first) URL was not added or the 10320/LOC was not created.')
Exemplo n.º 43
0
    def test_add_additional_URL_another(self):
        """Test adding an additional URL."""
        log_new_test_case("test_add_additional_URL_another")

        # Test variables:
        testhandle = self.handle_withloc
        url = 'http://third.foo'
        
        # Run code to be tested:
        log_start_test_code()
        self.inst.add_additional_URL(testhandle, url)
        log_end_test_code()

        # Check desired effects on handle:
        contained = self.inst.is_URL_contained_in_10320LOC(testhandle, url)
        self.assertTrue(contained,
            'The URL was not added.')
    def test_add_additional_URL_first(self):
        """Test adding the first additional URL'(created the 10320/LOC entry)."""
        log_new_test_case("test_add_additional_URL_first")

        # Test variables
        testhandle = self.handle_withoutloc
        url = 'http://first.foo'

        # Run code to be tested:
        log_start_test_code()
        self.inst.add_additional_URL(testhandle, url)
        log_end_test_code()

        # Check desired effects on handle:
        contained = self.inst.is_URL_contained_in_10320LOC(testhandle, url)
        self.assertTrue(contained,
            'The (first) URL was not added or the 10320/LOC was not created.')
Exemplo n.º 45
0
    def test_delete_handle_normal(self):
        """Test deleting an entire record."""
        log_new_test_case("test_delete_handle_normal")

        # Test variables
        testhandle = self.handle

        # Run code to be tested:
        log_start_test_code()
        resp = self.inst.delete_handle(testhandle)
        log_end_test_code()

        # Check desired effects on handle:
        # Check if handle really deleted:
        rec = self.inst.retrieve_handle_record_json(testhandle)
        self.assertIsNone(
            rec, 'Record should be None after deletion, but is: ' + str(resp))
    def test_remove_additional_URL(self):
        """Test normal removal of additional URL from 10320/LOC."""
        log_new_test_case("test_remove_additional_URL")

        # Test variables
        testhandle = self.handle_withloc
        url = 'http://first.foo'

        # Run code to be tested:
        log_start_test_code()
        self.inst.remove_additional_URL(testhandle, url)
        log_end_test_code()

        # Check desired effects on handle:
        contained = self.inst.is_URL_contained_in_10320LOC(testhandle, url)
        self.assertFalse(contained,
            'After removal, the URL was still there.')
Exemplo n.º 47
0
    def test_exchange_additional_URL_no10320LOC(self):
        """Test if replacing an URL has any effect if there is no 10320/LOC."""
        log_new_test_case("test_exchange_additional_URL_no10320LOC")

        # Test variables
        testhandle = self.handle_withoutloc
        old = 'http://first.foo'
        new = 'http://newfirst.foo'

        # Run the code to be tested:
        log_start_test_code()
        self.inst.exchange_additional_URL(testhandle, old, new)
        log_end_test_code()

        # Check desired effects on handle:
        contained = self.inst.is_URL_contained_in_10320LOC(testhandle, new)
        self.assertFalse(contained,
            'After replacing an URL in nonexistent 10320/LOC, the replacement was there.')
    def test_exchange_additional_URL_no10320LOC(self):
        """Test if replacing an URL has any effect if there is no 10320/LOC."""
        log_new_test_case("test_exchange_additional_URL_no10320LOC")

        # Test variables
        testhandle = self.handle_withoutloc
        old = 'http://first.foo'
        new = 'http://newfirst.foo'

        # Run the code to be tested:
        log_start_test_code()
        self.inst.exchange_additional_URL(testhandle, old, new)
        log_end_test_code()

        # Check desired effects on handle:
        contained = self.inst.is_URL_contained_in_10320LOC(testhandle, new)
        self.assertFalse(contained,
            'After replacing an URL in nonexistent 10320/LOC, the replacement was there.')
    def test_search_handle_wrong_url_test(self):
        """Test exception when wrong search servlet URL is given."""
        log_new_test_case("test_search_handle_wrong_url_test")

        # Make new client instance with existing but wrong url for searching:
        inst = EUDATHandleClient.instantiate_for_read_and_search(
            self.url,
            self.searchuser,
            self.searchpassword,
            reverselookup_baseuri=self.searchurl_wrong,
            reverselookup_url_extension=self.searchpath,
            HTTPS_verify=self.https_verify)

        # Run code to be tested + check exception:
        log_start_test_code()
        with self.assertRaises(ReverseLookupException):
            inst.search_handle(URL='*')
        log_end_test_code()
    def test_search_handle_hs_url_test(self):
        """Test exception when wrong search servlet URL (Handle Server REST API URL) is given."""
        log_new_test_case("test_search_handle_hs_url_test")

        # Make new instance with handle server url as search url:
        self.inst = EUDATHandleClient.instantiate_for_read_and_search(
            self.url,
            self.searchuser,
            self.searchpassword,
            reverselookup_baseuri=self.url,
            reverselookup_url_extension=self.path_to_api,
            HTTPS_verify=self.https_verify)

        # Run code to be tested + check exception:
        log_start_test_code()
        with self.assertRaises(ReverseLookupException):
            self.inst.search_handle(URL='*')
            # TODO specify exception
        log_end_test_code()
    def test_register_handle_already_exists(self):
        """Test if overwrite=False prevents handle overwriting."""
        log_new_test_case("test_register_handle_already_exists")

        # Test variables
        testhandle = self.handle

        # Run code to be tested + check exception:
        log_start_test_code()
        with self.assertRaises(HandleAlreadyExistsException):
            self.inst.register_handle(testhandle,
                                      'http://foo.foo',
                                      TEST1='I am just an illusion.')
        log_end_test_code()

        # Check if nothing was changed:
        rec = self.inst.retrieve_handle_record_json(testhandle)
        val1 = self.inst.get_value_from_handle(testhandle, 'TEST1', rec)
        self.assertEqual(val1, 'val1',
            'The handle should not be overwritten, thus this value should have stayed the same.')
Exemplo n.º 52
0
    def test_delete_handle_value_several_entries_one_nonexistent(self):
        """Test deleting several entries from a record, one of them does not exist."""
        log_new_test_case(
            "test_delete_handle_value_several_entries_one_nonexistent")

        # Test variables
        testhandle = self.handle

        # Run code to be tested:
        log_start_test_code()
        self.inst.delete_handle_value(testhandle, ['test1', 'test100'])
        log_end_test_code()

        # Check desired effects on handle:
        rec = self.inst.retrieve_handle_record_json(testhandle)
        val = self.inst.get_value_from_handle(testhandle, 'test1', rec)
        indices = self.inst.get_handlerecord_indices_for_key(
            'test1', rec['values'])
        self.assertIsNone(val,
                          'The index for the deleted entry should be None.')
        self.assertEqual(len(indices), 0,
                         'There should be no index for the deleted entry.')
Exemplo n.º 53
0
    def test_delete_handle_value_inexistent_entry(self):
        """Test deleting one entry from a record."""
        log_new_test_case("test_delete_handle_value_inexistent_entry")

        # Test variables
        testhandle = self.handle
        key = 'test100'

        # Run code to be tested:
        log_start_test_code()
        self.inst.delete_handle_value(testhandle, key)
        log_end_test_code()

        # Check desired effects on handle:
        rec = self.inst.retrieve_handle_record_json(testhandle)
        val = self.inst.get_value_from_handle(testhandle, key, rec)
        indices = self.inst.get_handlerecord_indices_for_key(
            key, rec['values'])
        self.assertIsNone(val,
                          'The index for the deleted entry should be None.')
        self.assertEqual(len(indices), 0,
                         'There should be no index for the deleted entry.')