Пример #1
0
    def test_Obsolete_output_dataFormat_URI_term(self):
        """Sending as 'dataFormat': obsolete URI and term
		Purpose:
			Sending obsolete URI and term to get an error
		Sent:
			Obsolete URI and term
		Expected outcome:
			Error returned, URI is invalid
		"""
        sent_resource = emptyInputTool()
        sent_resource['id'] = 'test_Obsolete_output_dataFormat_URI_term'
        sent_resource['function'] = [{
            'operation': [{
                'uri': 'http://edamontology.org/operation_0004',
                'term': 'Operation'
            }],
            'output': [{
                'dataType': {
                    'uri': 'http://edamontology.org/data_2044',
                    'term': 'Sequence'
                },
                'dataFormat': [{
                    'uri': 'http://edamontology.org/format_1228',
                    'term': 'UniGene entry format'
                }]
            }]
        }]

        expected_response = {
            'function': [{
                'output': [{
                    'dataFormat': [{
                        'general_errors':
                        ['Invalid URI: http://edamontology.org/format_1228.']
                    }]
                }]
            }]
        }

        response = self.client.post('/tool/', sent_resource, format='json')
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertEqual(json.loads(response.content), expected_response)

        expected_response = {'detail': 'Not found.'}

        response = self.client.get(
            '/tool/test_Obsolete_output_dataFormat_URI_term')
        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
        self.assertEqual(json.loads(response.content), expected_response)
Пример #2
0
    def test_inp_dFormat_array_array(self):
        """Sending array of arrays as 'dataFormat'
		Purpose:
			What happens when we send wrong type as the field (this case - array of numbers)
		Sent:
			Array of arrays of mixed types
		Expected outcome:
			Error informing about incorrect value
		"""
        sent_resource = emptyInputTool()
        sent_resource['id'] = 'test_inp_dFormat_array_array'
        sent_resource['function'] = [{
            'operation': [{
                'uri': 'http://edamontology.org/operation_0004',
                'term': 'Operation'
            }],
            'input': [{
                'dataType': {
                    'uri': 'http://edamontology.org/data_2044',
                    'term': 'Sequence'
                },
                'dataFormat': [[2, 3], '7']
            }]
        }]

        expected_response = {
            'function': [{
                'input': [{
                    'dataFormat': [{
                        'general_errors':
                        ['Invalid data. Expected a dictionary, but got list.']
                    }, {
                        'general_errors': [
                            'Invalid data. Expected a dictionary, but got unicode.'
                        ]
                    }]
                }]
            }]
        }

        response = self.client.post('/tool/', sent_resource, format='json')
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertEqual(json.loads(response.content), expected_response)

        expected_response = {'detail': 'Not found.'}

        response = self.client.get('/tool/test_inp_dFormat_array_array')
        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
        self.assertEqual(json.loads(response.content), expected_response)
    def test_functionDescription_number(self):
        """Sending number as 'functionDescription'
		Purpose:
			What happens when we send wrong type as the field (this case - number)
		Sent:
			Number
		Expected outcome:
			Resource registered with stringified number.
		"""
        sent_resource = emptyInputTool()
        sent_resource['id'] = 'test_functionDescription_number'
        sent_resource['function'] = [{
            'operation': [{
                'uri': 'http://edamontology.org/operation_0004',
                'term': 'Operation'
            }],
            'functionDescription':
            1234567890
        }]

        response = self.client.post('/tool/', sent_resource, format='json')
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)

        response = self.client.get('/tool/test_functionDescription_number',
                                   format='json')
        self.assertEqual(response.status_code, status.HTTP_200_OK)

        expected_resource = emptyOutputTool()

        expected_resource['id'] = 'test_functionDescription_number'
        expected_resource['function'] = [{
            'operation': [{
                'uri': 'http://edamontology.org/operation_0004',
                'term': 'Operation'
            }],
            'functionDescription':
            u'1234567890',
            'functionHandle':
            None,
            'input': [],
            'output': []
        }]

        received_resource = json.loads(response.content)
        received_resource['additionDate'] = None
        received_resource['lastUpdate'] = None

        self.assertEqual(expected_resource, received_resource)
