Exemplo n.º 1
0
def test_db_does_not_delete_user_data(config, db, tmpdir):
    # Add a file to the test_campaign folder
    with open(os.path.join(config['campaign_dir'], 'precious_file.txt'),
              'a') as my_file:
        my_file.write("Precious content")

    # Try creating another database overwriting this one
    config['overwrite'] = True
    with pytest.raises(Exception):
        DatabaseManager.new(**config)
Exemplo n.º 2
0
def test_have_same_structure():
    d1 = {'a': 1, 'b': 2}
    d2 = {'a': [], 'b': 3}
    d3 = {'a': 4, 'c': 5}
    assert DatabaseManager.have_same_structure(d1, d2) is True
    assert DatabaseManager.have_same_structure(d1, d3) is False

    d4 = {'a': {'c': 1}, 'b': 2}
    d5 = {'a': {'c': 3}, 'b': 4}
    d6 = {'a': {'c': 5, 'd': 6}, 'b': 7}
    assert DatabaseManager.have_same_structure(d1, d4) is False
    assert DatabaseManager.have_same_structure(d4, d5) is True
    assert DatabaseManager.have_same_structure(d4, d6) is False
Exemplo n.º 3
0
def test_db_loading(config, db, tmpdir):
    # Note that the db fixture initializes a db for us
    # Load the database file
    db = DatabaseManager.load(config['campaign_dir'])

    # Make sure campaign dir is correct
    assert db.campaign_dir == config['campaign_dir']

    # Check for a correctly loaded configuration
    del config['campaign_dir']
    assert db.get_config() == config
Exemplo n.º 4
0
def test_db_loading(config, db, tmpdir):
    campaign_path = config['campaign_dir']

    # Note that the db fixture initializes a db for us
    # Load the database file
    db = DatabaseManager.load(config['campaign_dir'])

    # Make sure campaign dir is correct
    assert db.campaign_dir == config['campaign_dir']

    # Check for a correctly loaded configuration
    del config['campaign_dir']
    assert db.get_config() == config

    # Modify the campaign database, removing an entry
    db.db.purge_table('config')

    # Wrong database format is currently detected
    with pytest.raises(Exception):
        DatabaseManager.load(campaign_path)
Exemplo n.º 5
0
def test_exception_throwing(config, db):
    with pytest.raises(ValueError):
        DatabaseManager.load('./non_absolute_path')
    with pytest.raises(ValueError):
        DatabaseManager.load('/abs/path/to/non/existing/file')
    with pytest.raises(ValueError):
        config['campaign_dir'] = './non_absolute_path'
        DatabaseManager.new(**config)
Exemplo n.º 6
0
def test_db_creation_from_scratch(tmpdir, config, ns_3):
    # This should be ok
    DatabaseManager.new(**config)
    # This should raise FileExistsError because directory already exists
    with pytest.raises(FileExistsError):
        DatabaseManager.new(**config)
    # This should execute no problem because we overwrite the database
    DatabaseManager.new(**config, overwrite=True)
Exemplo n.º 7
0
def db(config):
    """
    Provide a valid database, initialized with an example configuration.
    """
    db = DatabaseManager.new(**config)
    return db