updated tests, formatting

This commit is contained in:
Alok Saldanha
2021-04-02 11:52:49 -04:00
parent 5c488d8d5e
commit d2d22cecaa
4 changed files with 29 additions and 6 deletions
+1 -1
View File
@@ -22,7 +22,7 @@ jobs:
pip install black pip install black
- name: Run black - name: Run black
run: | run: |
black -l 79 . --check black . --check
# This job is copied over from `deploy.yaml` # This job is copied over from `deploy.yaml`
run-tests: run-tests:
runs-on: ubuntu-18.04 runs-on: ubuntu-18.04
+5 -3
View File
@@ -29,8 +29,10 @@ class S3ItemSource(ItemSource):
): ):
self._name = name self._name = name
self.s3 = s3fs.S3FileSystem() self.s3 = s3fs.S3FileSystem()
if bucket.startswith('s3://'): if bucket.startswith("s3://"):
raise Exception(f"Bucket name should not include s3:// prefix, got {bucket}") raise Exception(
f"Bucket name should not include s3:// prefix, got {bucket}"
)
self.bucket = bucket self.bucket = bucket
self.h5ad_suffix = h5ad_suffix self.h5ad_suffix = h5ad_suffix
self.annotation_dir_suffix = annotation_dir_suffix self.annotation_dir_suffix = annotation_dir_suffix
@@ -69,7 +71,7 @@ class S3ItemSource(ItemSource):
raise Exception(f"S3 url '{url}' does not exist.") raise Exception(f"S3 url '{url}' does not exist.")
s3key_map = dict( s3key_map = dict(
(filepath[len(self.bucket) :].lstrip('/'), "s3://" + filepath) (filepath[len(self.bucket) :].lstrip("/"), "s3://" + filepath)
for filepath in sorted(self.s3.ls(url)) for filepath in sorted(self.s3.ls(url))
) )
+3 -1
View File
@@ -5,7 +5,9 @@ from cellxgene_gateway.items.file.fileitem_source import FileItemSource
class TestFileItemSource(unittest.TestCase): class TestFileItemSource(unittest.TestCase):
def test_make_fileitem_from_path_GIVEN_annotation_file_THEN_name_lacks_csv(self): def test_make_fileitem_from_path_GIVEN_annotation_file_THEN_name_lacks_csv(
self,
):
source = FileItemSource(tempfile.gettempdir(), "local") source = FileItemSource(tempfile.gettempdir(), "local")
item = source.make_fileitem_from_path( item = source.make_fileitem_from_path(
"customanno.csv", "someh5ad_annotations", True "customanno.csv", "someh5ad_annotations", True
+20 -1
View File
@@ -2,6 +2,7 @@ import unittest
from flask import Flask from flask import Flask
from cellxgene_gateway import flask_util
from cellxgene_gateway.cache_entry import CacheEntry, CacheEntryStatus from cellxgene_gateway.cache_entry import CacheEntry, CacheEntryStatus
from cellxgene_gateway.cache_key import CacheKey from cellxgene_gateway.cache_key import CacheKey
from cellxgene_gateway.gateway import app from cellxgene_gateway.gateway import app
@@ -27,13 +28,31 @@ class TestRenderEntry(unittest.TestCase):
self.assertEqual(entry.status, CacheEntryStatus.loading) self.assertEqual(entry.status, CacheEntryStatus.loading)
def test_GIVEN_absolute_static_url_THEN_include_path(self): def test_GIVEN_absolute_static_url_THEN_include_path(self):
flask_util.include_source_in_url = False
actual = CacheEntry.for_key(key, 8000).rewrite_text_content(
"src:url(/static/assets/"
)
expected = "src:url(/view/czi/pbmc3k.h5ad/static/assets/"
self.assertEqual(actual, expected)
def test_GIVEN_absolute_src_THEN_include_path(self):
flask_util.include_source_in_url = False
actual = CacheEntry.for_key(key, 8000).rewrite_text_content(
'<link rel="shortcut icon" href="/static/assets/favicon.ico">'
)
expected = '<link rel="shortcut icon" href="/view/czi/pbmc3k.h5ad/static/assets/favicon.ico">'
self.assertEqual(actual, expected)
def test_GIVEN_absolute_static_url_include_source_THEN_include_path(self):
flask_util.include_source_in_url = True
actual = CacheEntry.for_key(key, 8000).rewrite_text_content( actual = CacheEntry.for_key(key, 8000).rewrite_text_content(
"src:url(/static/assets/" "src:url(/static/assets/"
) )
expected = "src:url(/source/local/view/czi/pbmc3k.h5ad/static/assets/" expected = "src:url(/source/local/view/czi/pbmc3k.h5ad/static/assets/"
self.assertEqual(actual, expected) self.assertEqual(actual, expected)
def test_GIVEN_absolute_src_THEN_include_path(self): def test_GIVEN_absolute_src_include_source_THEN_include_path(self):
flask_util.include_source_in_url = True
actual = CacheEntry.for_key(key, 8000).rewrite_text_content( actual = CacheEntry.for_key(key, 8000).rewrite_text_content(
'<link rel="shortcut icon" href="/static/assets/favicon.ico">' '<link rel="shortcut icon" href="/static/assets/favicon.ico">'
) )