Пример #4
0
    def test_out_dFormat_dict(self):
        """Sending dictionary as 'dataFormat'
		Purpose:
			What happens when we send wrong type as the field (this case - dict of mixed types)
		Sent:
			Dictionary with mixed types (strings and arrays)
		Expected outcome:
			Error informing about incorrect value
		"""
        sent_resource = emptyInputTool()
        sent_resource['id'] = 'test_out_dFormat_dict'
        sent_resource['function'] = [{
            'operation': [{
                'uri': 'http://edamontology.org/operation_0004',
                'term': 'Operation'
            }],
            'output': [{
                'dataType': {
                    'uri': 'http://edamontology.org/data_2044',
                    'term': 'Sequence'
                },
                'dataFormat': {
                    'a': 'b',
                    'c': [1, 2, 3]
                }
            }]
        }]

        expected_response = {
            'function': [{
                'output': [{
                    'dataFormat': {
                        'general_errors':
                        ['Expected a list of items but got type "dict".']
                    }
                }]
            }]
        }

        response = self.client.post('/tool/', sent_resource, format='json')
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertEqual(json.loads(response.content), expected_response)

        expected_response = {'detail': 'Not found.'}

        response = self.client.get('/tool/test_out_dFormat_dict')
        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
        self.assertEqual(json.loads(response.content), expected_response)
    def test_functionDescription_correct(self):
        """Sending string as 'functionDescription'
		Purpose:
			Basic test of successful sending of a string as functionDescription
		Sent:
			functionDescription as a string
		Expected outcome:
			Resource registered with the sent string
		"""
        sent_resource = emptyInputTool()
        sent_resource['id'] = 'test_functionDescription_correct'
        sent_resource['function'] = [{
            'operation': [{
                'uri': 'http://edamontology.org/operation_0004',
                'term': 'Operation'
            }],
            'functionDescription':
            'Just a functionDescription'
        }]
        response = self.client.post('/tool/', sent_resource, format='json')
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)

        response = self.client.get('/tool/test_functionDescription_correct',
                                   format='json')
        self.assertEqual(response.status_code, status.HTTP_200_OK)

        expected_resource = emptyOutputTool()

        expected_resource['id'] = 'test_functionDescription_correct'
        expected_resource['function'] = [{
            'operation': [{
                'uri': 'http://edamontology.org/operation_0004',
                'term': 'Operation'
            }],
            'functionDescription':
            'Just a functionDescription',
            'functionHandle':
            None,
            'input': [],
            'output': []
        }]

        received_resource = json.loads(response.content)
        received_resource['additionDate'] = None
        received_resource['lastUpdate'] = None

        self.assertEqual(expected_resource, received_resource)
    def test_functionDescription_1000_length(self):
        """Sending 1000 times character 'a' as 'functionDescription'
		Purpose:
			What happens when we send string of max allowed length
		Sent:
			1000 times 'a'
		Expected outcome:
			Resource registered with 1000 times 'a' as a functionDescription
		"""
        sent_resource = emptyInputTool()
        sent_resource['id'] = 'test_functionDescription_1000_length'
        sent_resource['function'] = [{
            'operation': [{
                'uri': 'http://edamontology.org/operation_0004',
                'term': 'Operation'
            }],
            'functionDescription':
            1000 * 'a'
        }]
        response = self.client.post('/tool/', sent_resource, format='json')
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)

        response = self.client.get(
            '/tool/test_functionDescription_1000_length', format='json')
        self.assertEqual(response.status_code, status.HTTP_200_OK)

        expected_resource = emptyOutputTool()

        expected_resource['id'] = 'test_functionDescription_1000_length'
        expected_resource['function'] = [{
            'operation': [{
                'uri': 'http://edamontology.org/operation_0004',
                'term': 'Operation'
            }],
            'functionDescription':
            1000 * 'a',
            'functionHandle':
            None,
            'input': [],
            'output': []
        }]

        received_resource = json.loads(response.content)
        received_resource['additionDate'] = None
        received_resource['lastUpdate'] = None

        self.assertEqual(expected_resource, received_resource)
    def test_functionDescription_non_ascii(self):
        """Sending string with non-ascii characters as 'functionDescription'
		Purpose:
			What happens when we send non-ascii characters
		Sent:
			String with non-ascii characters
		Expected outcome:
			Resource registered with the non-ascii characters
		"""
        sent_resource = emptyInputTool()
        sent_resource['id'] = 'test_functionDescription_non_ascii'
        sent_resource['function'] = [{
            'operation': [{
                'uri': 'http://edamontology.org/operation_0004',
                'term': 'Operation'
            }],
            'functionDescription':
            u'ąęćżźń£ Ø Δ ♥ †'
        }]
        response = self.client.post('/tool/', sent_resource, format='json')
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)

        response = self.client.get('/tool/test_functionDescription_non_ascii',
                                   format='json')
        self.assertEqual(response.status_code, status.HTTP_200_OK)

        expected_resource = emptyOutputTool()

        expected_resource['id'] = 'test_functionDescription_non_ascii'
        expected_resource['function'] = [{
            'operation': [{
                'uri': 'http://edamontology.org/operation_0004',
                'term': 'Operation'
            }],
            'functionDescription':
            u'ąęćżźń£ Ø Δ ♥ †',
            'functionHandle':
            None,
            'input': [],
            'output': []
        }]

        received_resource = json.loads(response.content)
        received_resource['additionDate'] = None
        received_resource['lastUpdate'] = None

        self.assertEqual(expected_resource, received_resource)
