diff options
| author | Hunternif <hunternif@gmail.com> | 2021-08-06 23:05:50 +0100 |
|---|---|---|
| committer | Hunternif <hunternif@gmail.com> | 2021-08-06 23:05:50 +0100 |
| commit | cf26cc74a7a0252ff9329aff0c2f932f5da57a4f (patch) | |
| tree | 84f530c2fcc921fa56ba496f0059fa9707b4e948 /server | |
| parent | 8c63b7502b5cab79ba2adc25821b952b44308e00 (diff) | |
server: update ' to "
Diffstat (limited to 'server')
| -rw-r--r-- | server/szurubooru/api/metric_api.py | 46 | ||||
| -rw-r--r-- | server/szurubooru/func/metrics.py | 74 | ||||
| -rw-r--r-- | server/szurubooru/rest/context.py | 8 | ||||
| -rw-r--r-- | server/szurubooru/search/executor.py | 20 | ||||
| -rw-r--r-- | server/szurubooru/tests/func/test_metrics.py | 110 |
5 files changed, 129 insertions, 129 deletions
diff --git a/server/szurubooru/api/metric_api.py b/server/szurubooru/api/metric_api.py index 29aa7a2..2bba66f 100644 --- a/server/szurubooru/api/metric_api.py +++ b/server/szurubooru/api/metric_api.py @@ -25,27 +25,27 @@ def _serialize_post_metric( def _get_metric(params: Dict[str, str]) -> model.Metric: - return metrics.get_metric_by_tag_name(params['tag_name']) + return metrics.get_metric_by_tag_name(params["tag_name"]) -@rest.routes.get('/metrics/?') +@rest.routes.get("/metrics/?") def get_metrics( ctx: rest.Context, params: Dict[str, str] = {}) -> rest.Response: - auth.verify_privilege(ctx.user, 'metrics:list') + auth.verify_privilege(ctx.user, "metrics:list") all_metrics = metrics.get_all_metrics() return { - 'results': [_serialize_metric(ctx, metric) for metric in all_metrics] + "results": [_serialize_metric(ctx, metric) for metric in all_metrics] } -@rest.routes.post('/metrics/?') +@rest.routes.post("/metrics/?") def create_metric( ctx: rest.Context, params: Dict[str, str] = {}) -> rest.Response: - auth.verify_privilege(ctx.user, 'metrics:create') - tag_name = ctx.get_param_as_string('tag_name') + auth.verify_privilege(ctx.user, "metrics:create") + tag_name = ctx.get_param_as_string("tag_name") tag = tags.get_tag_by_name(tag_name) - min = ctx.get_param_as_float('min') - max = ctx.get_param_as_float('max') + min = ctx.get_param_as_float("min") + max = ctx.get_param_as_float("max") metric = metrics.create_metric(tag, min, max) ctx.session.flush() @@ -54,41 +54,41 @@ def create_metric( return _serialize_metric(ctx, metric) -@rest.routes.delete('/metric/(?P<tag_name>.+)') +@rest.routes.delete("/metric/(?P<tag_name>.+)") def delete_metric(ctx: rest.Context, params: Dict[str, str]) -> rest.Response: metric = _get_metric(params) versions.verify_version(metric, ctx) - auth.verify_privilege(ctx.user, 'metrics:delete') + auth.verify_privilege(ctx.user, "metrics:delete") # snapshots.delete(metric, ctx.user) metrics.delete_metric(metric) ctx.session.commit() return {} -@rest.routes.get('/post-metrics/?') +@rest.routes.get("/post-metrics/?") def get_post_metrics( ctx: rest.Context, params: Dict[str, str] = {}) -> rest.Response: - auth.verify_privilege(ctx.user, 'metrics:list') + auth.verify_privilege(ctx.user, "metrics:list") return _search_executor.execute_and_serialize( ctx, lambda post_metric: _serialize_post_metric(ctx, post_metric)) -@rest.routes.get('/post-metrics/median/(?P<tag_name>.+)') +@rest.routes.get("/post-metrics/median/(?P<tag_name>.+)") def get_post_metrics_median( ctx: rest.Context, params: Dict[str, str] = {}) -> rest.Response: - auth.verify_privilege(ctx.user, 'metrics:list') + auth.verify_privilege(ctx.user, "metrics:list") metric = _get_metric(params) - tag_name = params['tag_name'] + tag_name = params["tag_name"] query_text = ctx.get_param_as_string( - 'query', - default='%s:%f..%f' % (tag_name, metric.min, metric.max)) + "query", + default="%s:%f..%f" % (tag_name, metric.min, metric.max)) total_count = _search_executor.count(query_text) offset = ceil(total_count/2) - 1 _, results = _search_executor.execute(query_text, offset, 1) return { - 'query': query_text, - 'offset': offset, - 'limit': 1, - 'total': len(results), - 'results': list([_serialize_post_metric(ctx, pm) for pm in results]) + "query": query_text, + "offset": offset, + "limit": 1, + "total": len(results), + "results": list([_serialize_post_metric(ctx, pm) for pm in results]) } diff --git a/server/szurubooru/func/metrics.py b/server/szurubooru/func/metrics.py index 6f16a95..944c4d5 100644 --- a/server/szurubooru/func/metrics.py +++ b/server/szurubooru/func/metrics.py @@ -30,13 +30,13 @@ class MetricSerializer(serialization.BaseSerializer): def _serializers(self) -> Dict[str, Callable[[], Any]]: return { - 'version': lambda: self.metric.version, - 'min': lambda: self.metric.min, - 'max': lambda: self.metric.max, - 'exact_count': lambda: self.metric.post_metric_count, - 'range_count': lambda: self.metric.post_metric_range_count, - 'tag': lambda: tags.serialize_tag(self.metric.tag, [ - 'names', 'category', 'description', 'usages']) + "version": lambda: self.metric.version, + "min": lambda: self.metric.min, + "max": lambda: self.metric.max, + "exact_count": lambda: self.metric.post_metric_count, + "range_count": lambda: self.metric.post_metric_range_count, + "tag": lambda: tags.serialize_tag(self.metric.tag, [ + "names", "category", "description", "usages"]) } @@ -46,9 +46,9 @@ class PostMetricSerializer(serialization.BaseSerializer): def _serializers(self) -> Dict[str, Callable[[], Any]]: return { - 'tag_name': lambda: self.post_metric.metric.tag_name, - 'post_id': lambda: self.post_metric.post_id, - 'value': lambda: self.post_metric.value, + "tag_name": lambda: self.post_metric.metric.tag_name, + "post_id": lambda: self.post_metric.post_id, + "value": lambda: self.post_metric.value, } @@ -58,10 +58,10 @@ class PostMetricRangeSerializer(serialization.BaseSerializer): def _serializers(self) -> Dict[str, Callable[[], Any]]: return { - 'tag_name': lambda: self.post_metric_range.metric.tag_name, - 'post_id': lambda: self.post_metric_range.post_id, - 'low': lambda: self.post_metric_range.low, - 'high': lambda: self.post_metric_range.high, + "tag_name": lambda: self.post_metric_range.metric.tag_name, + "post_id": lambda: self.post_metric_range.post_id, + "low": lambda: self.post_metric_range.low, + "high": lambda: self.post_metric_range.high, } @@ -100,7 +100,7 @@ def try_get_metric_by_tag_name(tag_name: str) -> Optional[model.Metric]: def get_metric_by_tag_name(tag_name: str) -> model.Metric: metric = try_get_metric_by_tag_name(tag_name) if not metric: - raise MetricDoesNotExistsError('Metric %r not found.' % tag_name) + raise MetricDoesNotExistsError("Metric %r not found." % tag_name) return metric @@ -144,9 +144,9 @@ def create_metric( max: float) -> model.Metric: assert tag if tag.metric: - raise MetricAlreadyExistsError('Tag already has a metric.') + raise MetricAlreadyExistsError("Tag already has a metric.") if min >= max: - raise InvalidMetricError('Metric min(%r) >= max(%r)' % (min, max)) + raise InvalidMetricError("Metric min(%r) >= max(%r)" % (min, max)) metric = model.Metric(tag=tag, min=min, max=max) db.session.add(metric) return metric @@ -156,13 +156,13 @@ def update_or_create_metric( tag: model.Tag, metric_data: Any) -> Optional[model.Metric]: assert tag - for field in ('min', 'max'): + for field in ("min", "max"): if field not in metric_data: - raise InvalidMetricError('Metric is missing %r field.' % field) + raise InvalidMetricError("Metric is missing %r field." % field) - min, max = metric_data['min'], metric_data['max'] + min, max = metric_data["min"], metric_data["max"] if min >= max: - raise InvalidMetricError('Metric min(%r) >= max(%r)' % (min, max)) + raise InvalidMetricError("Metric min(%r) >= max(%r)" % (min, max)) if tag.metric: tag.metric.min = min tag.metric.max = max @@ -180,10 +180,10 @@ def update_or_create_post_metric( assert metric if metric.tag not in post.tags: raise PostMissingTagError( - 'Post doesn\'t have this tag.') + "Post doesn\"t have this tag.") if value < metric.min or value > metric.max: raise MetricValueOutOfRangeError( - 'Metric value %r out of range.' % value) + "Metric value %r out of range." % value) post_metric = try_get_post_metric(post, metric) if not post_metric: post_metric = model.PostMetric(post=post, metric=metric, value=value) @@ -201,15 +201,15 @@ def update_or_create_post_metrics(post: model.Post, metrics_data: Any) -> None: assert post post.metrics = [] for metric_data in metrics_data: - for field in ('tag_name', 'value'): + for field in ("tag_name", "value"): if field not in metric_data: - raise InvalidMetricError('Metric is missing %r field.' % field) - value = float(metric_data['value']) - tag_name = metric_data['tag_name'] + raise InvalidMetricError("Metric is missing %r field." % field) + value = float(metric_data["value"]) + tag_name = metric_data["tag_name"] tag = tags.get_tag_by_name(tag_name) if not tag.metric: raise MetricDoesNotExistsError( - 'Tag %r has no metric.' % tag_name) + "Tag %r has no metric." % tag_name) post_metric = update_or_create_post_metric(post, tag.metric, value) post.metrics.append(post_metric) @@ -223,14 +223,14 @@ def update_or_create_post_metric_range( assert metric if metric.tag not in post.tags: raise PostMissingTagError( - 'Post doesn\'t have this tag.') + "Post doesn\"t have this tag.") for value in (low, high): if value < metric.min or value > metric.max: raise MetricValueOutOfRangeError( - 'Metric value %r out of range.' % value) + "Metric value %r out of range." % value) if low >= high: raise InvalidMetricError( - 'Metric range low(%r) >= high(%r)' % (low, high)) + "Metric range low(%r) >= high(%r)" % (low, high)) post_metric_range = try_get_post_metric_range(post, metric) if not post_metric_range: post_metric_range = model.PostMetricRange( @@ -252,17 +252,17 @@ def update_or_create_post_metric_ranges( assert post post.metric_ranges = [] for metric_data in metric_ranges_data: - for field in ('tag_name', 'low', 'high'): + for field in ("tag_name", "low", "high"): if field not in metric_data: raise InvalidMetricError( - 'Metric range is missing %r field.' % field) - low = float(metric_data['low']) - high = float(metric_data['high']) - tag_name = metric_data['tag_name'] + "Metric range is missing %r field." % field) + low = float(metric_data["low"]) + high = float(metric_data["high"]) + tag_name = metric_data["tag_name"] tag = tags.get_tag_by_name(tag_name) if not tag.metric: raise MetricDoesNotExistsError( - 'Tag %r has no metric.' % tag_name) + "Tag %r has no metric." % tag_name) post_metric_range = update_or_create_post_metric_range( post, tag.metric, low, high) post.metric_ranges.append(post_metric_range) diff --git a/server/szurubooru/rest/context.py b/server/szurubooru/rest/context.py index cc5393c..a75ca60 100644 --- a/server/szurubooru/rest/context.py +++ b/server/szurubooru/rest/context.py @@ -189,21 +189,21 @@ class Context: if default is not MISSING: return cast(float, default) raise errors.MissingRequiredParameterError( - 'Required parameter %r is missing.' % name) + "Required parameter %r is missing." % name) value = self._params[name] try: value = float(value) if min is not None and value < min: raise errors.InvalidParameterError( - 'Parameter %r must be at least %r.' % (name, min)) + "Parameter %r must be at least %r." % (name, min)) if max is not None and value > max: raise errors.InvalidParameterError( - 'Parameter %r may not exceed %r.' % (name, max)) + "Parameter %r may not exceed %r." % (name, max)) return value except (ValueError, TypeError): pass raise errors.InvalidParameterError( - 'Parameter %r must be a float value.' % name) + "Parameter %r must be a float value." % name) def get_param_as_bool( self, name: str, default: Union[object, bool] = MISSING diff --git a/server/szurubooru/search/executor.py b/server/szurubooru/search/executor.py index 92a7e2f..5302b14 100644 --- a/server/szurubooru/search/executor.py +++ b/server/szurubooru/search/executor.py @@ -31,8 +31,8 @@ class Executor: Class for search parsing and execution. Handles plaintext parsing and delegates sqlalchemy filter decoration to SearchConfig instances. """ - AROUND_NEXT = 'up' - AROUND_PREV = 'down' + AROUND_NEXT = "up" + AROUND_PREV = "down" def __init__(self, search_config: BaseSearchConfig) -> None: self.config = search_config @@ -46,7 +46,7 @@ class Executor: filter_query = ( self.config .create_around_query() - .options(sa.orm.lazyload('*'))) + .options(sa.orm.lazyload("*"))) prev_filter_query = ( self._prepare_sorted_around_query( filter_query, search_query, entity_id, self.AROUND_PREV @@ -56,8 +56,8 @@ class Executor: filter_query, search_query, entity_id, self.AROUND_NEXT ).limit(1)) # random post - if 'sort:random' not in query_text: - query_text = 'sort:random ' + query_text + if "sort:random" not in query_text: + query_text = "sort:random " + query_text count, random_entities = self.execute(query_text, 0, 1) return ( prev_filter_query.one_or_none(), @@ -137,7 +137,7 @@ class Executor: search_query = self.parser.parse(query_text) self.config.on_search_query_parsed(search_query) count_query = self.config.create_count_query(True) - count_query = count_query.options(sa.orm.lazyload('*')) + count_query = count_query.options(sa.orm.lazyload("*")) count_query = self._prepare_db_query(count_query, search_query, False) count_statement = ( count_query @@ -220,12 +220,12 @@ class Executor: found_sort_column = False for sort_token in search_query.sort_tokens: - if sort_token.name == 'random': + if sort_token.name == "random": continue if sort_token.name not in self.config.sort_columns: raise errors.SearchError( - 'Unknown sort token: %r. ' - 'Available sort tokens: %r.' % ( + "Unknown sort token: %r. " + "Available sort tokens: %r." % ( sort_token.name, _format_dict_keys(self.config.sort_columns))) column, default_order = ( @@ -235,7 +235,7 @@ class Executor: # the order column may be joined, so we need to query its value: column_query = ( db.session.query(self.config.id_column, column) - .options(sa.orm.lazyload('*'))) + .options(sa.orm.lazyload("*"))) column_query = ( # empty search query because we already know entity id self._prepare_db_query(column_query, SearchQuery(), False) diff --git a/server/szurubooru/tests/func/test_metrics.py b/server/szurubooru/tests/func/test_metrics.py index 22f3e38..17b20ef 100644 --- a/server/szurubooru/tests/func/test_metrics.py +++ b/server/szurubooru/tests/func/test_metrics.py @@ -10,14 +10,14 @@ def test_serialize_metric(tag_factory): db.session.flush() result = metrics.serialize_metric(metric) assert result == { - 'version': 1, - 'min': 1, - 'max': 2, + "version": 1, + "min": 1, + "max": 2, } def test_serialize_post_metric(post_factory, tag_factory, metric_factory): - tag = tag_factory(names=['mytag']) + tag = tag_factory(names=["mytag"]) post = post_factory(id=456, tags=[tag]) metric = metric_factory(tag) post_metric = model.PostMetric(post=post, metric=metric, value=-12.3) @@ -25,14 +25,14 @@ def test_serialize_post_metric(post_factory, tag_factory, metric_factory): db.session.flush() result = metrics.serialize_post_metric(post_metric) assert result == { - 'tag_name': 'mytag', - 'post_id': 456, - 'value': -12.3, + "tag_name": "mytag", + "post_id": 456, + "value": -12.3, } def test_serialize_post_metric_range(post_factory, tag_factory, metric_factory): - tag = tag_factory(names=['mytag']) + tag = tag_factory(names=["mytag"]) post = post_factory(id=456, tags=[tag]) metric = metric_factory(tag) post_metric_range = model.PostMetricRange( @@ -41,20 +41,20 @@ def test_serialize_post_metric_range(post_factory, tag_factory, metric_factory): db.session.flush() result = metrics.serialize_post_metric_range(post_metric_range) assert result == { - 'tag_name': 'mytag', - 'post_id': 456, - 'low': -1.2, - 'high': 3.4 + "tag_name": "mytag", + "post_id": 456, + "low": -1.2, + "high": 3.4 } def test_try_get_metric_by_tag_name(tag_factory, metric_factory): - tag = tag_factory(names=['mytag']) + tag = tag_factory(names=["mytag"]) metric = metric_factory(tag) db.session.add_all([tag, metric]) db.session.flush() - assert metrics.try_get_metric_by_tag_name('unknown') is None - assert metrics.try_get_metric_by_tag_name('mytag') is metric + assert metrics.try_get_metric_by_tag_name("unknown") is None + assert metrics.try_get_metric_by_tag_name("mytag") is metric def test_try_get_post_metric( @@ -95,13 +95,13 @@ def test_get_all_metrics(metric_factory): def test_get_all_metric_tag_names(tag_factory, metric_factory): - tag1 = tag_factory(names=['abc', 'def']) - tag2 = tag_factory(names=['ghi']) + tag1 = tag_factory(names=["abc", "def"]) + tag2 = tag_factory(names=["ghi"]) metric1 = metric_factory(tag=tag1) metric2 = metric_factory(tag=tag2) db.session.add_all([metric1, metric2]) db.session.flush() - assert metrics.get_all_metric_tag_names() == ['abc', 'def', 'ghi'] + assert metrics.get_all_metric_tag_names() == ["abc", "def", "ghi"] def test_create_metric(tag_factory): @@ -131,7 +131,7 @@ def test_create_metric_with_invalid_params(tag_factory): def test_update_or_create_metric(tag_factory): tag = tag_factory() db.session.add(tag) - new_metric = metrics.update_or_create_metric(tag, {'min': 1, 'max': 2}) + new_metric = metrics.update_or_create_metric(tag, {"min": 1, "max": 2}) assert new_metric is not None db.session.flush() assert tag.metric is not None @@ -139,7 +139,7 @@ def test_update_or_create_metric(tag_factory): assert tag.metric.max == 2 assert tag.metric.version == 1 - new_metric = metrics.update_or_create_metric(tag, {'min': 3, 'max': 4}) + new_metric = metrics.update_or_create_metric(tag, {"min": 3, "max": 4}) assert new_metric is None db.session.flush() assert tag.metric.min == 3 @@ -147,8 +147,8 @@ def test_update_or_create_metric(tag_factory): assert tag.metric.version == 2 -@pytest.mark.parametrize('params', [ - {'min': 1}, {'max': 2}, {'min': 2, 'max': 1} +@pytest.mark.parametrize("params", [ + {"min": 1}, {"max": 2}, {"min": 2, "max": 1} ]) def test_update_or_create_metric_with_invalid_params(tag_factory, params): tag = tag_factory() @@ -206,19 +206,19 @@ def test_update_or_create_post_metric_update(post_factory, metric_factory): def test_update_or_create_post_metrics_missing_tag( post_factory, tag_factory, metric_factory): post = post_factory() - tag = tag_factory(names=['tag1']) + tag = tag_factory(names=["tag1"]) metric = metric_factory(tag) db.session.add(metric) db.session.flush() - data = [{'tag_name': 'tag1', 'value': 1.5}] + data = [{"tag_name": "tag1", "value": 1.5}] with pytest.raises(metrics.PostMissingTagError): metrics.update_or_create_post_metrics(post, data) -@pytest.mark.parametrize('params', [ +@pytest.mark.parametrize("params", [ [{}], - [{'tag_name': 'tag'}], - [{'value': 1.5}] + [{"tag_name": "tag"}], + [{"value": 1.5}] ]) def test_update_or_create_post_metrics_with_missing_fields( params, post_factory): @@ -229,19 +229,19 @@ def test_update_or_create_post_metrics_with_missing_fields( def test_update_or_create_post_metrics_with_invalid_tag( post_factory, tag_factory): - tag = tag_factory(names=['tag1']) + tag = tag_factory(names=["tag1"]) post = post_factory(tags=[tag]) db.session.add(tag) db.session.flush() - data = [{'tag_name': 'tag1', 'value': 2}] + data = [{"tag_name": "tag1", "value": 2}] with pytest.raises(metrics.MetricDoesNotExistsError): metrics.update_or_create_post_metrics(post, data) def test_update_or_create_post_metrics( post_factory, tag_factory, metric_factory): - tag1 = tag_factory(names=['tag1']) - tag2 = tag_factory(names=['tag2']) + tag1 = tag_factory(names=["tag1"]) + tag2 = tag_factory(names=["tag2"]) post = post_factory(tags=[tag1, tag2]) metric1 = metric_factory(tag1) metric2 = metric_factory(tag2) @@ -249,8 +249,8 @@ def test_update_or_create_post_metrics( db.session.flush() data = [ - {'tag_name': 'tag1', 'value': 1.2}, - {'tag_name': 'tag2', 'value': 3.4}, + {"tag_name": "tag1", "value": 1.2}, + {"tag_name": "tag2", "value": 3.4}, ] metrics.update_or_create_post_metrics(post, data) db.session.flush() @@ -262,8 +262,8 @@ def test_update_or_create_post_metrics( def test_update_or_create_post_metrics_with_trim( post_factory, tag_factory, metric_factory, post_metric_factory): - tag1 = tag_factory(names=['tag1']) - tag2 = tag_factory(names=['tag2']) + tag1 = tag_factory(names=["tag1"]) + tag2 = tag_factory(names=["tag2"]) post = post_factory(tags=[tag1, tag2]) metric1 = metric_factory(tag1) metric2 = metric_factory(tag2) @@ -275,7 +275,7 @@ def test_update_or_create_post_metrics_with_trim( assert post.metrics[0].value == 1.2 data = [ - {'tag_name': 'tag2', 'value': 3.4}, + {"tag_name": "tag2", "value": 3.4}, ] metrics.update_or_create_post_metrics(post, data) db.session.flush() @@ -295,7 +295,7 @@ def test_update_or_create_post_metric_range_without_tag( metrics.update_or_create_post_metric_range(post, metric, 2, 3) -@pytest.mark.parametrize('low, high', [ +@pytest.mark.parametrize("low, high", [ (-99, 1), (1, 99), ]) def test_update_or_create_post_metric_range_with_values_out_of_range( @@ -339,24 +339,24 @@ def test_update_or_create_post_metric_range_update( def test_update_or_create_post_metric_ranges_missing_tag( post_factory, tag_factory, metric_factory): post = post_factory() - tag = tag_factory(names=['tag1']) + tag = tag_factory(names=["tag1"]) metric = metric_factory(tag) db.session.add(metric) db.session.flush() - data = [{'tag_name': 'tag1', 'low': 2, 'high': 3}] + data = [{"tag_name": "tag1", "low": 2, "high": 3}] with pytest.raises(metrics.PostMissingTagError): metrics.update_or_create_post_metric_ranges(post, data) -@pytest.mark.parametrize('params', [ +@pytest.mark.parametrize("params", [ [{}], - [{'tag_name': 'tag'}], - [{'tag_name': 'tag', 'low': 2}], - [{'low': 2, 'high': 3}], + [{"tag_name": "tag"}], + [{"tag_name": "tag", "low": 2}], + [{"low": 2, "high": 3}], ]) def test_update_or_create_post_metric_ranges_with_missing_fields( params, post_factory, tag_factory): - tag = tag_factory(names=['tag']) + tag = tag_factory(names=["tag"]) post = post_factory(tags=[tag]) with pytest.raises(metrics.InvalidMetricError): metrics.update_or_create_post_metric_ranges(post, params) @@ -364,24 +364,24 @@ def test_update_or_create_post_metric_ranges_with_missing_fields( def test_update_or_create_post_metric_ranges_with_invalid_tag( post_factory, tag_factory): - tag = tag_factory(names=['tag1']) + tag = tag_factory(names=["tag1"]) post = post_factory(tags=[tag]) db.session.add(tag) db.session.flush() - data = [{'tag_name': 'tag1', 'low': 2, 'high': 3}] + data = [{"tag_name": "tag1", "low": 2, "high": 3}] with pytest.raises(metrics.MetricDoesNotExistsError): metrics.update_or_create_post_metric_ranges(post, data) def test_update_or_create_post_metric_ranges_with_invalid_values( post_factory, tag_factory, metric_factory): - tag = tag_factory(names=['tag1']) + tag = tag_factory(names=["tag1"]) post = post_factory(tags=[tag]) metric = metric_factory(tag=tag) db.session.add_all([metric, tag]) db.session.flush() data = [ - {'tag_name': 'tag1', 'low': 4, 'high': 2}, + {"tag_name": "tag1", "low": 4, "high": 2}, ] with pytest.raises(metrics.InvalidMetricError): metrics.update_or_create_post_metric_ranges(post, data) @@ -389,8 +389,8 @@ def test_update_or_create_post_metric_ranges_with_invalid_values( def test_update_or_create_post_metric_ranges( post_factory, tag_factory, metric_factory): - tag1 = tag_factory(names=['tag1']) - tag2 = tag_factory(names=['tag2']) + tag1 = tag_factory(names=["tag1"]) + tag2 = tag_factory(names=["tag2"]) post = post_factory(tags=[tag1, tag2]) metric1 = metric_factory(tag1) metric2 = metric_factory(tag2) @@ -398,8 +398,8 @@ def test_update_or_create_post_metric_ranges( db.session.flush() data = [ - {'tag_name': 'tag1', 'low': 2, 'high': 3}, - {'tag_name': 'tag2', 'low': 4, 'high': 5}, + {"tag_name": "tag1", "low": 2, "high": 3}, + {"tag_name": "tag2", "low": 4, "high": 5}, ] metrics.update_or_create_post_metric_ranges(post, data) db.session.flush() @@ -413,8 +413,8 @@ def test_update_or_create_post_metric_ranges( def test_update_or_create_post_metric_ranges_with_trim( post_factory, tag_factory, metric_factory, post_metric_range_factory): - tag1 = tag_factory(names=['tag1']) - tag2 = tag_factory(names=['tag2']) + tag1 = tag_factory(names=["tag1"]) + tag2 = tag_factory(names=["tag2"]) post = post_factory(tags=[tag1, tag2]) metric1 = metric_factory(tag1) metric2 = metric_factory(tag2) @@ -428,7 +428,7 @@ def test_update_or_create_post_metric_ranges_with_trim( assert post.metric_ranges[0].high == 2 data = [ - {'tag_name': 'tag2', 'low': 3, 'high': 4}, + {"tag_name": "tag2", "low": 3, "high": 4}, ] metrics.update_or_create_post_metric_ranges(post, data) db.session.flush() |