Mercurial > kallithea
comparison kallithea/tests/functional/test_admin.py @ 8687:5e46f73f0d1c
model: always import the whole db module - drop "from" imports
author | Mads Kiilerich <mads@kiilerich.com> |
---|---|
date | Mon, 12 Oct 2020 11:12:37 +0200 |
parents | b095e2fbba44 |
children |
comparison
equal
deleted
inserted
replaced
8686:b095e2fbba44 | 8687:5e46f73f0d1c |
---|---|
1 import csv | 1 import csv |
2 import datetime | 2 import datetime |
3 import os | 3 import os |
4 from os.path import dirname | 4 from os.path import dirname |
5 | 5 |
6 from kallithea.model import meta | 6 from kallithea.model import db, meta |
7 from kallithea.model.db import UserLog | |
8 from kallithea.tests import base | 7 from kallithea.tests import base |
9 | 8 |
10 | 9 |
11 FIXTURES = os.path.join(dirname(dirname(os.path.abspath(__file__))), 'fixtures') | 10 FIXTURES = os.path.join(dirname(dirname(os.path.abspath(__file__))), 'fixtures') |
12 | 11 |
13 | 12 |
14 class TestAdminController(base.TestController): | 13 class TestAdminController(base.TestController): |
15 | 14 |
16 @classmethod | 15 @classmethod |
17 def setup_class(cls): | 16 def setup_class(cls): |
18 UserLog.query().delete() | 17 db.UserLog.query().delete() |
19 meta.Session().commit() | 18 meta.Session().commit() |
20 | 19 |
21 def strptime(val): | 20 def strptime(val): |
22 fmt = '%Y-%m-%d %H:%M:%S' | 21 fmt = '%Y-%m-%d %H:%M:%S' |
23 if '.' not in val: | 22 if '.' not in val: |
30 frag += (6 - len(frag)) * '0' # add 0s | 29 frag += (6 - len(frag)) * '0' # add 0s |
31 return date.replace(microsecond=int(frag)) | 30 return date.replace(microsecond=int(frag)) |
32 | 31 |
33 with open(os.path.join(FIXTURES, 'journal_dump.csv')) as f: | 32 with open(os.path.join(FIXTURES, 'journal_dump.csv')) as f: |
34 for row in csv.DictReader(f): | 33 for row in csv.DictReader(f): |
35 ul = UserLog() | 34 ul = db.UserLog() |
36 for k, v in row.items(): | 35 for k, v in row.items(): |
37 if k == 'action_date': | 36 if k == 'action_date': |
38 v = strptime(v) | 37 v = strptime(v) |
39 if k in ['user_id', 'repository_id']: | 38 if k in ['user_id', 'repository_id']: |
40 # nullable due to FK problems | 39 # nullable due to FK problems |
43 meta.Session().add(ul) | 42 meta.Session().add(ul) |
44 meta.Session().commit() | 43 meta.Session().commit() |
45 | 44 |
46 @classmethod | 45 @classmethod |
47 def teardown_class(cls): | 46 def teardown_class(cls): |
48 UserLog.query().delete() | 47 db.UserLog.query().delete() |
49 meta.Session().commit() | 48 meta.Session().commit() |
50 | 49 |
51 def test_index(self): | 50 def test_index(self): |
52 self.log_user() | 51 self.log_user() |
53 response = self.app.get(base.url(controller='admin/admin', action='index')) | 52 response = self.app.get(base.url(controller='admin/admin', action='index')) |