Ejemplo n.º 1
0
 def test_initial_creation(self):
     config = SQLStorageConfiguration()
     self.assertEqual(config.url, 'sqlite:///:memory:')
     self.assertEqual(config.echo, False)
     self.assertEqual(config.encoding, 'utf-8')
     self.assertEqual(config.create_db, True)
     self.assertEqual(config.drop_all_first, True)
Ejemplo n.º 2
0
    def test_upload_from_file_exception(self):
        config = SQLStorageConfiguration()
        engine = SQLStorageEngine(config)
        engine.initialise()
        store = SQLPostProcessorsStore(engine)

        self.assert_upload_from_file_exception(store)
Ejemplo n.º 3
0
    def test_initialise(self):

        config = SQLStorageConfiguration()
        engine = SQLStorageEngine(config)
        engine.initialise()
        with self.assertRaises(StorageEngineException):
            engine.binaries_store()
Ejemplo n.º 4
0
    def test_linkedaccounts_storage(self):
        config = SQLStorageConfiguration()
        engine = SQLStorageEngine(config)
        engine.initialise()
        store = SQLLinkedAccountStore(engine)

        self.assert_linkedaccounts_storage(store)
Ejemplo n.º 5
0
    def test_load_from_sql(self):
        config = SQLStorageConfiguration()
        engine = SQLStorageEngine(config)
        engine.initialise()
        store = SQLPersonStore(engine)

        self.assert_upload_from_file(store)
Ejemplo n.º 6
0
    def test_upload_from_file_verbose(self):
        config = SQLStorageConfiguration()
        engine = SQLStorageEngine(config)
        engine.initialise()
        store = SQLServicesStore(engine)

        self.assert_upload_from_file(store, verbose=True)
Ejemplo n.º 7
0
    def test_upload_from_file(self):
        config = SQLStorageConfiguration()
        engine = SQLStorageEngine(config)
        engine.initialise()
        store = SQLGenderStore(engine)

        self.assert_upload_from_text_file(store)
Ejemplo n.º 8
0
    def test_upload_from_file(self):
        config = SQLStorageConfiguration()
        engine = SQLStorageEngine(config)
        engine.initialise()
        store = SQLDefaultVariableStore(engine)

        self.assert_upload_from_file(store)
Ejemplo n.º 9
0
    def test_load_services_exception(self):
        config = SQLStorageConfiguration()
        engine = SQLStorageEngine(config)
        engine.initialise()
        store = SQLServicesStore(engine)

        self.assert_load_exception(store)
Ejemplo n.º 10
0
    def test_upload_from_file(self):
        config = SQLStorageConfiguration()
        engine = SQLStorageEngine(config)
        engine.initialise()
        store = SQLPostQuestionProcessorsStore(engine)

        self.assert_upload_from_file(store, verbose=False)
Ejemplo n.º 11
0
    def test_empty_defaults(self):
        config = SQLStorageConfiguration()
        engine = SQLStorageEngine(config)
        engine.initialise()
        store = SQLDefaultVariableStore(engine)

        self.assert_empty_defaults(store)
Ejemplo n.º 12
0
    def test_load(self):
        config = SQLStorageConfiguration()
        engine = SQLStorageEngine(config)
        engine.initialise()
        store = SQLPostQuestionProcessorsStore(engine)

        self.assert_load(store)
Ejemplo n.º 13
0
    def test_empty_properties(self):
        config = SQLStorageConfiguration()
        engine = SQLStorageEngine(config)
        engine.initialise()
        store = SQLPropertyStore(engine)

        self.assert_empty_properties(store)
Ejemplo n.º 14
0
    def test_user_storage(self):
        config = SQLStorageConfiguration()
        engine = SQLStorageEngine(config)
        engine.initialise()
        store = SQLUserStore(engine)

        self.assert_user_storage(store)
Ejemplo n.º 15
0
    def test_variable_storage(self):
        config = SQLStorageConfiguration()
        engine = SQLStorageEngine(config)
        engine.initialise()
        store = SQLVariablesStore(engine)

        self.assert_variable_storage(store)
Ejemplo n.º 16
0
    def test_load_variables(self):
        config = SQLStorageConfiguration()
        engine = SQLStorageEngine(config)
        engine.initialise()
        store = SQLPatternNodesStore(engine)

        self.assert_upload_from_file(store)
Ejemplo n.º 17
0
    def test_upload_csv_files_from_directory_with_subdir(self):
        config = SQLStorageConfiguration()
        engine = SQLStorageEngine(config)
        engine.initialise()
        store = SQLMapsStore(engine)

        self.assert_upload_csv_files_from_directory_with_subdir(store)
Ejemplo n.º 18
0
    def test_category_by_groupid_storage(self):
        config = SQLStorageConfiguration()
        engine = SQLStorageEngine(config)
        engine.initialise()
        store = SQLCategoryStore(engine)
        self.assertEqual(store.storage_engine, engine)

        self.assert_category_by_groupid_storage(store)
Ejemplo n.º 19
0
    def test_upload_from_directory(self):
        config = SQLStorageConfiguration()
        engine = SQLStorageEngine(config)
        engine.initialise()
        store = SQLCategoryStore(engine)
        self.assertEqual(store.storage_engine, engine)

        self.assert_upload_from_directory(store)
