def test_create_relationship(self): with self.app.app_context(): from src.database.db import get_db, init_app, distroy_db from src.models.survey_model import Survey, SurveyVersion distroy_db(self.app) init_app(self.app) current_transaction = get_db().transaction with current_transaction: test_Survey_1 = Survey( slug="test_survey_1", language="en" ) test_SurveyVersion_1 = SurveyVersion( title="Test Survey 1" ) test_Survey_1.save() test_SurveyVersion_1.save() rel = test_Survey_1.versions.connect(test_SurveyVersion_1) assert len(test_SurveyVersion_1.survey.all()) == 1 pytest.test_Survey_SurveyVersion_rel_1 = rel pytest.test_Survey_1 = test_Survey_1 pytest.test_SurveyVersion_1 = test_SurveyVersion_1
def test_parent_wrapper_assignment(self): with self.app.app_context(): from src.database.db import get_db from src.models.survey_model import Survey current_transaction = get_db().transaction test_survey_version_wrapper_1 = pytest.test_survey_version_wrapper_1 with current_transaction: test_survey_1 = Survey( language="en", slug="test_survey_1" ) test_survey_1.save() test_survey_1.versions.connect( test_survey_version_wrapper_1.version ) test_survey_wrapper_1 = SurveyWrapper(test_survey_1) pytest.test_survey_wrapper_1 = test_survey_wrapper_1 test_survey_version_wrapper_1.parent_wrapper = test_survey_wrapper_1 assert test_survey_version_wrapper_1.parent_wrapper == test_survey_wrapper_1
def test_setup_for_datetime_filtering_methods(self): with self.app.app_context(): from src.database.db import get_db from src.models.survey_model import Survey, SurveyVersion current_transaction = get_db().transaction with current_transaction: test_survey_3 = Survey(slug="test_survey_3", language="en") test_survey_3.save() test_survey_version_4 = SurveyVersion( title="Test Survey Version 4", ) test_survey_version_5 = SurveyVersion( title="Test Survey Version 5") test_survey_version_6 = SurveyVersion( title="Test Survey Version 6") test_survey_version_7 = SurveyVersion( title="Test Survey Version 7") test_survey_version_8 = SurveyVersion( title="Test Survey Version 8") test_survey_version_4.save() test_survey_version_5.save() test_survey_version_6.save() test_survey_version_7.save() test_survey_version_8.save() test_survey_3.versions.connect(test_survey_version_4, { 'addedOn': datetime(2019, 4, 21, 14, 2, 40, 12, pytz.utc) }) test_survey_3.versions.connect(test_survey_version_5, { 'addedOn': datetime(2019, 4, 22, 14, 2, 40, 12, pytz.utc) }) test_survey_3.versions.connect(test_survey_version_6, { 'addedOn': datetime(2019, 4, 22, 18, 2, 40, 12, pytz.utc) }) test_survey_3.versions.connect(test_survey_version_7, { 'addedOn': datetime(2019, 4, 23, 18, 2, 40, 12, pytz.utc) }) test_survey_3.versions.connect(test_survey_version_8, { 'addedOn': datetime(2019, 5, 22, 18, 2, 40, 12, pytz.utc) }) test_survey_wrapper_3 = SurveyWrapper(test_survey_3) test_survey_wrapper_3.currentVersion = test_survey_version_8 pytest.test_survey_3 = test_survey_3 pytest.test_survey_version_4 = test_survey_version_4 pytest.test_survey_version_5 = test_survey_version_5 pytest.test_survey_version_6 = test_survey_version_6 pytest.test_survey_version_7 = test_survey_version_7 pytest.test_survey_version_8 = test_survey_version_8 pytest.test_survey_wrapper_3 = test_survey_wrapper_3
def test_create_relationship(self): with self.app.app_context(): from src.database.db import init_db, get_db, distroy_db from src.models.survey_model import Survey distroy_db(self.app) init_db(self.app) current_transaction = get_db().transaction with current_transaction: test_survey_1 = Survey( language="en", slug = "test_survey_1" ) test_survey_1.save() test_survey_2 = Survey( language="fr", slug = "test_survey_2" ) test_survey_2.save() rel = test_survey_1.related_surveys.connect( test_survey_2, { 'reason': 'language', 'description': "These surveys are related" } ) pytest.test_survey_1 = test_survey_1 pytest.test_survey_2 = test_survey_2 pytest.test_survey_survey_rel_1 = rel
def test_one_cardinality_for_SurveyVersion(self): with self.app.app_context(): from src.database.db import get_db from src.models.survey_model import SurveyVersion, Survey from neomodel.exceptions import AttemptedCardinalityViolation current_transaction = get_db().transaction with pytest.raises(AttemptedCardinalityViolation): with current_transaction: test_Survey_2 = Survey( slug='test_survey_2', language='en' ) test_Survey_2.save() test_SurveyVersion_1 = pytest.test_SurveyVersion_1 test_SurveyVersion_1.survey.connect(test_Survey_2)
def test_survey_setter(self): with self.app.app_context(): from src.database.db import get_db from src.models.survey_model import Survey current_transaction = get_db().transaction with current_transaction: test_survey_2 = Survey(slug="test_survey_2", language="en") test_survey_2.save() test_survey_wrapper_1 = pytest.test_survey_wrapper_1 # type: SurveyWrapper test_survey_wrapper_1.survey = test_survey_2 assert test_survey_wrapper_1._survey == test_survey_2
def test_set_up(self): with self.app.app_context(): from src.database.db import get_db, init_db, distroy_db from src.models.survey_model import Survey distroy_db(self.app) init_db(self.app) current_transaction = get_db().transaction with current_transaction: test_survey_1 = Survey(slug="test_survey_1", language="en") test_survey_1.save() pytest.test_survey_1 = test_survey_1 # type: Survey
def test_create_node(self): with self.app.app_context(): from src.database.db import get_db, distroy_db, init_db distroy_db(self.app) init_db(self.app) from src.models.survey_model import Survey transaction_factory = get_db() current_transaction = transaction_factory.transaction with current_transaction: from src.models.survey_model import Survey test_survey_1 = Survey( slug="test_survey_1", language="en" ) test_survey_1.save() pytest.test_survey_1 = test_survey_1
def test_language_options_constraint(self): with self.app.app_context(): from src.database.db import get_db from src.models.survey_model import Survey from neomodel.exception import DeflateError current_transaction = get_db().transaction with pytest.raises(DeflateError): with current_transaction: test_survey_3 = Survey( slug="test_survey_3", language="Japanese" ) test_survey_3.save() with current_transaction: test_survey_3.language = "en" test_survey_3.save() test_survey_3.language = "fr" test_survey_3.save()
def test_schema_dump(self): with self.app.app_context(): from src.database.db import get_db, init_db, distroy_db from src.models.survey_model import Survey from src.utils.marshmallow.survey_schema import SurveySchema distroy_db(self.app) init_db(self.app) current_transaction = get_db().transaction with current_transaction: test_survey_1 = Survey( slug="test_survey_1", language="en", ) test_survey_1.save() test_output_1 = SurveySchema().dump(test_survey_1) pytest.test_survey_1 = test_survey_1 pytest.test_output_1_data = test_output_1.data assert bool(test_output_1.errors) is False
def test_reason_field_required_constraint(self): with self.app.app_context(): from src.database.db import get_db from src.models.survey_model import Survey from neomodel.exceptions import RequiredProperty current_transaction = get_db().transaction with current_transaction: test_survey_1 = pytest.test_survey_1 test_survey_3 = Survey( language = "en", slug = "test_survey_3" ) test_survey_3.save() with pytest.raises(RequiredProperty): test_survey_1.related_surveys.connect(test_survey_3) test_survey_1.related_surveys.connect( test_survey_3, { 'reason': 'similar' } )
def test_slug_required_constrain(self): with self.app.app_context(): from src.database.db import get_db from src.models.survey_model import Survey from neomodel.exceptions import RequiredProperty current_transaction = get_db().transaction with pytest.raises(RequiredProperty): with current_transaction: test_survey_5 = Survey( language="en" ) test_survey_5.save() with current_transaction: test_survey_5.slug = "test_survey_5" test_survey_5.save()
def test_language_required_constraint(self): with self.app.app_context(): from src.database.db import get_db from neomodel.exceptions import RequiredProperty from src.models.survey_model import Survey transaction_factory = get_db() current_transaction = transaction_factory.transaction with pytest.raises(RequiredProperty): with current_transaction: test_survey_2 = Survey( slug="test_survey_2" ) test_survey_2.save() current_transaction = transaction_factory.transaction with current_transaction: test_survey_2.language = "en" test_survey_2.save()
def test_slug_unique_constrain(self): with self.app.app_context(): from src.database.db import get_db from src.models.survey_model import Survey from neomodel.exceptions import UniqueProperty current_transaction = get_db().transaction with pytest.raises(UniqueProperty): with current_transaction: test_survey_6 = Survey( slug="test_survey_5", language="en" ) test_survey_6.save() current_transaction = get_db().transaction with current_transaction: test_survey_6.slug = "test_survey_6" test_survey_6.save()