Пример #8
0
    def test_mismatch_correct_inp_dataType_URI_term(self):
        """Sending as 'dataType': mismatched URI and term
		Purpose:
			Sending correct URI with mismatched term
		Sent:
			Correct, but mismatched URI/term pair
		Expected outcome:
			Error returned, term does not match the URI
		"""
        sent_resource = emptyInputTool()
        sent_resource['id'] = 'test_mismatch_correct_inp_dataType_URI_term'
        sent_resource['function'] = [{
            'operation': [{
                'uri': 'http://edamontology.org/operation_0004',
                'term': 'Operation'
            }],
            'input': [{
                'dataType': {
                    'uri': 'http://edamontology.org/data_0006',
                    'term': 'Ontology'
                }
            }]
        }]

        expected_response = {
            'function': [{
                'input': [{
                    'dataType': {
                        'general_errors': [
                            'The term does not match the URI: Ontology, http://edamontology.org/data_0006.'
                        ]
                    }
                }]
            }]
        }

        response = self.client.post('/tool/', sent_resource, format='json')
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertEqual(json.loads(response.content), expected_response)

        expected_response = {'detail': 'Not found.'}

        response = self.client.get(
            '/tool/test_mismatch_correct_inp_dataType_URI_term')
        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
        self.assertEqual(json.loads(response.content), expected_response)
Пример #9
0
    def test_operation_duplicate(self):
        """Sending two identical strings as 'operation'
		Purpose:
			Checking if the system will remove duplicate elements
		Sent:
			Two identical operation strings
		Expected outcome:
			Resource registered without the duplicate string
		"""
        sent_resource = emptyInputTool()
        sent_resource['id'] = 'test_operation_duplicate'
        sent_resource['function'] = [{
            'operation': [{
                'uri': 'http://edamontology.org/operation_0004'
            }, {
                'uri': 'http://edamontology.org/operation_0004'
            }]
        }]
        response = self.client.post('/tool/', sent_resource, format='json')
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)

        response = self.client.get('/tool/test_operation_duplicate',
                                   format='json')
        self.assertEqual(response.status_code, status.HTTP_200_OK)

        expected_resource = emptyOutputTool()

        expected_resource['id'] = 'test_operation_duplicate'
        expected_resource['function'] = [{
            'operation': [{
                'uri': 'http://edamontology.org/operation_0004',
                'term': 'Operation'
            }],
            'functionDescription':
            None,
            'functionHandle':
            None,
            'input': [],
            'output': []
        }]

        received_resource = json.loads(response.content)
        received_resource['additionDate'] = None
        received_resource['lastUpdate'] = None

        self.assertItemsEqual(expected_resource, received_resource)
Пример #10
0
    def test_operation_extra_fields(self):
        """Sending array of dicts with extra fields as 'operation'
		Purpose:
			What happens when we send wrong type as the field (this case - add some fields to the object)
		Sent:
			Array of arrays of mixed types
		Expected outcome:
			Resource is registered, extra fields are ignored.
		"""
        sent_resource = emptyInputTool()
        sent_resource['id'] = 'test_operation_extra_fields'
        sent_resource['function'] = [{
            'operation': [{
                'uri': 'http://edamontology.org/operation_0004',
                'some': 'field'
            }]
        }]

        response = self.client.post('/tool/', sent_resource, format='json')
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)

        response = self.client.get('/tool/test_operation_extra_fields',
                                   format='json')
        self.assertEqual(response.status_code, status.HTTP_200_OK)

        expected_resource = emptyOutputTool()

        expected_resource['id'] = 'test_operation_extra_fields'
        expected_resource['function'] = [{
            'operation': [{
                'uri': 'http://edamontology.org/operation_0004',
                'term': 'Operation'
            }],
            'functionDescription':
            None,
            'functionHandle':
            None,
            'input': [],
            'output': []
        }]

        received_resource = json.loads(response.content)
        received_resource['additionDate'] = None
        received_resource['lastUpdate'] = None

        self.assertItemsEqual(expected_resource, received_resource)
Пример #11
0
    def test_inp_dFormat_number(self):
        """Sending number as 'dataFormat'
		Purpose:
			What happens when we send wrong type as the field (this case - number)
		Sent:
			Number
		Expected outcome:
			Error informing about incorrect value
		"""
        sent_resource = emptyInputTool()
        sent_resource['id'] = 'test_inp_dFormat_number'
        sent_resource['function'] = [{
            'operation': [{
                'uri': 'http://edamontology.org/operation_0004',
                'term': 'Operation'
            }],
            'input': [{
                'dataType': {
                    'uri': 'http://edamontology.org/data_2044',
                    'term': 'Sequence'
                },
                'dataFormat': 1234567890
            }]
        }]

        expected_response = {
            'function': [{
                'input': [{
                    'dataFormat': {
                        'general_errors':
                        ['Expected a list of items but got type "int".']
                    }
                }]
            }]
        }

        response = self.client.post('/tool/', sent_resource, format='json')
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertEqual(json.loads(response.content), expected_response)

        expected_response = {'detail': 'Not found.'}

        response = self.client.get('/tool/test_inp_dFormat_number')
        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
        self.assertEqual(json.loads(response.content), expected_response)
