コード例 #1
0
class TestWrite(unittest.TestCase):
    def setUp(self):
        self.username = '******'
        self.password = '******'
        self.json_handler_OBJ = JSON_methods()
        self.json_handler_OBJ.session = requests.Session()
        self.json_handler_OBJ.session.auth = (self.username, self.password)
        self.write_OBJ = Write(None)

    def tearDown(self):
        pass

    def test_set_json_handler_Method(self):
        json_handler = None
        self.write_OBJ = Write(json_handler)
        self.write_OBJ.set_json_handler(self.json_handler_OBJ)
        self.assertIsInstance(self.write_OBJ.json_handler, JSON_methods)

    def test_data_file_hash_Method(self):
        return_value = self.write_OBJ.data_file_hash('title', 'desc', 'view',
                                                     '1', 'licence', 'url',
                                                     'filename')
        self.assertIsInstance(return_value, dict)

    def test_assay_hash_Method(self):
        return_value = self.write_OBJ.assay_hash('title', 'desc', 'view', '1',
                                                 'assay_class', 'assay_type',
                                                 'assay_tech_type')
        self.assertIsInstance(return_value, dict)

    def test_study_hash_Method(self):
        return_value = self.write_OBJ.study_hash('title', 'desc', 'view', '1')
        self.assertIsInstance(return_value, dict)

    def test_investigation_hash_Method(self):
        return_value = self.write_OBJ.investigation_hash(
            'title', 'desc', 'view', '1')
        self.assertIsInstance(return_value, dict)

    def test_post_tab_creation_Method(self):
        self.assertEqual(self.write_OBJ.create_tab, None)
        self.write_OBJ.post_tab_creation('desc', 'Create')
        self.assertNotEqual(self.write_OBJ.create_tab, None)
        self.write_OBJ.post_tab_creation('desc', 'Update')
        self.assertNotEqual(self.write_OBJ.create_tab, None)

    def test_doc_write_Method(self):
        self.assertEqual(self.write_OBJ.doc_write_tab, None)
        self.write_OBJ.doc_write('Create')
        self.assertNotEqual(self.write_OBJ.doc_write_tab, None)
        self.write_OBJ.doc_write('Update')
        self.assertNotEqual(self.write_OBJ.doc_write_tab, None)

    def test_compulsory_fields_Method(self):
        return_value = None
        self.assertEqual(return_value, None)
        return_value = self.write_OBJ.compulsory_fields()
        self.assertNotEqual(return_value, None)

    def test_data_file_fields_Method(self):
        return_value = None
        self.assertEqual(return_value, None)
        return_value = self.write_OBJ.data_file_fields()
        self.assertNotEqual(return_value, None)

    def test_optional_fields_Method(self):
        return_value = None
        self.assertEqual(return_value, None)
        return_value = self.write_OBJ.data_file_fields()
        self.assertNotEqual(return_value, None)

    def test_assay_fields_Method(self):
        return_value = None
        self.assertEqual(return_value, None)
        return_value = self.write_OBJ.assay_fields()
        self.assertNotEqual(return_value, None)

    def test_iterate_over_json_list_Method(self):
        return_value = None
        self.assertEqual(return_value, None)
        data = {}
        return_value = self.write_OBJ.iterate_over_json_list(data)
        self.assertNotEqual(return_value, None)
コード例 #2
0
class SEEK():
    '''
    Container of all classes
    All functions are called from this class
    FUNCTIONS :
        query       : select ID and type for searching
        post        : post a json
        search      : search a file based on query
        query       : set login details
        change_url  : FOR DEMO PURPOSE ONLY
                      Change url to sandbox website

    '''
    def __init__(self):
        self.json_handler = JSON_methods()
        self.SEEK_query = None
        self.SEEK_search = None
        self.SEEK_write = None

    def query(self):
        self.SEEK_query = Query(self.json_handler)
        self.SEEK_query.query()

    def post(self):
        if self.SEEK_write == None:
            self.SEEK_write = Write(self.json_handler)
        self.SEEK_write.post_choice()

    def search(self):
        self.SEEK_search = Search(self.json_handler)

        valid = True
        list_of_names = self.SEEK_query.get_list_of_user_names()
        list_of_ids = self.SEEK_query.get_list_of_user_ids()
        topic = self.SEEK_query.get_topic()
        if topic == 'Document query' or topic == 'Person query':
            settings_dict = self.SEEK_query.get_setting_options_dict()
            settings_dict = dict(settings_dict)
            id = self.SEEK_query.get_id_to_search()
            if id == '':
                print('ID is needed')
                valid = False
            type = self.SEEK_query.get_type_to_search()
            if valid == True:
                self.SEEK_search.search_parameters(topic, id, type,
                                                   settings_dict,
                                                   list_of_names, list_of_ids)
                self.SEEK_search.search()
        else:
            print('Select Document/Person query tab to search')

    def change_url(self):
        print('1: https://www.fairdomhub.org')
        print('2: https://sandbox3.fairdomhub.org')
        choice = input("Please choose url 1 or 2:\n")
        print('You entered {0}'.format(choice))
        self.json_handler.change_url(choice)
        if self.SEEK_query != None:
            self.SEEK_query.set_json_handler(self.json_handler)
        if self.SEEK_search != None:
            self.SEEK_search.set_json_handler(self.json_handler)

    def auth(self):
        self.json_handler.auth_request()
        # self.SEEK_query.set_json_handler(self.json_handler)
        if self.SEEK_query != None:
            self.SEEK_query.set_json_handler(self.json_handler)
        if self.SEEK_search != None:
            self.SEEK_search.set_json_handler(self.json_handler)
        if self.SEEK_write != None:
            self.SEEK_write.set_json_handler(self.json_handler)