Example #1
0
 def iter_samples(self):
     #FIXME: This is not very useful
     for f in self.get_files_from_data_dir("*"):
         n = Note.Note(Utils.random_string(), Utils.random_string())
         n.set_mtime(datetime.datetime.now())
         n.set_UID(Utils.random_string())
         yield n
def create_file(inDirURI):
    name = Utils.random_string()+".txt"
    uri = Vfs.uri_join(inDirURI.replace("file://",""),name)
    f = open(uri,'w')
    f.write(Utils.random_string())
    f.close()
    return name,uri
Example #3
0
def new_text(txt):
    if txt == None:
        txt = Utils.random_string()
    t = Text.Text(
                text=txt
                )
    t.set_UID(Utils.random_string())
    t.set_open_URI(Utils.random_string())
    return t
Example #4
0
def new_contact(filename):
    if filename == None:
        txt = read_data_file_from_data_dir("1.vcard")
    else:
        txt = read_data_file_from_data_dir(filename)
    c = Contact.Contact()
    c.set_from_vcard_string(txt)
    c.set_UID(Utils.random_string())
    c.set_open_URI(Utils.random_string())
    return c
Example #5
0
def new_event(filename):
    if filename == None:
        txt = read_data_file_from_data_dir("1.ical")
    else:
        txt = read_data_file_from_data_dir(filename)
    e = Event.Event()
    e.set_from_ical_string(txt)
    e.set_UID(Utils.random_string())
    e.set_open_URI(Utils.random_string())
    return e
Example #6
0
def new_email(content):
    if content == None:
        content = Utils.random_string()
    e = Email.Email(
                content=content,
                subject=Utils.random_string()
                )
    e.set_UID(Utils.random_string())
    e.set_open_URI(Utils.random_string())
    return e
Example #7
0
def new_setting(data):
    if data == None:
        data = Utils.random_string()
    s = Setting.Setting(
                key=Utils.random_string(),
                value=data
                )                
    s.set_UID(Utils.random_string())
    s.set_open_URI(None)
    return s
Example #8
0
def new_bookmark(data):
    if data == None:
        data = Utils.random_string()
    b = Bookmark.Bookmark(
                    title=data,
                    uri="http://www.%s.com" % Utils.random_string()
                    )
    b.set_UID(Utils.random_string())
    b.set_open_URI(b.get_uri())
    return b
Example #9
0
def new_note(title):
    if title == None:
        title = Utils.random_string()
    n = Note.Note(
                title=title,
                contents=Utils.random_string()
                )
    n.set_UID(Utils.random_string())
    n.set_mtime(datetime.datetime(1977,3,23))
    n.set_open_URI(Utils.random_string())
    return n
Example #10
0
 def iter_samples(self):
     # FIXME: This is not very useful
     for f in self.get_files_from_data_dir("*.ical"):
         t = Text.Text(text=open(f).read())
         t.set_mtime(datetime.datetime.now())
         t.set_UID(Utils.random_string())
         yield t
Example #11
0
def new_video(filename):
    v = Video.Video(
                URI=filename
                )                
    v.set_UID(Utils.random_string())
    v.set_open_URI(filename)
    return v
Example #12
0
    def __init__(self, sourceName=None, sinkName=None):
        #Set up our own mapping DB so we dont pollute the global one
        dbFile = os.path.join(os.environ['TEST_DIRECTORY'],Utils.random_string()+".db")
        conduit.GLOBALS.mappingDB = MappingDB.MappingDB(dbFile)

        #Dynamically load all datasources, datasinks and converters
        dirs_to_search =    [
                            conduit.SHARED_MODULE_DIR,
                            os.path.join(conduit.USER_DIR, "modules")
                            ]

        self.model = Module.ModuleManager(dirs_to_search)
        conduit.GLOBALS.moduleManager = self.model
        self.model.load_all(whitelist=None, blacklist=None)
        self.type_converter = TypeConverter.TypeConverter(self.model)
        conduit.GLOBALS.typeManager = self.type_converter
        self.sync_manager = Synchronization.SyncManager(self.type_converter)
        conduit.GLOBALS.syncManager = self.sync_manager

        ok("Environment ready", self.model != None and self.type_converter != None and self.sync_manager != None)

        self.source = None
        if sourceName != None:
            self.source = self.get_dataprovider(sourceName)

        self.sink = None
        if sinkName != None:
            self.sink = self.get_dataprovider(sinkName)

        self.sync_set = SyncSet.SyncSet(
                        moduleManager=self.model,
                        syncManager=self.sync_manager
                        )
Example #13
0
 def iter_samples(self):
     for f in self.get_files_from_data_dir("*.vcard"):
         txt = open(f).read()
         c = Contact.Contact()
         c.set_from_vcard_string(txt)
         c.set_mtime(datetime.datetime.now())
         c.set_UID(Utils.random_string())
         yield c
