Пример #1
0
 def test_create_context(self):
     self._print("ContextTests.test_context")
     if self.off(): return
     metadata = ContextMetadata()
     context = Context(metadata)
     cdocs = context.cdocs
     self.assertEqual( len(cdocs), 5, msg=f"must be 4 cdocs, not {len(cdocs)} from {cdocs}" )
Пример #2
0
 def test_get_doc_from_right_root(self) :
     self._print(f"ContextTests.test_get_doc_from_right_root")
     if self.off(): return
     metadata = ContextMetadata()
     context = Context(metadata)
     docpath = "/app/home/teams/todos/assignee"
     txt = context.get_doc_from_roots(["public"], docpath)
     self.assertIsNotNone(txt, msg=f"doc at {docpath} in root 'public' must not be none")
Пример #3
0
 def test_get_doc_from_wrong_root(self) :
     self._print(f"ContextTests.test_get_doc_from_wrong_root")
     if self.off(): return
     metadata = ContextMetadata()
     context = Context(metadata)
     docpath = "/app/home/teams/todos/assignee"
     txt = context.get_doc_from_roots(["images"], docpath, False)
     self.assertIsNone(txt, msg=f"doc at {docpath} in root 'images' must be none")
Пример #4
0
 def setup(self,
           configpath: Optional[str] = None,
           askdebug: Optional[bool] = True):
     self.ask_debug()
     configpath = self.ask_config()
     metadata = None
     self._config = SimpleConfig(configpath)
     self._metadata = ContextMetadata(self._config)
     self._context = Context(self._metadata)
Пример #5
0
 def test_get_known_type_doc(self):
     self._print(f"ContextTests.test_get_known_type_doc")
     if self.off(): return
     metadata = ContextMetadata()
     context = Context(metadata)
     docpath = "/app/home/teams/3-copy.png"
     f = context.get_doc(docpath)
     self._print(f"the image doc {type(f)} ")
     self.assertIsNotNone(f, msg=f"doc at {docpath} must not be none")
     self.assertEqual( type(f).__name__, 'bytes', msg=f"type must be 'bytes'")
Пример #6
0
 def test_get_doc_just_checking(self) :
     self._print(f"ContextTests.test_get_doc_just_checking")
     if self.off(): return
     metadata = ContextMetadata()
     context = Context(metadata)
     docpath = "/app/home/teams*delete_assignee"
     txt = context.get_doc(docpath)
     # this doc could be a not-found doc. for what I need today that's fine.
     self.assertIsNotNone(txt, msg=f"doc at {docpath} must not be none")
     self._print(f"ContextTests.test_get_doc_just_checking: doing get_docs. the doc txt is: {txt}")
Пример #7
0
 def test_filter_root_names_for_path(self):
     self._print("ContextTests.test_filter_root_names_for_path")
     if self.off(): return
     metadata = ContextMetadata()
     context = Context(metadata)
     roots = ["images", "fish", "public"]
     rs = context.filter_root_names_for_path(roots, "/x/y/z")
     self._print(f"filtered roots: {rs}")
     self.assertIsNotNone( rs, msg="filtered roots must not be None")
     self.assertEqual(len(rs), 1, msg="must be 1 filtered root")
     self.assertEqual(rs, ["public"], msg="filtered roots must be ['public']")
Пример #8
0
 def test_get_filetype(self):
     self._print("ContextTests.test_get_filetype")
     if self.off(): return
     metadata = ContextMetadata()
     context = Context(metadata)
     atype = context.get_filetype("/x/y/z.gif")
     self._print(f"type for /x/y/z.gif: {atype}")
     self.assertEqual(atype, "gif", msg="type must be gif")
     atype = context.get_filetype("/x/y/z")
     self._print(f"type for /x/y/z: {atype}")
     self.assertEqual(atype, 'cdocs', msg="type must be cdocs")
