Пример #1
0
def test___eq__():
    """equality test"""
    first = medium.Medium("ID", "FILENAME", json.dumps(TAGS1))
    second = medium.Medium("ID", "FILENAME", json.dumps(TAGS1))
    third = medium.Medium("ID", "FILENAME", json.dumps(["TAG1", "TAG111"]))
    assert first == second
    assert first != third
    assert second != third
Пример #2
0
def test_mime_type(tmpdir):
    """brauchen dafür vielleicht testdatei"""
    path = lambda x: os.path.join(tmpdir, x)
    open(path("empty.txt"), "w").close()
    with open(path("text.txt"), "w") as file:
        file.write("Demo Text")
    with open(path("pixel.png"), "wb") as file:
        file.write(b'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR')
    media1 = medium.Medium(None, path("text.txt"), '["Text"]')
    media2 = medium.Medium(None, path("empty.txt"), '["Nothing"]')
    media3 = medium.Medium(None, path("pixel.png"), '["image"]')
    assert media1.mime_type() == "text/plain"
    assert media2.mime_type() == "inode/x-empty"
    assert media3.mime_type() == "image/png"
Пример #3
0
def test_create_media_id(tmpdir):
    """also needs a file"""
    path = lambda *x: os.path.join(tmpdir, *x)
    with open(path("pixel.png"), "wb") as file:
        file.write(b'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR')
    media = medium.Medium(None, path("pixel.png"), [])
    assert media.medium_id == \
    "02a3e298f1533f62558c58e4c70edcab9af5a50d62d925fd5390942020fb0fb8"
Пример #4
0
def test_rename(tmpdir):
    """change file name. can also change path"""
    path = lambda *x: os.path.join(tmpdir, *x)
    open(path("empty.txt"), "w").close()
    media = medium.Medium(None, path("empty.txt"), '["Nothing"]')
    media.rename(path("lol.txt"))
    assert os.listdir(tmpdir) == ["lol.txt"]
    os.mkdir(path("test"))
    media.rename(path("test", "lol.txt"))
    assert os.listdir(path("test")) == ["lol.txt"]
Пример #5
0
"""Testing the database function"""
#pylint: disable=w0621

import copy
import json

import pytest

from mediamanager import database
from mediamanager import medium

DEMO = medium.Medium("ID", "FILENAME", json.dumps(["TAG1", "TAG2"]))
DEMO2 = medium.Medium("ID2", "FILENAME2", json.dumps(["TAG1", "TAG2"]))

@pytest.fixture(scope="function")
def data_base():
    """mock the database"""
    my_db = database.Database(":memory:")
    yield my_db
    my_db.database.close()

def test_empty(data_base):
    """Empty database should return empty"""
    result = data_base.database_cursor.execute(
        "select * from collection").fetchall()
    assert result == []
    assert data_base.get_ids() == []

def test_put(data_base):
    """selecting all IDs if only one ID"""
    data_base.put(DEMO)
Пример #6
0
def demo2():
    """second demo"""
    return medium.Medium(ID2, FILENAME2, json.dumps(TAGS2))
Пример #7
0
def demo():
    """first demo"""
    return medium.Medium(ID1, FILENAME1, json.dumps(TAGS1))