Example #14
0
 def iter_samples(self):
     for f in self.get_files_from_data_dir("*.ical"):
         txt = open(f).read()
         e = Event.Event()
         e.set_from_ical_string(txt)
         e.set_mtime(datetime.datetime.now())
         e.set_UID(Utils.random_string())
         yield e
Example #15
0
def new_audio(filename = None):
    if not filename:
        filename = get_files_from_data_dir("*.mp3")[0]
    a = Audio.Audio(
                URI=filename
                )                
    a.set_UID(Utils.random_string())
    a.set_open_URI(filename)
    return a
Example #16
0
def new_file(filename):
    if filename == None:
        f = Utils.new_tempfile(Utils.random_string())
    else:
        files = get_files_from_data_dir(filename)
        f = File.File(URI=files[0])
    uri = f._get_text_uri()
    f.set_UID(uri)
    f.set_open_URI(uri)
    return f
Example #17
0
    def _get_unique_filename(self, directory):
        """
        Returns the name of a non-existant file on the
        ipod within directory

        @param directory: Name of the directory within the device root to make
        the random file in
        """
        done = False
        while not done:
            f = os.path.join(self.mountPoint, directory, Utils.random_string())
            if not os.path.exists(f):
                done = True
        return f
Example #18
0
    def _get_unique_filename(self, directory):
        """
        Returns the name of a non-existant file on the
        ipod within directory

        @param directory: Name of the directory within the device root to make
        the random file in
        """
        done = False
        while not done:
            f = os.path.join(self.mountPoint,directory,Utils.random_string())
            if not os.path.exists(f):
                done = True
        return f
Example #19
0
 def __init__(self):
     DataProvider.DataProviderBase.__init__(self)
     #Through an error on the nth time through
     self.errorAfter = 999
     self.errorFatal = False
     self.newHash = False
     self.newMtime = False
     self.slow = False
     self.UID = Utils.random_string()
     self.numData = 5
     #Variables to test the config fuctions
     self.aString = ""
     self.aInt = 0
     self.aBool = False
     self.aList = []
     self.count = 0
Example #20
0
 def __init__(self):
     self.update_configuration(
         errorAfter = 999,
         errorFatal = False,
         newHash = False,
         newMtime = False,
         slow = False,
         UID = Utils.random_string(),
         numData = 5,
         #Variables to test the config fuctions
         aString = "",
         aInt = 0,
         aBool = False,
         aList = [],
         count = 0,
     )
Example #21
0
 def __init__(self):
     self.update_configuration(
         errorAfter=999,
         errorFatal=False,
         newHash=False,
         newMtime=False,
         slow=False,
         UID=Utils.random_string(),
         numData=5,
         #Variables to test the config fuctions
         aString="",
         aInt=0,
         aBool=False,
         aList=[],
         count=0,
     )
Example #22
0
        def setUpSync(self):
            # FIXME: I'd put this in an EnvironmentWrapper, but i need priorities before i can do that :/
            conduit.IS_INSTALLED =              False
            conduit.IS_DEVELOPMENT_VERSION =    True
            conduit.SHARED_DATA_DIR =           os.path.join(soup.get_root(),"data")
            conduit.SHARED_MODULE_DIR =         os.path.join(soup.get_root(),"conduit","modules")
            conduit.BROWSER_IMPL =              os.environ.get("CONDUIT_BROWSER_IMPL","system")
            conduit.SETTINGS_IMPL =             os.environ.get("CONDUIT_SETTINGS_IMPL","Python")
            conduit.GLOBALS.settings =          Settings.Settings()

            #Set up our own mapping DB so we dont pollute the global one
            dbFile = os.path.join(os.environ['TEST_DIRECTORY'],Utils.random_string()+".db")
            conduit.GLOBALS.mappingDB = MappingDB.MappingDB(dbFile)

            self.modules = Module.ModuleManager([])
            conduit.GLOBALS.moduleManager = self.modules
            self.modules.load_all(whitelist=None, blacklist=None)

            self.type_converter = conduit.TypeConverter.TypeConverter(self.modules)
            conduit.GLOBALS.typeConverter = self.type_converter
            self.sync_manager = conduit.Synchronization.SyncManager(self.type_converter)
            conduit.GLOBALS.syncManager = self.sync_manager
Example #23
0
    def get(self, LUID):
        DataProvider.DataSource.get(self, LUID)
        if self.slow:
            time.sleep(1)

        index = int(LUID)
        if index >= self.errorAfter:
            if self.errorFatal:
                raise Exceptions.SyncronizeFatalError("Error After:%s Count:%s" % (self.errorAfter, index))
            else:
                raise Exceptions.SyncronizeError("Error After:%s Count:%s" % (self.errorAfter, index))

        mtime = DEFAULT_MTIME
        if self.newMtime:
            mtime = datetime.datetime.now()
            
        hash = DEFAULT_HASH
        if self.newHash:
            hash = Utils.random_string()

        data = TestDataType(LUID, mtime, hash)
        return data