Пример #12
0
    def test_operation_Pass_URI_only(self):
        """Sending as 'operation': correct URI
		Purpose:
			Sending correct URI
		Sent:
			Correct URI
		Expected outcome:
			Resource registered - URI resolves to a concept, term filled in
		"""
        sent_resource = emptyInputTool()
        sent_resource['id'] = 'test_operation_Pass_URI_only'
        sent_resource['function'] = [{
            'operation': [{
                'uri': 'http://edamontology.org/operation_0004'
            }]
        }]
        response = self.client.post('/tool/', sent_resource, format='json')
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)

        response = self.client.get('/tool/test_operation_Pass_URI_only',
                                   format='json')
        self.assertEqual(response.status_code, status.HTTP_200_OK)

        expected_resource = emptyOutputTool()

        expected_resource['id'] = 'test_operation_Pass_URI_only'
        expected_resource['function'] = [{
            'operation': [{
                'uri': 'http://edamontology.org/operation_0004',
                'term': 'Operation'
            }],
            'functionDescription':
            None,
            'functionHandle':
            None,
            'input': [],
            'output': []
        }]

        received_resource = json.loads(response.content)

        received_resource['additionDate'] = None
        received_resource['lastUpdate'] = None

        self.assertItemsEqual(expected_resource, received_resource)
Пример #13
0
    def test_out_dFormat_empty_array(self):
        """Sending an empty arrays as 'dataFormat'
		Purpose:
			What happens when we send wrong type as the field (this case - empty array)
		Sent:
			Empty array
		Expected outcome:
			Error informing about empty array
		"""
        sent_resource = emptyInputTool()
        sent_resource['id'] = 'test_out_dFormat_empty_array'
        sent_resource['function'] = [{
            'operation': [{
                'uri': 'http://edamontology.org/operation_0004',
                'term': 'Operation'
            }],
            'output': [{
                'dataType': {
                    'uri': 'http://edamontology.org/data_2044',
                    'term': 'Sequence'
                },
                'dataFormat': []
            }]
        }]

        expected_response = {
            'function': [{
                'output': [{
                    'dataFormat': {
                        'general_errors': ['This list may not be empty.']
                    }
                }]
            }]
        }

        response = self.client.post('/tool/', sent_resource, format='json')
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertEqual(json.loads(response.content), expected_response)

        expected_response = {'detail': 'Not found.'}

        response = self.client.get('/tool/test_out_dFormat_empty_array')
        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
        self.assertEqual(json.loads(response.content), expected_response)
	def test_functionHandle_301_length(self):
		"""Sending 301 times character 'a' as 'functionHandle'
		Purpose:
			What happens when we send more characters than allowed
		Sent:
			301 times 'a'
		Expected outcome:
			Error message informing user of the string length limit
		"""
		sent_resource = emptyInputTool()
		sent_resource['id'] = 'test_functionHandle_301_length'
		sent_resource['function'] = [
			{
				'operation': [
					{
						'uri': 'http://edamontology.org/operation_0004',
						'term': 'Operation'
					}
				],
				'functionHandle': 301*'a'
			}
		]

		expected_response = {
			'function': [
				{
					'functionHandle': [
						'Ensure this field has no more than 300 characters.'
					]
				}	
			]
		}

		response = self.client.post('/tool/', sent_resource, format='json')
		self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
		self.assertEqual(json.loads(response.content), expected_response)

		expected_response = {
			'detail': 'Not found.'
		}
		
		response = self.client.get('/tool/test_functionHandle_301_length')
		self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
		self.assertEqual(json.loads(response.content), expected_response)
	def test_functionHandle_empty_none(self):
		"""Sending null/None as 'functionHandle'
		Purpose:
			What happens when we send None
		Sent:
			None
		Expected outcome:
			Error informing that this field cannot be null/None
		"""
		sent_resource = emptyInputTool()
		sent_resource['id'] = 'test_functionHandle_empty_none'
		sent_resource['function'] = [
			{
				'operation': [
					{
						'uri': 'http://edamontology.org/operation_0004',
						'term': 'Operation'
					}
				],
				'functionHandle': None
			}
		]
		
		expected_response = {
			'function': [
				{
					'functionHandle': [
						'This field may not be null.'
					]
				}	
			]
		}

		response = self.client.post('/tool/', sent_resource, format='json')
		self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
		self.assertEqual(json.loads(response.content), expected_response)

		expected_response = {
			'detail': 'Not found.'
		}
		
		response = self.client.get('/tool/test_functionHandle_empty_none')
		self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
		self.assertEqual(json.loads(response.content), expected_response)
