Skip to content

Commit

Permalink
Merge pull request #7 from smaht-dac/tests
Browse files Browse the repository at this point in the history
Add More Tests
  • Loading branch information
willronchetti authored Jul 21, 2023
2 parents 6b911f4 + b554fcc commit 2d78d11
Show file tree
Hide file tree
Showing 40 changed files with 1,411 additions and 55 deletions.
24 changes: 19 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ jobs:
# The type of runner that the job will run on
runs-on: ubuntu-20.04

# Build matrix
strategy:
matrix:
test_type: [ 'UNIT', 'DOCKER' ]

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
Expand All @@ -31,6 +36,7 @@ jobs:
python-version: 3.9

- name: Install/Link Postgres
if: ${{ matrix.test_type == 'UNIT' }}
run: |
sudo apt-get install curl ca-certificates gnupg
curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
Expand All @@ -41,6 +47,7 @@ jobs:
sudo ln -s /usr/lib/postgresql/11/bin/initdb /usr/local/bin/initdb
- name: Install Deps
if: ${{ matrix.test_type == 'UNIT' }}
run: |
make build
Expand All @@ -51,23 +58,30 @@ jobs:
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1

- name: QA
- name: QA (UNIT)
if: ${{ matrix.test_type == 'UNIT' }}
env:
# S3_ENCRYPT_KEY: ${{ secrets.S3_ENCRYPT_KEY }}
# # The need for this old environment variable name will go away soon.
# TRAVIS_JOB_ID: sno-x-test-${{ github.run_number }}-
# This will be the new environment variable name.
TEST_JOB_ID: smaht-test-indexing-${{ github.run_number }}-${{ matrix.python_version }}-
run: |
make test
make remote-test
- name: Docker Build
if: ${{ matrix.test_type == 'DOCKER' }}
run: |
touch deploy/docker/local/docker_development.ini # cheap substitute for prepare-docker to make ignored file
docker build .
- name: Cleanup
if: ${{ always() }}
if: ${{ always() && matrix.test_type == 'UNIT' }}
env:
S3_ENCRYPT_KEY: ${{ secrets.S3_ENCRYPT_KEY }}
# The need for this old environment variable name will go away soon.
# TRAVIS_JOB_ID: sno-x-test-${{ github.run_number }}-
# This will be the new environment variable name.
TEST_JOB_ID: sno-test-indexing-${{ github.run_number }}-${{ matrix.python_version }}-
TEST_JOB_ID: smaht-test-indexing-${{ github.run_number }}-${{ matrix.python_version }}-
run: |
poetry run wipe-test-indices $TEST_JOB_ID search-fourfront-testing-opensearch-kqm7pliix4wgiu4druk2indorq.us-east-1.es.amazonaws.com:443
poetry run wipe-test-indices $TEST_JOB_ID search-opensearch-smaht-testing-ykavtw57jz4cx4f2gqewhu4b44.us-east-1.es.amazonaws.com:443
8 changes: 8 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ smaht-portal
Change Log
----------

0.0.5
=====

* Improve testing by porting relevant tests as needed
* Changes to accommodate working search/other tests
* Allow testing with ES in GA with smaht-development credentials
* Build Docker as part of GA

0.0.4
=====

Expand Down
5 changes: 2 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,8 @@ test-static:
poetry run python -m pytest -vv -m static
make lint

remote-test: # Actually, we don't normally use this. Instead the GA workflow sets up two parallel tests.
make remote-test-unit
make remote-test-npm
remote-test: # smaht-portal uses this make target for now as tests are not that burdensome
pytest -vv --aws-auth --durations=20 --es search-opensearch-smaht-testing-ykavtw57jz4cx4f2gqewhu4b44.us-east-1.es.amazonaws.com:443

