Exemplo n.º 1
0
 def test_should_load_from_file_sucessfully(self):
     try:
         factory: IObjectFactory = ObjectFactory()
         factory.load_dependencies(FILE_PATH + '/dependencies.json')
         pass
     except Exception as e:
         self.assertTrue(False, str(e))
         pass
     pass
Exemplo n.º 2
0
    def test_should_add_dependency_with_sucess(self):
        try:
            factory: IObjectFactory = ObjectFactory()
            log_class: ILogging = type('log_class', (ILogging, ), {})

            factory.add_dependency('test_should_add_dependency_with_sucess',
                                   ILogging, log_class)
            self.assertTrue(True)
        except ValueError as e:
            self.assertTrue(False, str(e))
Exemplo n.º 3
0
    def test_should_not_load_from_file_notfound(self):
        try:
            factory: IObjectFactory = ObjectFactory()
            factory.load_dependencies(FILE_PATH + '/dependencies__.json')

            self.assertTrue(False)
            pass
        except Exception:
            self.assertRaises(FileNotFoundError)
            pass
        pass
Exemplo n.º 4
0
    def test_should_not_load_param_crawler_missing(self):
        try:
            factory: IObjectFactory = ObjectFactory()
            factory.load_dependencies(FILE_PATH + '/dependencies_no_crawler.json')

            self.assertTrue(False)
            pass
        except Exception as e:
            self.assertRaises(AttributeError)
            self.assertTrue(str(e).__contains__('crawler'))
            pass
        pass
Exemplo n.º 5
0
    def test_should_not_load_from_empty_json_file_param(self):
        try:
            factory: IObjectFactory = ObjectFactory()
            factory.load_dependencies('')

            repoFromGetInstance: ILogging = factory.get_instance('test', ILogging)
            self.assertTrue(repoFromGetInstance is None)
            pass
        except Exception as e:
            self.assertTrue(False, str(e))
            pass
        pass
Exemplo n.º 6
0
    def test_should_not_get_instance_from_unknown_dependency(self):
        try:
            factory: IObjectFactory = ObjectFactory()
            log_class: ILogging = type('log_class', (ILogging, ), {})

            factory.add_dependency('test_should_add_dependency_with_sucess',
                                   ILogging, log_class)
            repo_from_get_instance = factory.get_instance('test', ILogging)

            self.assertTrue(repo_from_get_instance is None)
        except Exception as e:
            self.assertTrue(False, str(e))
Exemplo n.º 7
0
    def test_should_get_instance_from_loaded_predefined_dependency(self):
        try:
            factory: IObjectFactory = ObjectFactory()
            factory.load_dependencies(FILE_PATH + '/dependencies.json')

            repo_from_get_instance: ILogging = factory.get_instance(
                'test', ILogging)
            self.assertTrue(isinstance(repo_from_get_instance, ILogging))

            repo_from_get_instance.log('Hello World!')
        except Exception as e:
            self.assertTrue(False, str(e))
Exemplo n.º 8
0
    def test_should_not_add_interface_not_subclass_abc(self):
        try:
            factory: IObjectFactory = ObjectFactory()
            factory.add_dependency(
                'test_should_not_add_interface_not_subclass_abc',
                type("not_abc_base_class", (), {}),
                type("not_abc_class", (), {}))

            self.assertTrue(False)
        except Exception as e:
            self.assertRaises(TypeError)
            self.assertTrue(str(e).lower().__contains__('not subclass of'))
Exemplo n.º 9
0
    def test_should_get_instance_from_added_dependency(self):
        try:
            factory: IObjectFactory = ObjectFactory()

            factory.add_dependency(
                'test_should_get_instance_from_added_dependency', ILogging,
                ChildClassILogging)

            repo_from_get_instance = factory.get_instance(
                'test_should_get_instance_from_added_dependency', ILogging)

            self.assertTrue(isinstance(repo_from_get_instance, ILogging))
        except Exception as e:
            self.assertTrue(False, str(e))
Exemplo n.º 10
0
    def test_should_not_add_dependency_isnt_instance_interface(self):
        try:
            factory: IObjectFactory = ObjectFactory()
            repo_class: IDataRepository = type('repo_class',
                                               (IDataRepository, ), {})

            factory.add_dependency(
                'test_should_not_add_dependency_isnt_instance_interface',
                ILogging, repo_class)

            self.assertTrue(False)
        except Exception as e:
            self.assertRaises(TypeError)
            self.assertTrue(str(e).lower().__contains__('not subclass of'))
Exemplo n.º 11
0
    def test_should_not_add_dependency_error_duplicate(self):
        try:
            factory: IObjectFactory = ObjectFactory()
            log_class: ILogging = type('log_class', (ILogging, ), {})

            factory.add_dependency(
                'test_should_not_add_dependency_error_duplicate', ILogging,
                log_class)
            factory.add_dependency(
                'test_should_not_add_dependency_error_duplicate', ILogging,
                log_class)

            self.assertTrue(False)
        except Exception as e:
            self.assertRaises(ValueError)
            self.assertTrue(str(e).lower() == 'dependecy already set')
Exemplo n.º 12
0
    def test_should_add_two_diff_dependencies_same_crawler(self):
        try:
            factory: IObjectFactory = ObjectFactory()
            repo_class: IDataRepository = type('repo_class',
                                               (IDataRepository, ), {})
            log_class: ILogging = type('log_class', (ILogging, ), {})

            factory.add_dependency(
                'test_should_add_two_diff_dependencies_same_crawler',
                IDataRepository, repo_class)
            factory.add_dependency(
                'test_should_add_two_diff_dependencies_same_crawler', ILogging,
                log_class)

            self.assertTrue(True)
        except Exception as e:
            self.assertTrue(False, str(e))