Пример #16
0
    def test_incorrect_input_dataType_URI(self):
        """Sending as 'dataType': incorrect URI
		Purpose:
			Sending incorrect URI to get an error
		Sent:
			Obsolete URI
		Expected outcome:
			Error returned, URI is invalid
		"""
        sent_resource = emptyInputTool()
        sent_resource['id'] = 'test_incorrect_input_dataType_URI'
        sent_resource['function'] = [{
            'operation': [{
                'uri': 'http://edamontology.org/operation_0004',
                'term': 'Operation'
            }],
            'input': [{
                'dataType': {
                    'uri': 'http://edamontology.org/invalid',
                }
            }]
        }]

        expected_response = {
            'function': [{
                'input': [{
                    'dataType': {
                        'general_errors':
                        ['Invalid URI: http://edamontology.org/invalid.']
                    }
                }]
            }]
        }

        response = self.client.post('/tool/', sent_resource, format='json')
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertEqual(json.loads(response.content), expected_response)

        expected_response = {'detail': 'Not found.'}

        response = self.client.get('/tool/test_incorrect_input_dataType_URI')
        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
        self.assertEqual(json.loads(response.content), expected_response)
Пример #17
0
    def test_inp_dFormat_none(self):
        """Sending a null/None as 'dataFormat'
		Purpose:
			What happens when we send wrong type as the field (this case - null/None)
		Sent:
			null/None
		Expected outcome:
			Error informing about the null/None
		"""
        sent_resource = emptyInputTool()
        sent_resource['id'] = 'test_inp_dFormat_none'
        sent_resource['function'] = [{
            'operation': [{
                'uri': 'http://edamontology.org/operation_0004',
                'term': 'Operation'
            }],
            'input': [{
                'dataType': {
                    'uri': 'http://edamontology.org/data_2044',
                    'term': 'Sequence'
                },
                'dataFormat': None
            }]
        }]

        expected_response = {
            'function': [{
                'input': [{
                    'dataFormat': ['This field may not be null.']
                }]
            }]
        }

        response = self.client.post('/tool/', sent_resource, format='json')
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertEqual(json.loads(response.content), expected_response)

        expected_response = {'detail': 'Not found.'}

        response = self.client.get('/tool/test_inp_dFormat_none')
        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
        self.assertEqual(json.loads(response.content), expected_response)
Пример #18
0
    def test_inp_dataType_string(self):
        """Sending as 'dataType': string
		Purpose:
			What happens when we send wrong type as the field (this case - string)
		Sent:
			String as dataType
		Expected outcome:
			Error informing about incorrect value
		"""
        sent_resource = emptyInputTool()
        sent_resource['id'] = 'test_inp_dataType_string'
        sent_resource['function'] = [{
            'operation': [{
                'uri': 'http://edamontology.org/operation_0004',
                'term': 'Operation'
            }],
            'input': [{
                'dataType': 'just a string'
            }]
        }]

        expected_response = {
            'function': [{
                'input': [{
                    'dataType': {
                        'general_errors': [
                            'Invalid data. Expected a dictionary, but got unicode.'
                        ]
                    }
                }]
            }]
        }

        response = self.client.post('/tool/', sent_resource, format='json')
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertEqual(json.loads(response.content), expected_response)

        expected_response = {'detail': 'Not found.'}

        response = self.client.get('/tool/test_inp_dataType_string')
        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
        self.assertEqual(json.loads(response.content), expected_response)
Пример #19
0
    def test_docsCitationInstructions_case_sensitive(self):
        """Sending camel case url as 'docsCitationInstructions'
		Purpose:
			What happens when we send URL with camel case
		Sent:
			Camel case URL
		Expected outcome:
			Resource registered with lowercase URL string
		"""
        sent_resource = emptyInputTool()
        sent_resource['id'] = 'test_docsCitationInstructions_case_sensitive'
        sent_resource['docs'] = {
            'docsCitationInstructions': 'HTTP://ExAmPlE.cOm'
        }

        response = self.client.post('/tool/', sent_resource, format='json')
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)

        response = self.client.get(
            '/tool/test_docsCitationInstructions_case_sensitive',
            format='json')
        self.assertEqual(response.status_code, status.HTTP_200_OK)

        expected_resource = emptyOutputTool()

        expected_resource[
            'id'] = 'test_docsCitationInstructions_case_sensitive'
        expected_resource['docs'] = {
            'docsCitationInstructions': 'HTTP://ExAmPlE.cOm',
            'docsTermsOfUse': None,
            'docsDownload': None,
            'docsHome': None,
            'docsDownloadSource': None,
            'docsDownloadBinaries': None,
            'docsGithub': None
        }

        received_resource = json.loads(response.content)
        received_resource['additionDate'] = None
        received_resource['lastUpdate'] = None

        self.assertEqual(expected_resource, received_resource)
    def test_usesVersion_dict(self):
        """Sending dictionary as 'usesVersion'
		Purpose:
			What happens when we send wrong type as the field (this case - dict of mixed types)
		Sent:
			Dictionary with mixed types (strings and arrays)
		Expected outcome:
			Resource registered with stringified dictionary.
		Note:
			Spaces are added to the stringified value.
		"""
        sent_resource = emptyInputTool()
        sent_resource['id'] = 'test_usesVersion_dict'
        sent_resource['uses'] = [{
            'usesName': 'just a usesName',
            'usesVersion': {
                'a': 'b',
                'c': [1, 2, 3]
            }
        }]

        response = self.client.post('/tool/', sent_resource, format='json')
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)

        response = self.client.get('/tool/test_usesVersion_dict',
                                   format='json')
        self.assertEqual(response.status_code, status.HTTP_200_OK)

        expected_resource = emptyOutputTool()

        expected_resource['id'] = 'test_usesVersion_dict'
        expected_resource['uses'] = [{
            'usesName': 'just a usesName',
            'usesVersion': "{u'a': u'b', u'c': [1, 2, 3]}",
            'usesHomepage': None
        }]

        received_resource = json.loads(response.content)
        received_resource['additionDate'] = None
        received_resource['lastUpdate'] = None

        self.assertEqual(expected_resource, received_resource)