Пример #9
0
 def test_get_doc(self) :
     self._print(f"ContextTests.test_get_doc")
     if self.off(): return
     metadata = ContextMetadata()
     context = Context(metadata)
     docpath = "/app/home/teams/todos/assignee"
     txt = context.get_doc(docpath)
     self.assertIsNotNone(txt, msg=f"doc at {docpath} must not be none")
     self._print(f"test_get_doc: doing get_docs. the doc txt is: {txt}")
     point = txt.find("assignee in company starstruck!")
     self.assertNotEqual(-1,point, msg="must include 'assignee in company starstruck!'")
     point = txt.find("my app name: you should see: my app's name is fruit")
     self.assertNotEqual(-1,point, msg="must include 'my app name: you should see: my app's name is fruit'")
Пример #10
0
 def test_get_root_names_accepting_path(self):
     self._print("ContextTests.test_get_root_names_accepting_path")
     if self.off(): return
     metadata = ContextMetadata()
     context = Context(metadata)
     gifs = context.get_root_names_accepting_path("/x/y/z.gif")
     self._print(f"roots for /x/y/z.gif: {gifs}")
     self.assertIsNotNone( gifs, msg="gifs must not be None")
     self.assertEqual(len(gifs), 1, msg="must be 1 items in gifs")
     cdocs = context.get_root_names_accepting_path("/x/y/z")
     self._print(f"roots for /x/y/z: {cdocs}")
     self.assertIsNotNone( cdocs, msg="cdocs must not be None")
     self.assertEqual(len(cdocs), 2, msg="must be 2 items in cdocs")
Пример #11
0
 def test_get_labels(self):
     self._print(f"ContextTests.test_get_labels")
     if self.off(): return
     docpath = "/app/home/teams/todos/assignee"
     #docpath = "/v1/test/fish"
     metadata = ContextMetadata()
     context = Context(metadata)
     labels = context.get_labels(docpath)
     print(f"test_get_labels: the labels are: {labels}")
     self.assertIn("app", labels, msg=f"labels at {docpath} must include key 'app'")
     self.assertIn("team", labels, msg=f"labels at {docpath} must include key 'team'")
     self.assertIn("my_app_name", labels, msg=f"labels at {docpath} must include key 'my_app_name'")
     self.assertEqual("my app's name is fruit", labels["my_app_name"], msg=f"label my app name must == my app's name is fruit")
     self.assertEqual("starstruck", labels["company"], msg=f"label company must == starstruck")
Пример #12
0
 def test_accepts(self):
     self._print("ContextTests.test_accepts")
     if self.off(): return
     metadata = ContextMetadata()
     accepts = metadata.accepts
     if self.noise: self._print(f"accepts: {accepts}")
     self.assertIsNotNone( accepts, msg="accepts must not be None")
     self.assertEqual(len(accepts), 5, msg=f"must be 4 keys in accepts, not {accepts}")
     self.assertIsNotNone( accepts["images"], msg="accepts must have an 'images' key")
     images = accepts["images"]
     self.assertEqual(len(images), 4, msg="must be 4 items in images")
     self.assertIn("gif", images, msg=f"images must include item 'gif'")
     self.assertIn("png", images, msg=f"images must include item 'png'")
     self.assertIn("jpg", images, msg=f"images must include item 'jpg'")
     self.assertIn("jpeg", images, msg=f"images must include item 'jpeg'")
Пример #13
0
 def test_accepted_by(self):
     self._print("ContextTests.test_accepted_by")
     if self.off(): return
     metadata = ContextMetadata()
     accceptedby = metadata.accepted_by
     self._print(f"accceptedby: {accceptedby}")
     self.assertIsNotNone( accceptedby, msg="accceptedby must not be None")
     self.assertEqual(len(accceptedby), 7, msg=f"must be 7 keys in accceptedby, not {accceptedby}")
     self.assertIsNotNone( accceptedby["cdocs"], msg="accepts must have a 'cdocs' key")
     cdocs = accceptedby["cdocs"]
     self.assertEqual(len(cdocs), 2, msg="must be 2 items in cdocs")
     self.assertIn("public", cdocs, msg=f"cdocs must include item 'public'")
     self.assertIn("internal", cdocs, msg=f"cdocs must include item 'internal'")
     gif = accceptedby["gif"]
     self.assertIn("images", gif, msg=f"gif must include item 'images'")