Ejemplo n.º 20
0
    def setUp(self):
        config = SQLStorageConfiguration()
        storage_engine = SQLStorageEngine(config)
        storage_engine.initialise()

        client = AccountLinkerTestClient()
        self.context = client.create_client_context("TESTUSER")
        self.context.brain._security._account_linker = BasicAccountLinkerService(storage_engine)
Ejemplo n.º 21
0
    def upload(storetype,
               url,
               filename,
               dirname,
               subdir,
               extension,
               create=False,
               drop_all=False,
               verbose=False):
        outputLog(None, "")
        config = SQLStorageConfiguration()
        config.url = url
        config.create_db = create
        config.drop_all_first = drop_all

        engine = SQLStorageEngine(config)
        engine.initialise()
        store = Uploader._get_store(storetype, engine)

        outputLog(None, "Emptying [%s]" % storetype)
        store.empty()

        outputLog(None, "Loading [%s]" % storetype)

        if filename is not None:
            count, success = store.upload_from_file(filename,
                                                    commit=True,
                                                    verbose=verbose)
            outputLog(None, "Lines processed [%d]" % count)
            outputLog(None, "Entities successful [%s]" % success)

        elif dirname is not None:
            count, success = store.upload_from_directory(
                dirname,
                fileformat=Store.TEXT_FORMAT,
                extension=extension,
                subdir=subdir,
                commit=True,
                verbose=verbose)
            outputLog(None, "Lines processed [%d]" % count)
            outputLog(None, "Entities successful [%s]" % success)

        else:
            raise Exception("You must specify either --file or --dir")

        return count, success
Ejemplo n.º 22
0
    def test_storage_where_no_property(self):
        config = SQLStorageConfiguration()
        engine = SQLStorageEngine(config)
        engine.initialise()
        store = SQLConversationStore(engine)
        self.assertEqual(store.storage_engine, engine)

        self.assert_just_conversation_storage(store)
Ejemplo n.º 23
0
    def test_update_link_not_found(self):
        config = SQLStorageConfiguration()
        engine = SQLStorageEngine(config)
        engine.initialise()
        store = SQLLinkStore(engine)
        self.assertEqual(store.storage_engine, engine)

        self.assert_update_link_not_found(store)
Ejemplo n.º 24
0
    def test_get_all(self):
        config = SQLStorageConfiguration()
        engine = SQLStorageEngine(config)
        engine.initialise()
        store = SQLConversationStore(engine)

        with self.assertRaises(Exception):
            store._get_all()
Ejemplo n.º 25
0
    def test_remove_link_with_exception(self):
        config = SQLStorageConfiguration()
        engine = SQLStorageEngine(config)
        engine.initialise()
        store = SQLLinkStore(engine)
        self.assertEqual(store.storage_engine, engine)

        self.assert_remove_link_with_exception(store)
Ejemplo n.º 26
0
    def test_empty_named(self):
        config = SQLStorageConfiguration()
        engine = SQLStorageEngine(config)
        engine.initialise()
        store = SQLCategoryStore(engine)
        self.assertEqual(store.storage_engine, engine)

        self.assert_empty_name(store)
Ejemplo n.º 27
0
    def test_process_line_verbose(self):
        config = SQLStorageConfiguration()
        engine = SQLStorageEngine(config)
        engine.initialise()
        store = SQLPersonStore(engine)
        store.empty()

        store.process_line("test", ["field1", "field2"], verbose=True)
        store.process_line("test", ["field1", "field2"], verbose=False)
Ejemplo n.º 28
0
    def test_get_lookup_not_present(self):
        config = SQLStorageConfiguration()
        engine = SQLStorageEngine(config)
        engine.initialise()
        store = SQLPersonStore(engine)
        store.empty()

        collection = store.get_lookup()
        self.assertEquals({}, collection)
Ejemplo n.º 29
0
    def test_load_usergroups(self):
        config = SQLStorageConfiguration()
        engine = SQLStorageEngine(config)
        engine.initialise()
        store = SQLUserGroupStore(engine)

        yaml_data = yaml.load("""
         users:
           user1:
             groups:
               group1
           user2:
             groups:
               group4
           user3:
             groups:
               group1
                
         groups:
           group1:
             roles:
               role1, role2, role3  
             groups:
               group1, group2
             users:
               user1, user2

           group2:
             roles:
               role4, role5  
             groups:
               group5
             users:
               user3

           group3:
             roles:
               role6
               """, Loader=yaml.FullLoader)

        store.load_from_yaml(yaml_data, verbose=False)

        store.commit()

        authorisor = BasicUserGroupAuthorisationService(BrainSecurityAuthorisationConfiguration())
        store.load_usergroups(authorisor)

        self.assertTrue("user1" in authorisor.users)
        self.assertTrue("user2" in authorisor.users)
        self.assertTrue("user3" in authorisor.users)

        self.assertTrue("group1" in authorisor.groups)
        self.assertTrue("group2" in authorisor.groups)
        self.assertTrue("group3" in authorisor.groups)

        self.assertTrue(authorisor.authorise("user3", "role3"))
Ejemplo n.º 30
0
    def test_split_into_fields(self):
        config = SQLStorageConfiguration()
        engine = SQLStorageEngine(config)
        engine.initialise()
        store = SQLPropertyStore(engine)

        self.assertEquals(None, store.split_into_fields(""))
        self.assertEquals(None, store.split_into_fields("X"))
        self.assertEquals(['X', 'Y'], store.split_into_fields('"X","Y"'))
        self.assertEquals(['X', 'Y'], store.split_into_fields('"X","Y","Z"'))