Example #1
0
    def test_MongoToYaml(self):
        Get = ctrs.get.Get()
        scenario_1()

        #docs = Get.cmd('cnts|q:_c:Usr|vflds:1')
        docs = Get.cmd('cnts')
        PyYaml.dump(docs, logCollNam='cnts', allflds=True)
Example #2
0
    def test_get_one(self):
        Get = ctrs.get.Get()
        DS = ctrs.d.DS()

        #docs = Get.cmd('cnts')
        #PyYaml.dump(docs, logCollNam='cnts', allflds=True)

        doc = Get.cmd('cnts:1|q:slug:ni')

        #docs = Get.cmd('cnts')
        PyYaml.dump([doc], logCollNam='cnts', allflds=True)

        assert True

        doc = Get.get_one(**dict(collNam='cnts', query=dict(_c='Usr'), vflds=True))
        assert doc['vNam'] == u"Stooge, Larry Wayne"
        doc = Get.cmd('cnts:1|q:_c:Usr|vflds:1')
        assert doc['vNam'] == u"Stooge, Larry Wayne"
Example #3
0
    def test_trash(self):
        g = self.g
        to_yaml = ctrs.d.to_yaml
        debug   = self.g['logger'].debug
        Put = ctrs.put.Put()
        Lnk = ctrs.lnk.Lnk()
        Post = ctrs.post.Post()
        Get = ctrs.get.Get()
        DS = ctrs.d.DS()

        if True:
            # start of cmd's to add/manipulate db
            # here are a few
            Post.cmd('Prs|slug:owner|fNam:John|lNam:Doe')
            Post.cmd('Cmp|slug:company|cNam:Company')
            Post.cmd('Cmp|slug:dept|cNam:Department')
            Post.cmd('Prs|slug:manager|fNam:Bill|lNam:Smith')
            Post.cmd('Prs|slug:employee|fNam:Tommy|lNam:Milton')
            Post.cmd('Pl|slug:atlanta-ga|city:Atlanta')
            Post.cmd('Pl|slug:ny-ny|city:New York')

            # test for valid _c
            # ie, Prs.owner. slug is owner, collection is cnts
            # BUT!!! _c needs to be confirmed
            Lnk.cmd('add|Cmp.company|Prs.owner|company-owner')
            Lnk.cmd('add|Cmp.dept|Cmp.company|dept-company')
            Lnk.cmd('add|Prs.manager|Cmp.dept|manager-dept')
            Lnk.cmd('add|Prs.employee|Prs.manager|employee-manager')

        docs = Get.cmd('cnts')
        DS.listDocs(docs)

        # this is the before trash action
        doc = Get.cmd('cnts:1|q:slug:owner')
        assert lTrimCompare(to_yaml(doc), \
            '''
            Prs.owner
              Children
                Cmp.company
                  Cmp.dept
                    Prs.manager
                      Prs.employee
            ''')

        doc = Get.cmd('cnts:1|q:slug:company')
        assert lTrimCompare(to_yaml(doc), \
            '''
            Cmp.company
              pars
                Prs.owner.company
              pths
                Prs.owner.owner: [Prs.owner]
              Children
                Cmp.dept
                  Prs.manager
                    Prs.employee
            ''')

        doc = Get.cmd('cnts:1|q:slug:employee')
        assert lTrimCompare(to_yaml(doc), \
            '''
            Prs.employee
              pars
                Prs.manager.employee
              pths
                Prs.manager.manager: [Prs.manager]
                Cmp.dept.dept: [Cmp.dept,Prs.manager]
                Cmp.company.company: [Cmp.company,Cmp.dept,Prs.manager]
                Prs.owner.owner: [Prs.owner,Cmp.company,Cmp.dept,Prs.manager]
            ''')

        # trash lnk
        # direct call
        resp = Lnk.trash(**dict(chld_=dict(_c='Cmp', slug='company'), par_= dict(_c='Prs', slug='owner'), role_='company-owner'))
        resp['response']['doc']['pars'][0]['trash'] == True


        # using cmd shortcut
        # TODO: create Put.recycle to unset trash field
        resp = Put.cmd('set|Cmp|q:slug:company|pars.0.trash:0')

        resp = Lnk.cmd('del|Cmp.company|Prs.owner|company-owner')
        resp['response']['doc']['pars'][0]['trash'] == True


        # check at least one of doc.pths that should now have trash = True
        doc = Get.cmd('cnts:1|q:slug:employee')
        doc['pths'][3]['trash'] == True


        #docs = Get.cmd('cnts|q:_c:Usr|vflds:1')
        docs = Get.cmd('cnts|vflds:1')
        PyYaml.dump(docs, logCollNam='cnts', allflds=True)
        # PyYaml.dump(docs, logCollNam='cnts', onlyflds=['vNam'])
        # PyYaml.dump(docs, logCollNam='cnts', onlyflds=['_c','vNam','slug','pars'])


        x=0