remote-test-npm: # Note this only does the 'not indexing' tests
poetry run python -m pytest -xvv -r w --instafail --force-flaky --max-runs=2 --timeout=600 -m "not manual and not integratedx and not performance and not broken and not broken_remotely and not sloppy and not indexing and not static" --aws-auth --durations=20 --cov src/encoded --es search-cgap-unit-testing-opensearch-tcs45cjpwgdzoi7pafr6oewq6u.us-east-1.es.amazonaws.com:443
Expand Down
9 changes: 4 additions & 5 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "encoded"
version = "0.0.4"
version = "0.0.5"
description = "SMaHT Data Analysis Portal"
authors = ["4DN-DCIC Team <[email protected]>"]
license = "MIT"
Expand Down Expand Up @@ -42,7 +42,7 @@ certifi = ">=2021.5.30"
chardet = "3.0.4"
codeguru-profiler-agent = "^1.2.4"
colorama = "0.3.3"
dcicsnovault = "8.2.0.1b42"
dcicsnovault = "8.2.0.1b45"
dcicutils = "7.5.1.1b0"
encoded-core = "^0.0.2"
elasticsearch = "7.13.4"
Expand Down
2 changes: 1 addition & 1 deletion src/encoded/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ def include_snovault(config: Configurator) -> None:
config.include('snovault.resource_views')
config.include('snovault.settings')
config.include('snovault.server_defaults')
# Renderers is giving problems at the moment - Will 6/1/23
config.include('snovault.renderers')
config.include('snovault.ingestion.ingestion_listener')
# configure redis server in production.ini
if 'redis.server' in config.registry.settings:
config.include('snovault.redis')
Expand Down
7 changes: 7 additions & 0 deletions src/encoded/appdefs.py
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
import os


APP_VERSION_REGISTRY_KEY = 'snovault.app_version'


ENCODED_ROOT_DIR = os.path.dirname(__file__)
PROJECT_DIR = os.path.dirname(os.path.dirname(ENCODED_ROOT_DIR)) # two levels of hierarchy up
13 changes: 9 additions & 4 deletions src/encoded/project/loadxl.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@

class SMaHTProjectLoadxl(SnovaultProjectLoadxl):

def loadxl_order(self):
""" Defines any hard orderings that must happen when reindexing types """
return [
order = [
'AccessKey',
'User',
'Consortium',
Expand All @@ -29,4 +27,11 @@ def loadxl_order(self):
'FilterSet',
'HiglassViewConfig',
'IngestionSubmission'
]
]

def loadxl_order(self):
""" Defines any hard orderings that must happen when reindexing types """
return self.order