Пример #21
0
	def test_mirror_array(self):
		"""Sending array as 'mirror'
		Purpose:
			What happens when we send wrong type as the field (this case - array of strings and arrays)
		Sent:
			Array with mixed types (strings and arrays)
		Expected outcome:
			Error informing about incorrect value
		"""
		sent_resource = emptyInputTool()
		sent_resource['id'] = 'test_mirror_array'
		sent_resource['mirror'] = ['a','b','c',['d']]

		expected_response = {
			'mirror': [
				[
					'This is not a valid URL: a.'
				],
				[
					'This is not a valid URL: b.'
				],
				[
					'This is not a valid URL: c.'
				],
				[
					'Wrong type found, expected unicode/string, got array/list.'
				]
			]
		}

		response = self.client.post('/tool/', sent_resource, format='json')
		self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
		self.assertEqual(json.loads(response.content), expected_response)

		expected_response = {
			'detail': 'Not found.'
		}
		
		response = self.client.get('/tool/test_mirror_array')
		self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
		self.assertEqual(json.loads(response.content), expected_response)
Пример #22
0
	def test_interfaceDocs_300_length(self):
		"""Sending 300 times character 'a' as 'interfaceDocs'
		Purpose:
			What happens when we send string of max allowed length
		Sent:
			300 times 'a'
		Expected outcome:
			Resource registered with 300 times 'a' as a interfaceDocs
		"""
		sent_resource = emptyInputTool()
		sent_resource['id'] = 'test_interfaceDocs_300_length'
		sent_resource['interface'] = [
			{
				'interfaceType': 'API',
				'interfaceDocs': 'http://' + 293*'a'
			}
		]

		response = self.client.post('/tool/', sent_resource, format='json')
		self.assertEqual(response.status_code, status.HTTP_201_CREATED)

		response = self.client.get('/tool/test_interfaceDocs_300_length', format='json')
		self.assertEqual(response.status_code, status.HTTP_200_OK)

		expected_resource = emptyOutputTool()

		expected_resource['id'] = 'test_interfaceDocs_300_length'
		expected_resource['interface'] = [
			{
				'interfaceType': 'API',
				'interfaceDocs': 'http://' + 293*'a',
				'interfaceSpecURL': None,
				'interfaceSpecFormat': None
			}
		]

		received_resource = json.loads(response.content)
		received_resource['additionDate'] = None
		received_resource['lastUpdate'] = None

		self.assertEqual(expected_resource, received_resource)
Пример #23
0
    def test_creditsDeveloper_correct_2(self):
        """Sending two strings as 'creditsDeveloper'
		Purpose:
			Basic test of successful sending of a string as creditsDeveloper
		Sent:
			creditsDeveloper as a string
		Expected outcome:
			Resource registered with the sent array of 2 strings
		"""
        sent_resource = emptyInputTool()
        sent_resource['id'] = 'test_creditsDeveloper_correct_2'
        sent_resource['credits'] = {
            'creditsDeveloper':
            ['Just a creditsDeveloper', 'another creditsDeveloper']
        }

        response = self.client.post('/tool/', sent_resource, format='json')
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)

        response = self.client.get('/tool/test_creditsDeveloper_correct_2',
                                   format='json')
        self.assertEqual(response.status_code, status.HTTP_200_OK)

        expected_resource = emptyOutputTool()

        expected_resource['id'] = 'test_creditsDeveloper_correct_2'
        expected_resource['credits'] = {
            'creditsDeveloper':
            ['Just a creditsDeveloper', 'another creditsDeveloper'],
            'creditsContributor': [],
            'creditsInstitution': [],
            'creditsInfrastructure': [],
            'creditsFunding': [],
            'creditsAffiliation': []
        }

        received_resource = json.loads(response.content)
        received_resource['additionDate'] = None
        received_resource['lastUpdate'] = None

        self.assertItemsEqual(expected_resource, received_resource)