Example #24
0
    def get(self, LUID):
        DataProvider.DataSource.get(self, LUID)
        if self.slow:
            time.sleep(1)

        index = int(LUID)
        if index >= self.errorAfter:
            if self.errorFatal:
                raise Exceptions.SyncronizeFatalError(
                    "Error After:%s Count:%s" % (self.errorAfter, index))
            else:
                raise Exceptions.SyncronizeError("Error After:%s Count:%s" %
                                                 (self.errorAfter, index))

        mtime = DEFAULT_MTIME
        if self.newMtime:
            mtime = datetime.datetime.now()

        hash = DEFAULT_HASH
        if self.newHash:
            hash = Utils.random_string()

        data = TestDataType(LUID, mtime, hash)
        return data
Example #25
0
 def get_UID(self):
     return Utils.random_string()
Example #26
0
import os
import time
import datetime
import tempfile

try:
    f = File.File()
except:
    ok("Base: Must specify URI", True)

null = File.File("/foo/bar")
ok("Base: non-existant file", null.exists() == False)

# test tempfile handling
temp = Utils.new_tempfile(Utils.random_string())
ok("Base: Detected tempfile", temp.is_local() and temp._is_tempfile())

uri = temp.get_local_uri()
ok("Base: Tempfile in temp dir", uri and uri.startswith(tempfile.gettempdir()))

temp.delete()
gone = File.File(uri)
ok("Base: Delete tempfile", not gone.exists())

# test making directories
tmpdir = Utils.new_tempdir()
tmpdir2 = os.path.join(tmpdir, "subdir")
f = File.File(tmpdir2)
ok("Base: make directory", f.make_directory() == True)
Example #27
0
 def generate_sample(self):
     f = Utils.new_tempfile(Utils.random_string())
     uri = f._get_text_uri()
     f.set_UID(uri)
     f.set_open_URI(uri)
     return f
Example #28
0
 def add(self, LUID):
     #Add a temp file to folder
     tmpfile = Utils.new_tempfile(Utils.random_string())
     self.put(tmpfile,True,None)
Example #29
0
 def text_to_note(self, text, **kwargs):
     n = Note.Note(title=_("Note-") + Utils.random_string(), contents=text)
     return n
Example #30
0
 def generate_sample(self):
     e = Email.Email(content=Utils.random_string(), subject=Utils.random_string())
     e.set_mtime(datetime.datetime.now())
     e.set_UID(Utils.random_string())
     return e
Example #31
0
 def get_UID(self):
     return Utils.random_string()
Example #32
0
 def __init__(self, *args):
     DataProvider.DataSource.__init__(self, *args)
     _TestBase.__init__(self)
     self.UID = Utils.random_string()
Example #33
0
 def add(self, LUID):
     #Add a temp file to folder
     tmpfile = Utils.new_tempfile(Utils.random_string())
     self.put(tmpfile, True, None)
Example #34
0
 def __init__(self, *args):
     _TestBase.__init__(self)
     DataProvider.DataSource.__init__(self)
     self.UID = Utils.random_string()
Example #35
0
 def text_to_note(self, text, **kwargs):
     n = Note.Note(
                 title=_("Note-")+Utils.random_string(),
                 contents=text
                 )
     return n
config = {
    "username":     os.environ.get("TEST_USERNAME","*****@*****.**"),
    "password":     os.environ["TEST_PASSWORD"],
}
test.configure(sink=config)
google = test.get_sink().module

#Log in
try:
    google.refresh()
    ok("Logged in", google.loggedIn == True)
except Exception, err:
    ok("Logged in (%s)" % err, False) 

#make a new contact with a random email address (so it doesnt conflict)
contact = Contact.parse_vcf(vcfData % Utils.random_string())[0]
test.do_dataprovider_tests(
        supportsGet=True,
        supportsDelete=True,
        safeLUID=SAFE_CONTACT_ID,
        data=contact,
        name="contact"
        )

#check we get a conflict if we put a contact with a known existing email address
#FIXME: We should actually automatically resolve this conflict...
contact = new_contact(None)
try:
    google.put(contact, False)
    ok("Detected duplicate email", False)
except Exceptions.SynchronizeConflictError:
Example #37
0
from common import *
import conduit.datatypes.File as File
import conduit.utils as Utils

import os
import tempfile
import datetime
import random
import stat

tmpdir = tempfile.mkdtemp()
ok("Created tempdir %s" % tmpdir, True)

contents = Utils.random_string()
name = Utils.random_string()+".foo"
tmpFile = File.TempFile(contents)

tmpFile.force_new_filename(name)
ok("Set filename to %s" % name, tmpFile._newFilename == name)

newPath = os.path.join(tmpdir, name)
tmpFile.transfer(tmpdir)
ok("Transferred -> %s" % newPath, os.path.isfile(newPath))

f = File.File(newPath)
ok("File contents = %s" % contents, f.get_contents_as_text() == contents)
mtime = f.get_mtime()

f = File.File(newPath)
ok("File name ok", f.get_filename() == name)