Skip to content

Commit

Permalink
PR comment resolves
Browse files Browse the repository at this point in the history
  • Loading branch information
realVinayak committed Nov 8, 2023
1 parent 2ab4aee commit a16a613
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 30 deletions.
3 changes: 2 additions & 1 deletion specifyweb/specify/api_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@
from django.db.models import Max
from django.test import TestCase, Client

from specifyweb.businessrules.exceptions import BusinessRuleException
from specifyweb.permissions.models import UserPolicy
from specifyweb.specify import api, models
from specifyweb.specify.views import fix_record_data

def get_table(name: str):
return getattr(models, name.capitalize())

class MainSetupTearDown:
def setUp(self):
Expand Down
6 changes: 1 addition & 5 deletions specifyweb/specify/test_trees.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
from specifyweb.specify import models
from specifyweb.specify.api_tests import ApiTests
from specifyweb.specify.api_tests import ApiTests, get_table
from specifyweb.specify.tree_stats import get_tree_stats
from specifyweb.stored_queries.tests import SQLAlchemySetup


def get_table(name: str):
return getattr(models, name.capitalize())

class TestTreeSetup(ApiTests):
def setUp(self) -> None:
super().setUp()
Expand Down
7 changes: 4 additions & 3 deletions specifyweb/stored_queries/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,14 @@ class SQLAlchemySetup(ApiTests):
def setUpClass(cls):
# Django creates a new database for testing. SQLAlchemy needs to connect to the test database
super().setUpClass()
cls.test_sa_url = settings.SA_TEST_DB_URL
_engine = sqlalchemy.create_engine(cls.test_sa_url, pool_recycle=settings.SA_POOL_RECYCLE,
_engine = sqlalchemy.create_engine(settings.SA_TEST_DB_URL, pool_recycle=settings.SA_POOL_RECYCLE,
connect_args={'cursorclass': SSCursor})

cls.engine = _engine
Session = orm.sessionmaker(bind=_engine)

cls.test_session_context = models.make_session_context(Session)

@event.listens_for(_engine, 'before_cursor_execute', retval=True)
# Listen to low-level cursor execution events. Just before query is executed by SQLAlchemy, run it instead
# by Django, and then return a wrapped sql statement which will return the same result set.
Expand All @@ -81,7 +82,7 @@ def run_django_query(conn, cursor, statement, parameters, context, executemany):
final_query = str(unioned.compile(compile_kwargs={"literal_binds": True, }, dialect=mysql.dialect()))
return final_query, ()

cls.test_session_context = models.make_session_context(Session)


def setUp(self):
super().setUp()
Expand Down
3 changes: 2 additions & 1 deletion specifyweb/workbench/upload/tests/base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from specifyweb.specify.test_trees import get_table, TestTreeSetup
from specifyweb.specify.api_tests import get_table
from specifyweb.specify.test_trees import TestTreeSetup
from . import example_plan


Expand Down
16 changes: 6 additions & 10 deletions specifyweb/workbench/upload/tests/test_bugs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,16 @@
import io
import json
import csv
from pprint import pprint
from unittest import skip, expectedFailure
from datetime import datetime
from decimal import Decimal

from ..uploadable import Exclude
from ..upload_result import Uploaded, UploadResult, Matched, FailedBusinessRule, NullRecord, ReportInfo, TreeInfo
from ..upload_table import UploadTable, ScopedUploadTable, _to_many_filters_and_excludes, BoundUploadTable
from ..treerecord import TreeRecord, TreeDefItemWithParseResults

from unittest import expectedFailure

from ..upload_result import Uploaded, Matched, NullRecord

from ..upload import do_upload_csv, validate_row
from ..upload_plan_schema import parse_plan

from .base import UploadTestsBase
from specifyweb.specify.test_trees import get_table
from specifyweb.specify.api_tests import get_table

class BugTests(UploadTestsBase):

Expand Down
9 changes: 4 additions & 5 deletions specifyweb/workbench/upload/tests/testdisambiguation.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
from typing import List, Optional

from ..uploadable import Disambiguation
from ..upload_result import Uploaded, UploadResult, Matched, MatchedMultiple, FailedBusinessRule, ReportInfo, TreeInfo
from ..upload_table import UploadTable, ScopedUploadTable, _to_many_filters_and_excludes, BoundUploadTable
from ..upload_result import Matched, MatchedMultiple
from ..upload_table import UploadTable
from ..tomany import ToManyRecord
from ..treerecord import TreeRecord, BoundTreeRecord, TreeDefItemWithParseResults
from ..upload import do_upload, do_upload_csv, validate_row, get_disambiguation_from_row
from ..upload import do_upload, validate_row, get_disambiguation_from_row
from ..upload_plan_schema import parse_column_options, parse_plan
from ..disambiguation import DisambiguationInfo

from .base import UploadTestsBase
from specifyweb.specify.test_trees import get_table
from specifyweb.specify.api_tests import get_table

class DisambiguationTests(UploadTestsBase):

Expand Down
2 changes: 1 addition & 1 deletion specifyweb/workbench/upload/tests/testmustmatch.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json
from jsonschema import validate # type: ignore
from typing import List, Dict, Any, NamedTuple, Union
from specifyweb.specify.test_trees import get_table
from specifyweb.specify.api_tests import get_table
from .base import UploadTestsBase
from ..upload_result import Uploaded, Matched, NoMatch, NullRecord, ParseFailures, FailedBusinessRule
from ..upload import do_upload, do_upload_csv
Expand Down
2 changes: 1 addition & 1 deletion specifyweb/workbench/upload/tests/testonetoone.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json
from jsonschema import validate # type: ignore
from typing import List, Dict, Any, NamedTuple, Union
from specifyweb.specify.test_trees import get_table
from specifyweb.specify.api_tests import get_table
from .base import UploadTestsBase
from ..upload_result import Uploaded, Matched, NullRecord, ParseFailures, FailedBusinessRule
from ..upload import do_upload, do_upload_csv
Expand Down
2 changes: 1 addition & 1 deletion specifyweb/workbench/upload/tests/testscoping.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from ..upload import do_upload

from specifyweb.specify import models
from specifyweb.specify.test_trees import get_table
from specifyweb.specify.api_tests import get_table
from .base import UploadTestsBase
from . import example_plan

Expand Down
3 changes: 1 addition & 2 deletions specifyweb/workbench/upload/tests/testunupload.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from specifyweb.specify import auditcodes
from specifyweb.specify.test_trees import get_table
from specifyweb.specify.api_tests import get_table
from .base import UploadTestsBase
from ..upload_result import Uploaded, ParseFailures, FailedBusinessRule
from ..upload import do_upload, do_upload_csv, unupload_record
from ..upload_table import UploadTable
from ..treerecord import TreeRecord
Expand Down

0 comments on commit a16a613

Please sign in to comment.