Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Ricky Cook committed Jul 13, 2016
1 parent 070cb66 commit e1b66ee
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
1 change: 1 addition & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ def project(db, randid):
name=randid,
repo='test',
utility=False,
public=True
), delete=True) as model:
yield model

Expand Down
23 changes: 7 additions & 16 deletions tests/db/api/test_user_api_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,22 @@ def test_add_to_empty(self):
assert [role.name for role in user.roles] == ['admin']

@pytest.mark.usefixtures('db')
def test_add_multiple(self):
def test_add_multiple(self, role):
""" Add multiple roles to a user with no roles """
role = Role(name='test')
DB.session.add(role)
DB.session.commit()

user = User()
rest_set_roles(user, ['admin', 'test'])
assert [role.name for role in user.roles] == ['admin', 'test']
rest_set_roles(user, ['admin', role.name])
assert [role.name for role in user.roles] == ['admin', role.name]

@pytest.mark.usefixtures('db')
def test_set_with_existing(self):
def test_set_with_existing(self, role, user):
""" Set roles on a user with an existing role """
role = Role(name='test')
user = SECURITY_STATE.datastore.create_user(
email='[email protected]',
)
user.roles.append(Role.query.get(1))
user.roles.append(role)
DB.session.add(role)
DB.session.add(user)
DB.session.commit()

rest_set_roles(user, ['test'])
assert [role.name for role in user.roles] == ['test']
rest_set_roles(user, [role.name])
assert [role.name for role in user.roles] == [role.name]

@pytest.mark.usefixtures('db')
def test_add_fake(self):
Expand Down Expand Up @@ -110,7 +102,6 @@ def test_no_admin_update_roles(self, client, user, role):
'roles': [role.name],
})

print(response.data)
assert response.status_code == 401

DB.session.refresh(user)
Expand Down
12 changes: 11 additions & 1 deletion tests/db/models/test_project_db.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from dockci.models.job import Job
from dockci.models.job import Job, JobStageTmp
from dockci.models.project import Project
from dockci.server import DB

Expand All @@ -12,6 +12,7 @@ def create_project(slug, **kwargs):
slug=slug,
utility=False,
repo='test',
public=True,
)
final_kwargs.update(kwargs)
return Project(**final_kwargs)
Expand All @@ -30,6 +31,14 @@ def create_job(**kwargs):
class TestProjectsSummary(object):
""" Ensure ``Project.get_status_summary`` behaves as expected """

def setup_method(self, _):
JobStageTmp.query.delete()
Job.query.delete()
def teardown_method(self, _):
JobStageTmp.query.delete()
Job.query.delete()


@pytest.mark.parametrize('models,p_filters,exp_s,exp_f,exp_b,exp_i', [
(
(
Expand Down Expand Up @@ -111,6 +120,7 @@ def test_it(self, db, models, p_filters, exp_s, exp_f, exp_b, exp_i):
for job in jobs:
job.project = project
DB.session.add(job)
print('job')

DB.session.commit()

Expand Down

0 comments on commit e1b66ee

Please sign in to comment.