Пример #14
0
 def test_get_compose_doc_with_roots(self):
     self._print(f"ContextTests.test_get_compose_doc_with_roots")
     if self.off(): return
     docpath = "/app/home/teams"
     metadata = ContextMetadata()
     context = Context(metadata)
     doc = context.get_doc_from_roots(["internal"], docpath, False)
     self._print(f"test_get_compose_doc_with_roots: doc from 'internal': {doc}")
     assignee = doc.find('assignee in company starstruck!')
     self.assertNotEqual(-1, assignee, msg=f'{docpath} must include "assignee in company starstruck!" in {doc}')
     edit = doc.find('edit assignee')
     self.assertNotEqual(-1, edit, msg=f'{docpath} must include "edit assignee" in {doc}')
     doc = context.get_doc_from_roots(["public"], docpath)
     self._print(f"test_get_compose_doc_with_roots: doc from 'public': {doc}")
     notfound = doc.find("Not found!")
     self.assertNotEqual(notfound, -1, msg=f'doc at {docpath} must include "Not found!"')
Пример #15
0
 def test_formats(self):
     self._print(f"MetadataTests.test_formats")
     if self.off(): return
     metadata = ContextMetadata()
     formats = metadata.formats["public"]
     self._print(f"MetadataTests.test_formats: formats are: {formats}")
     self.assertEqual(
         2,
         len(formats),
         msg=f'formats for public must be 2, not {len(formats)}')
     self.assertIn("xml",
                   formats,
                   msg=f"formats must include xml: {formats}")
     users = metadata.uses_format["xml"]
     self._print(f"MetadataTests.test_formats: users are: {users}")
     self.assertEqual(2,
                      len(users),
                      msg=f'users of xml must be 2, not {len(users)}')
     self.assertIn("public",
                   users,
                   msg=f"users of xml must include public: {users}")
Пример #16
0
    def __init__(self, docspath:str, config:Optional[Config]=None, context:Optional[MultiContextDocs]=None):
        super().__init__()
        cfg = SimpleConfig(None) if config is None else config
        self._config = cfg
        self._context:MultiContextDocs = context
        self._docs_path:FilePath = docspath
        self._rootname = cfg.get_matching_key_for_value("docs", docspath)
        if self._rootname is None:
            raise ConfigException(f"Cdocs.__init__: no rootname for {docspath}")
        self._set_ext()
        self._tokens_filename:str  = cfg.get("filenames", "tokens", "tokens.json")
        self._labels_filename:str  = cfg.get("filenames", "labels", "labels.json")
        self._hashmark:str  = cfg.get("filenames", "hashmark", "#")
        self._plus:str  = cfg.get("filenames", "plus", "+")
        self._accepts = None

        self._track_last_change = False
        self._last_change = None
        self._last_change = self.get_last_change()
        #
        # these helpers can be swapped in and out as needed
        #
        self._concatter = SimpleConcatter(self)
        self._lister = SimpleLister(self)
        self._filer = SimpleFiler(self)
        self._transformer = SimpleTransformer(self)
        self._reader = SimpleReader(self) if cfg.reader is None else cfg.reader
        self._finder = SimpleFinder(self) if cfg.finder is None else cfg.finder

        if cfg.pather is None:
            logging.info("Cdocs.__init__: config's pather is None: {cfg}")
            metadata = ContextMetadata(cfg)
            #metadata.config = cfg
            self._pather = SimplePather(metadata, self)
            pass
        else:
            self._pather = cfg.pather
        logging.info(f"Cdocs.__init__: completed init. Cdocs is:\n{str(self)}")
Пример #17
0
 def test_roots(self):
     self._print("ContextTests.test_roots")
     if self.off(): return
     metadata = ContextMetadata()
     roots = metadata.roots
     self.assertEqual( len(roots), 5, msg="must be 4 roots" )
