test_archive_data.py 1.8 KB
Newer Older
Paul Arthur's avatar
Paul Arthur committed
1
from collab_admin_kit import archive_data
Rob Carleski's avatar
Rob Carleski committed
2
import datetime
3
4
5
6
7
8
9
10
11
import os
import yaml

data_dir = os.path.join(os.path.dirname(__file__) + '/data/')
config = data_dir + 'test_cak_config.yml'
args = {
    'lookback': 2,
    'drive_folder': 'Google Domain Reports'
}
Paul Arthur's avatar
Paul Arthur committed
12
archiver = archive_data.Archiver(
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
    args,
    yaml.load(open(config), Loader=yaml.BaseLoader)
)

def test_log_users():
    archiver.log_users()
    logfile = archiver.data_dir + '/user.csv'
    assert os.path.exists(logfile)
    assert os.stat(logfile).st_size > 0


def test_log_groups():
    archiver.log_groups()
    logfile = archiver.data_dir + '/group.csv'
    assert os.path.exists(logfile)
    assert os.stat(logfile).st_size > 0


def test_log_resources():
    archiver.log_resources()
    logfile = archiver.data_dir + '/resource.csv'
    assert os.path.exists(logfile)
    assert os.stat(logfile).st_size > 0


def test_log_oauth():
    archiver.log_oauth()
    logfile = archiver.data_dir + '/oauth.csv'
    assert os.path.exists(logfile)
    assert os.stat(logfile).st_size > 0


def test_log_logins():
    archiver.log_logins()
Rob Carleski's avatar
Rob Carleski committed
47
48
    hour = datetime.datetime.now().hour - archiver.lookback
    logfile = archiver.data_dir + '/logins-{}.csv'.format(hour)
49
50
51
52
53
54
55
56
57
    assert os.path.exists(logfile)
    assert os.stat(logfile).st_size > 0


def test_log_logins_custom_lookback():
    args = {
        'lookback': 10,
        'drive_folder': 'Google Domain Reports'
    }
Paul Arthur's avatar
Paul Arthur committed
58
    archiver = archive_data.Archiver(
59
60
61
62
63
64
65
66
67
68
69
70
71
        args,
        yaml.load(open(config), Loader=yaml.BaseLoader)
    )
    archiver.lookback = 10
    archiver.log_logins()
    archiver.cleanup()


def test_log_new_log_dir():
    args = {
        'lookback': 2,
        'drive_folder': 'New Log Folder'
    }
Paul Arthur's avatar
Paul Arthur committed
72
    archive_data.Archiver(
73
74
75
        args,
        yaml.load(open(config), Loader=yaml.BaseLoader)
    )