ITEM_INDEX_ORDER = SMaHTProjectLoadxl.order
2 changes: 1 addition & 1 deletion src/encoded/schemas/consortium.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"title": "Consortium",
"id": "/profiles/Consortium.json",
"id": "/profiles/consortium.json",
"$schema": "http://json-schema.org/draft-04/schema#",
"required": [
"name",
Expand Down
2 changes: 1 addition & 1 deletion src/encoded/schemas/submission_center.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"title": "SubmissionCenter",
"id": "/profiles/SubmissionCenter.json",
"id": "/profiles/submission_center.json",
"$schema": "http://json-schema.org/draft-04/schema#",
"required": [
"name",
Expand Down
2 changes: 1 addition & 1 deletion src/encoded/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def app_settings(request, wsgi_server_host_port, conn, DBSession): # noQA - We
return settings


INDEXER_NAMESPACE_FOR_TESTING = generate_indexer_namespace_for_testing('cgap')
INDEXER_NAMESPACE_FOR_TESTING = generate_indexer_namespace_for_testing('smaht')


@pytest.fixture(scope='session')
Expand Down
103 changes: 103 additions & 0 deletions src/encoded/tests/test_authentication.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import pytest
import unittest

from pyramid.interfaces import IAuthenticationPolicy
from pyramid.security import Authenticated, Everyone
from pyramid.testing import DummyRequest
from zope.interface.verify import verifyClass, verifyObject
from ..authentication import NamespacedAuthenticationPolicy


pytestmark = [pytest.mark.setone, pytest.mark.working]


class TestNamespacedAuthenticationPolicy(unittest.TestCase):
""" This is a modified version of TestRemoteUserAuthenticationPolicy
"""
def _getTargetClass(self):
return NamespacedAuthenticationPolicy

def _makeOne(self, namespace='user',
base='pyramid.authentication.RemoteUserAuthenticationPolicy',
*args, **kw):
return self._getTargetClass()(namespace, base, *args, **kw)

def test_class_implements_IAuthenticationPolicy(self):
klass = self._makeOne().__class__
verifyClass(IAuthenticationPolicy, klass)

def test_instance_implements_IAuthenticationPolicy(self):
verifyObject(IAuthenticationPolicy, self._makeOne())

def test_unauthenticated_userid_returns_None(self):
request = DummyRequest(environ={})
policy = self._makeOne()
self.assertEqual(policy.unauthenticated_userid(request), None)

def test_unauthenticated_userid(self):
request = DummyRequest(environ={'REMOTE_USER':'fred'})
policy = self._makeOne()
self.assertEqual(policy.unauthenticated_userid(request), 'user.fred')

def test_authenticated_userid_None(self):
request = DummyRequest(environ={})
policy = self._makeOne()
self.assertEqual(policy.authenticated_userid(request), None)

def test_authenticated_userid(self):
request = DummyRequest(environ={'REMOTE_USER':'fred'})
policy = self._makeOne()
self.assertEqual(policy.authenticated_userid(request), 'user.fred')

def test_effective_principals_None(self):
request = DummyRequest(environ={})
policy = self._makeOne()
self.assertEqual(policy.effective_principals(request), [Everyone])

def test_effective_principals(self):
request = DummyRequest(environ={'REMOTE_USER':'fred'})
policy = self._makeOne()
self.assertEqual(policy.effective_principals(request),
[Everyone, Authenticated, 'user.fred'])

def test_remember(self):
request = DummyRequest(environ={'REMOTE_USER':'fred'})
policy = self._makeOne()
result = policy.remember(request, 'fred')
self.assertEqual(result, [])

def test_forget(self):
request = DummyRequest(environ={'REMOTE_USER':'fred'})
policy = self._makeOne()
result = policy.forget(request)
self.assertEqual(result, [])

# From TestSessionAuthenticationPolicy

def test_session_remember(self):
request = DummyRequest()
policy = self._makeOne(
base='pyramid.authentication.SessionAuthenticationPolicy',
prefix='')
result = policy.remember(request, 'user.fred')
self.assertEqual(request.session.get('userid'), 'fred')
self.assertEqual(result, [])
self.assertEqual(policy.unauthenticated_userid(request), 'user.fred')

def test_session_forget(self):
request = DummyRequest(session={'userid':'fred'})
policy = self._makeOne(
base='pyramid.authentication.SessionAuthenticationPolicy',
prefix='')
result = policy.forget(request)
self.assertEqual(request.session.get('userid'), None)
self.assertEqual(result, [])

def test_session_forget_no_identity(self):
request = DummyRequest()
policy = self._makeOne(
base='pyramid.authentication.SessionAuthenticationPolicy',
prefix='')
result = policy.forget(request)
self.assertEqual(request.session.get('userid'), None)
self.assertEqual(result, [])
28 changes: 28 additions & 0 deletions src/encoded/tests/test_authorization.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import pytest


from .test_search import MockedRequest
from snovault.util import is_admin_request


pytestmark = [pytest.mark.working]


@pytest.mark.parametrize('mock_request, expected', [
[MockedRequest(), False],
[MockedRequest(principals_allowed=[
'group.admin'
]), True],
[MockedRequest(principals_allowed=[
'group.read-only-admin'
]), False], # read only admin is not admin technically
[MockedRequest(principals_allowed=[
'group.something-else'
]), False],
[MockedRequest(principals_allowed=[
'lots', 'of', 'other', 'perms', 'but', 'not', 'group', 'dot', 'admin'
]), False]
])
def test_authorization_is_admin_request(mock_request, expected):
""" Checks that the request tests correctly resolve. """
assert is_admin_request(mock_request) is expected
Loading

0 comments on commit 2d78d11

Please sign in to comment.