示例#1
0
def test_Wiki__markdown_defined_markdownFile_is_None():
    markdown = "Somebody once told me the OS was gonna delete me. I'm not the largest file on the disk."

    # method under test
    wiki = Wiki(owner="doesn't matter", markdown=markdown)

    assert_equals(markdown, wiki.markdown)
def test_Wiki():
    """Test the construction and accessors of Wiki objects."""

    #Wiki contstuctor only takes certain values
    assert_raises(ValueError, Wiki, title='foo')

    #Construct a wiki and test uri's
    wiki = Wiki(title='foobar2', markdown='bar', owner={'id': '5'})
示例#3
0
def test_Wiki__markdown_is_None_markdownFile_defined():
    markdown_path = "/somewhere/over/the/rainbow.txt"
    with patch("synapseclient.wiki.open", mock_open(), create=True) as mocked_open,\
         patch("os.path.isfile", return_value=True):
        # method under test
        wiki = Wiki(owner="doesn't matter", markdownFile=markdown_path)

        mocked_open.assert_called_once_with(markdown_path, 'r')
        mocked_open().read.assert_called_once_with()
示例#4
0
def test_Wiki__with_markdown_file():
    markdown_data = """
                    MARK DOWN MARK DOWN MARK DOWN MARK DOWN
                    AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
                    adkflajsl;kfjasd;lfkjsal;kfajslkfjasdlkfj
                    """
    markdown_path = "/somewhere/over/the/rainbow.txt"
    with patch("synapseclient.wiki.open", mock_open(read_data=markdown_data), create=True) as mocked_open,\
         patch("os.path.isfile", return_value=True):
        # method under test
        wiki = Wiki(owner="doesn't matter", markdownFile=markdown_path)

        mocked_open.assert_called_once_with(markdown_path, 'r')
        mocked_open().read.assert_called_once_with()
        assert_equals(markdown_data, wiki.markdown)
示例#5
0
def test_wiki_with_none_attachments():
    syn = synapseclient.client.Synapse()
    with patch.object(syn, 'restPOST') as mock_restPOST:
        w = Wiki(owner="syn1", markdown="markdown", attachments=None)
        syn.store(w)
示例#6
0
def test_Wiki__markdownFile_path_not_exist():
    # method under test
    Wiki(owner="doesn't matter",
         markdownFile="/this/is/not/the/file/you/are/looking.for")
示例#7
0
def test_Wiki__markdown_and_markdownFile_both_defined():
    Wiki(owner="doesn't matter",
         markdown="asdf",
         markdownFile="~/fakeFile.txt")
def test_wikiAttachment():
    md = """
    This is a test wiki
    =======================

    Blabber jabber blah blah boo.
    """

    ## create a new project
    project = create_project()

    ## file the setup.py file to upload
    original_path = os.path.join(os.path.dirname(client.__file__), '..',
                                 'setup.py')

    ## upload a file to the file handle service
    fileHandle = syn._uploadFileToFileHandleService(original_path)

    #Create and store the wiki
    wiki = Wiki(owner=project,
                title='A Test Wiki',
                markdown=md,
                attachmentFileHandleIds=[fileHandle['id']])
    wiki = syn.store(wiki)

    #Create a wiki subpage
    subwiki = Wiki(owner=project,
                   title='A sub-wiki',
                   markdown='nothing',
                   parentWikiId=wiki.id)
    subwiki = syn.store(subwiki)

    ## retrieve the root wiki from Synapse
    wiki2 = syn.getWiki(project)
    assert wiki == wiki2

    ## retrieve the sub wiki from Synapse
    wiki2 = syn.getWiki(project, subpageId=subwiki.id)
    assert subwiki == wiki2

    ## try making an update
    wiki['title'] = 'A New Title'
    wiki['markdown'] = wiki['markdown'] + "\nNew stuff here!!!\n"
    wiki = syn.store(wiki)

    assert wiki['title'] == 'A New Title'
    assert wiki['markdown'].endswith("\nNew stuff here!!!\n")

    headers = syn.getWikiHeaders(project)
    assert headers['totalNumberOfResults'] == 2
    assert headers['results'][0]['title'] in (wiki['title'], subwiki['title'])

    ## retrieve the file we just uploaded
    #tmpdir = tempfile.mkdtemp()
    # file_props = syn._downloadWikiAttachment(project, wiki,
    #            os.path.basename(original_path), dest_dir=tmpdir)
    # ## we get back a dictionary with path, files and cacheDir
    # path = file_props['path']
    # ## check and delete it
    # assert os.path.exists(path)
    # assert filecmp.cmp(original_path, path)
    # shutil.rmtree(tmpdir)

    ## cleanup
    syn._deleteFileHandle(fileHandle)
    syn.delete(wiki)
    syn.delete(subwiki)

    ## test that delete worked
    try:
        deleted_wiki = syn.getWiki(project)
    except Exception as ex:
        assert ex.response.status_code == 404
    else:
        assert False, 'Should raise 404 exception'