Пример #24
0
	def test_interfaceDocs_non_ascii(self):
		"""Sending string with non-ascii characters as 'interfaceDocs'
		Purpose:
			What happens when we send non-ascii characters
		Sent:
			String with non-ascii characters
		Expected outcome:
			Resource registered with non-ascii URL
		"""
		sent_resource = emptyInputTool()
		sent_resource['id'] = 'test_interfaceDocs_non_ascii'
		sent_resource['interface'] = [
			{
				'interfaceType': 'API',
				'interfaceDocs': u'http://ąęćżźń£ØΔ♥†.com'
			}
		]

		response = self.client.post('/tool/', sent_resource, format='json')
		self.assertEqual(response.status_code, status.HTTP_201_CREATED)

		response = self.client.get('/tool/test_interfaceDocs_non_ascii', format='json')
		self.assertEqual(response.status_code, status.HTTP_200_OK)
		
		expected_resource = emptyOutputTool()

		expected_resource['id'] = 'test_interfaceDocs_non_ascii'
		expected_resource['interface'] = [
			{
				'interfaceType': 'API',
				'interfaceDocs': u'http://ąęćżźń£ØΔ♥†.com',
				'interfaceSpecURL': None,
				'interfaceSpecFormat': None
			}
		]

		received_resource = json.loads(response.content)
		received_resource['additionDate'] = None
		received_resource['lastUpdate'] = None

		self.assertEqual(expected_resource, received_resource)
Пример #25
0
	def test_interfaceDocs_case_sensitive(self):
		"""Sending camel case url as 'interfaceDocs'
		Purpose:
			What happens when we send URL with camel case
		Sent:
			Camel case URL
		Expected outcome:
			Resource registered with lowercase URL string
		"""
		sent_resource = emptyInputTool()
		sent_resource['id'] = 'test_interfaceDocs_case_sensitive'
		sent_resource['interface'] = [
			{
				'interfaceType': 'API',
				'interfaceDocs': 'HTTP://ExAmPlE.cOm'
			}
		]
		
		response = self.client.post('/tool/', sent_resource, format='json')
		self.assertEqual(response.status_code, status.HTTP_201_CREATED)

		response = self.client.get('/tool/test_interfaceDocs_case_sensitive', format='json')
		self.assertEqual(response.status_code, status.HTTP_200_OK)

		expected_resource = emptyOutputTool()

		expected_resource['id'] = 'test_interfaceDocs_case_sensitive'
		expected_resource['interface'] = [
			{
				'interfaceType': 'API',
				'interfaceDocs': 'HTTP://ExAmPlE.cOm',
				'interfaceSpecURL': None,
				'interfaceSpecFormat': None
			}
		]

		received_resource = json.loads(response.content)
		received_resource['additionDate'] = None
		received_resource['lastUpdate'] = None

		self.assertEqual(expected_resource, received_resource)
Пример #26
0
	def test_interfaceDocs_correct(self):
		"""Sending a correctly formatted string as 'interfaceDocs'
		Purpose:
			Basic test of successful sending of a string as interfaceDocs
		Sent:
			interfaceDocs as a string
		Expected outcome:
			Resource registered with the sent string
		"""
		sent_resource = emptyInputTool()
		sent_resource['id'] = 'test_interfaceDocs_correct'
		sent_resource['interface'] = [
			{
				'interfaceType': 'API',
				'interfaceDocs': 'http://example.org'
			}
		]
		
		response = self.client.post('/tool/', sent_resource, format='json')
		self.assertEqual(response.status_code, status.HTTP_201_CREATED)

		response = self.client.get('/tool/test_interfaceDocs_correct', format='json')
		self.assertEqual(response.status_code, status.HTTP_200_OK)

		expected_resource = emptyOutputTool()

		expected_resource['id'] = 'test_interfaceDocs_correct'
		expected_resource['interface'] = [
			{
				'interfaceType': 'API',
				'interfaceDocs': 'http://example.org',
				'interfaceSpecURL': None,
				'interfaceSpecFormat': None
			}
		]

		received_resource = json.loads(response.content)
		received_resource['additionDate'] = None
		received_resource['lastUpdate'] = None

		self.assertEqual(expected_resource, received_resource)
