示例#1
0
    def test_init_with_id(self):
        usergroups = UserGroups(usergroups={})
        usergroups.id = '666'

        self.assertIsNotNone(usergroups)
        self.assertEqual('666', usergroups.id)
        self.assertEqual({'_id': '666', 'usergroups': {}}, usergroups.to_document())
示例#2
0
    def test_from_document(self):
        usergroups1 = UserGroups.from_document({'usergroups': {}})
        self.assertIsNotNone(usergroups1)
        self.assertIsNone(usergroups1.id)
        self.assertEqual({}, usergroups1.usergroups)

        usergroups2 = UserGroups.from_document({'_id': '666', 'usergroups': {}})
        self.assertIsNotNone(usergroups2)
        self.assertEqual('666', usergroups2.id)
        self.assertEqual({}, usergroups2.usergroups)
示例#3
0
 def test_repr_with_id(self):
     usergroups2 = UserGroups.from_document({
         '_id': '666',
         'usergroups': {}
     })
     self.assertEqual("<UserGroups(id='666', usergroups='{}')>",
                      str(usergroups2))
示例#4
0
    def upload_from_file(self,
                         filename,
                         fileformat=Store.TEXT_FORMAT,
                         commit=True,
                         verbose=False):

        YLogger.info(self, "Uploading usergroups from [%s] to Mongo", filename)

        usergroup_data = self._upload_usergroup_as_yaml(filename)

        usergroups = UserGroups(usergroup_data)

        YLogger.info(self, "Adding new usergroups to Mongo")
        if self.add_document(usergroups) is True:
            return 1, 1

        return 0, 0
示例#5
0
    def upload_from_file(self, filename, format=Store.TEXT_FORMAT, commit=True, verbose=False):

        YLogger.info(self, "Uploading usergroups from [%s] to Mongo", filename)

        usergroup_data = self._upload_usergroup_as_yaml(filename)

        collection = self.collection()
        usergroups = collection.find_one({})
        if usergroups is not None:
            usergroups.usergroups = usergroup_data
            collection.update(usergroups)
            YLogger.info(self, "Replacing existing usergroups in Mongo")
        else:
            usergroups = UserGroups(usergroup_data)
            self.add_document(usergroups)
            YLogger.info(self, "Adding new usergroups to Mongo")

        return 1, 1
示例#6
0
    def test_init_no_id(self):
        usergroups = UserGroups(usergroups={})

        self.assertIsNotNone(usergroups)
        self.assertIsNone(usergroups.id)
        self.assertEqual({'usergroups': {}}, usergroups.to_document())
示例#7
0
 def test_repr_no_id(self):
     usergroups1 = UserGroups.from_document({'usergroups': {}})
     self.assertEqual("<UserGroups(id='n/a', usergroups='{}')>",
                      str(usergroups1))
示例#8
0
 def test_from_document_no_id(self):
     usergroups1 = UserGroups.from_document({'usergroups': {}})
     self.assertIsNotNone(usergroups1)
     self.assertIsNone(usergroups1.id)
     self.assertEqual({}, usergroups1.usergroups)