Пример #18
0
    def test_split_plus_concat(self):
        # tests the use of:
        #    split-plus searches
        #    non-split-plus searches
        #    split-plus searches with roots that deny split-plus
        #    implicitly, the order of multi-root searches
        # see config.ini re: order of roots under [doc] in the
        # context of split-plus searches
        docpath = "app/home/teams#delete_assignee+todo"
        metadata = ContextMetadata()
        context = Context(metadata)

        # split plus: true
        #    both roots allow split plus
        doc = context.get_doc(docpath)
        print(f"\nContextTests.test_split_plus_concat: doc 1:\n{doc}")
        self.assertIsNotNone(doc, msg=f"doc at {docpath} must not be none")
        found = doc.find("edit assignee") > -1
        found = found and doc.find("my app name: you should see") > -1
        self.assertEqual(found, True, msg=f"doc: {doc} doesn't have expected content")

        # split plus: false
        #    both roots allow split plus
        doc = context.get_doc(docpath, False, False)
        print(f"\nContextTests.test_split_plus_concat: doc 2:\n{doc}")
        found = doc.find("edit assignee") > -1
        found = found and doc.find("my app name: you should see") > -1
        self.assertEqual(found, False, msg=f"doc: {doc} doesn't have expected content")

        context._nosplitplus = ['internal','public']

        # split plus: true
        #    both roots deny split plus
        doc = context.get_doc(docpath)
        print(f"\nContextTests.test_split_plus_concat: doc 3:\n{doc}")
        self.assertIsNotNone(doc, msg=f"doc at {docpath} must not be none")
        found = doc.find("edit assignee") == -1
        found = found and doc.find("my app name: you should see") == -1
        self.assertEqual(found, True, msg=f"doc: {doc} doesn't have expected content")
        # split plus: false
        #    both roots deny split plus
        doc = context.get_doc(docpath, False, False)
        print(f"\nContextTests.test_split_plus_concat: doc 4:\n{doc}")
        found = doc.find("edit assignee") == -1
        found = found and doc.find("my app name: you should see") == -1
        self.assertEqual(found, False, msg=f"doc: {doc} doesn't have expected content")

        context._nosplitplus = ['public']

        # split plus: true
        #    public denies split plus
        doc = context.get_doc(docpath)
        print(f"\nContextTests.test_split_plus_concat: doc 5:\n{doc}")
        self.assertIsNotNone(doc, msg=f"doc at {docpath} must not be none")
        found = doc.find("edit assignee") > -1
        found = found and doc.find("my app name: you should see") == -1
        self.assertEqual(found, True, msg=f"doc: {doc} doesn't have expected content")
        # split plus: false
        #    public denies split plus
        doc = context.get_doc(docpath, False, False)
        print(f"\nContextTests.test_split_plus_concat: doc 6:\n{doc}")
        found = doc.find("edit assignee") == -1
        found = found and doc.find("my app name: you should see") > -1
        self.assertEqual(found, True, msg=f"doc: {doc} doesn't have expected content")

        context._nosplitplus = ['internal']

        # split plus: true
        #    internal denies split plus
        doc = context.get_doc(docpath)
        print(f"\nContextTests.test_split_plus_concat: doc 7:\n{doc}")
        self.assertIsNotNone(doc, msg=f"doc at {docpath} must not be none")
        found = doc.find("edit assignee") == -1
        found = found and doc.find("my app name: you should see") > -1
        self.assertEqual(found, True, msg=f"doc: {doc} doesn't have expected content")

        # split plus: false
        #    internal denies split plus
        doc = context.get_doc(docpath, False, False)
        print(f"\nContextTests.test_split_plus_concat: doc 8:\n{doc}")
        found = doc.find("edit assignee") == -1
        found = found and doc.find("my app name: you should see") > -1
        self.assertEqual(found, True, msg=f"doc: {doc} doesn't have expected content")