Пример #27
0
    def test_Topic_Pass_2_topics(self):
        """Sending as 'topic': 2 objects
		Purpose:
			Sending 2 topic objects to test if saving multiple topics works
		Sent:
			2 correct URI/term pairs
		Expected outcome:
			Resource registered with 2 topics
		"""
        sent_resource = emptyInputTool()
        sent_resource['id'] = 'test_Topic_Pass_2_topics'
        sent_resource['topic'] = [{
            'uri': 'http://edamontology.org/topic_3070',
            'term': 'Biology'
        }, {
            'uri': 'http://edamontology.org/topic_2821',
            'term': 'Unicellular eukaryotes'
        }]
        response = self.client.post('/tool/', sent_resource, format='json')
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)

        response = self.client.get('/tool/test_Topic_Pass_2_topics',
                                   format='json')
        self.assertEqual(response.status_code, status.HTTP_200_OK)

        expected_resource = emptyOutputTool()

        expected_resource['id'] = 'test_Topic_Pass_2_topics'
        expected_resource['topic'] = [{
            'uri': 'http://edamontology.org/topic_3070',
            'term': 'Biology'
        }, {
            'uri': 'http://edamontology.org/topic_2821',
            'term': 'Unicellular eukaryotes'
        }]

        received_resource = json.loads(response.content)
        received_resource['additionDate'] = None
        received_resource['lastUpdate'] = None

        self.assertEqual(expected_resource, received_resource)
    def test_contactName_dict(self):
        """Sending as 'contactName': dictionary
		Purpose:
			What happens when we send wrong type as the field (this case - dict of mixed types)
		Sent:
			Dictionary with mixed types (strings and arrays)
		Expected outcome:
			Resource registered with stringified value
		"""
        sent_resource = emptyInputTool()
        sent_resource['id'] = 'test_contactName_dict'
        sent_resource['contact'] = [{
            'contactName': {
                'a': 'b',
                'c': [1, 2, 3]
            },
            'contactURL': 'http://example.com'
        }]

        response = self.client.post('/tool/', sent_resource, format='json')
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)

        response = self.client.get('/tool/test_contactName_dict',
                                   format='json')
        self.assertEqual(response.status_code, status.HTTP_200_OK)

        expected_resource = emptyOutputTool()

        expected_resource['id'] = 'test_contactName_dict'
        expected_resource['contact'] = [{
            'contactName': "{u'a': u'b', u'c': [1, 2, 3]}",
            'contactURL': 'http://example.com',
            'contactEmail': None,
            'contactTel': None
        }]

        received_resource = json.loads(response.content)
        received_resource['additionDate'] = None
        received_resource['lastUpdate'] = None

        self.assertEqual(expected_resource, received_resource)
Пример #29
0
    def test_creditsDeveloper_duplicate(self):
        """Sending two identical strings as 'creditsDeveloper'
		Purpose:
			Checking if the system will remove duplicate elements
		Sent:
			Two identical creditsDeveloper strings
		Expected outcome:
			Resource registered without the duplicate string
		"""
        sent_resource = emptyInputTool()
        sent_resource['id'] = 'test_creditsDeveloper_duplicate'
        sent_resource['credits'] = {
            'creditsDeveloper':
            ['Just a creditsDeveloper', 'Just a creditsDeveloper']
        }

        response = self.client.post('/tool/', sent_resource, format='json')
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)

        response = self.client.get('/tool/test_creditsDeveloper_duplicate',
                                   format='json')
        self.assertEqual(response.status_code, status.HTTP_200_OK)

        expected_resource = emptyOutputTool()

        expected_resource['id'] = 'test_creditsDeveloper_duplicate'
        expected_resource['credits'] = {
            'creditsDeveloper': ['Just a creditsDeveloper'],
            'creditsDeveloper': [],
            'creditsContributor': [],
            'creditsInfrastructure': [],
            'creditsFunding': [],
            'creditsInstitution': []
        }

        received_resource = json.loads(response.content)
        received_resource['additionDate'] = None
        received_resource['lastUpdate'] = None

        self.assertItemsEqual(expected_resource, received_resource)
Пример #30
0
	def test_usesHomepage_correct(self):
		"""Sending a correctly formatted string as 'usesHomepage'
		Purpose:
			Basic test of successful sending of a string as usesHomepage
		Sent:
			usesHomepage as a string
		Expected outcome:
			Resource registered with the sent string
		"""
		sent_resource = emptyInputTool()
		sent_resource['id'] = 'test_usesHomepage_correct'
		sent_resource['uses'] = [
			{
				'usesName': 'just a usesName',
				'usesHomepage': 'http://example.org'
			}
		]
		
		response = self.client.post('/tool/', sent_resource, format='json')
		self.assertEqual(response.status_code, status.HTTP_201_CREATED)

		response = self.client.get('/tool/test_usesHomepage_correct', format='json')
		self.assertEqual(response.status_code, status.HTTP_200_OK)

		expected_resource = emptyOutputTool()

		expected_resource['id'] = 'test_usesHomepage_correct'
		expected_resource['uses'] = [
			{
				'usesName': 'just a usesName',
				'usesHomepage': 'http://example.org',
				'usesVersion': None
			}
		]

		received_resource = json.loads(response.content)
		received_resource['additionDate'] = None
		received_resource['lastUpdate'] = None

		self.assertEqual(expected_resource, received_resource)