def test_create_relationship(self):
        with self.app.app_context():
            from src.database.db import get_db, init_db, distroy_db
            from src.models.question_model import PreQuestion
            from src.models.survey_model import SurveyVersion

            distroy_db(self.app)
            init_db(self.app)

            current_transaction = get_db().transaction

            with current_transaction:
                test_prequestion_1 = PreQuestion(
                    slug="test_prequestion_1",
                    text="This is and example PreQuestion 1",
                    language="en")
                test_prequestion_1.save()
                test_surveyversion_1 = SurveyVersion(
                    title="Test SurveyVersion 1")
                test_surveyversion_1.save()

                rel = test_surveyversion_1.prequestions.connect(
                    test_prequestion_1)

                pytest.test_prequestion_1 = test_prequestion_1
                pytest.test_surveyversion_1 = test_surveyversion_1
                pytest.test_surveyversion_prequestion_rel_1 = rel
Ejemplo n.º 2
0
    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
Ejemplo n.º 3
0
    def test_dump_with_previousVersions(self):
        with self.app.app_context():
            from src.database.db import get_db
            from src.models.survey_model import SurveyVersion

            current_transaction = get_db().transaction

            with current_transaction:
                test_survey_wrapper_1 = pytest.test_survey_wrapper_1

                test_survey_version_2 = SurveyVersion(
                    title = 'Test Survey Version 2'
                )

                test_survey_version_2.save()

                test_survey_version_3 = SurveyVersion(
                    title = 'Test Survey Version 3'
                )

                test_survey_version_3.save()

                test_survey_wrapper_1.currentVersion = test_survey_version_2
                test_survey_wrapper_1.currentVersion = test_survey_version_3

                pytest.test_survey_version_3 = test_survey_version_3
                pytest.test_survey_version_2 = test_survey_version_2

                pytest.test_output_4 = test_survey_wrapper_1.currentVersion.dump()
Ejemplo n.º 4
0
    def test_create_node(self):
        with self.app.app_context():
            from src.database.db import get_db, distroy_db, init_db
            from src.models.survey_model import SurveyVersion
            distroy_db(self.app)
            init_db(self.app)
            current_transaction = get_db().transaction

            with current_transaction:
                test_survey_version_1 = SurveyVersion(
                    title="Survey Version 1"
                )
                test_survey_version_1.save()
            
            pytest.test_survey_version_1 = test_survey_version_1
Ejemplo n.º 5
0
    def test_one_or_mode_cardinality_for_Survey(self):
        with self.app.app_context():
            from src.database.db import get_db
            from src.models.survey_model import SurveyVersion

            current_transaction = get_db().transaction

            with current_transaction:
                test_Survey_1 = pytest.test_Survey_1
                test_SurveyVersion_2 = SurveyVersion(
                    title="Test SurveyVersion 2"
                )
                test_SurveyVersion_2.save()
                test_Survey_1.versions.connect(test_SurveyVersion_2)
            
            assert len(test_Survey_1.versions.all()) == 2
Ejemplo n.º 6
0
    def test_currentVersion_setter_with_node(self):
        with self.app.app_context():
            from src.database.db import get_db
            from src.models.survey_model import SurveyVersion

            current_transaction = get_db().transaction

            with current_transaction:
                test_survey_version_2 = SurveyVersion(
                    title="Test Survey Version 2", )
                test_survey_version_2.save()

                test_survey_wrapper_1 = pytest.test_survey_wrapper_1
                test_survey_wrapper_1.currentVersion = test_survey_version_2

                assert test_survey_version_2.currentVersion is True
Ejemplo n.º 7
0
    def test_currentVersion_getter_with_version(self):
        with self.app.app_context():
            from src.database.db import get_db
            from src.models.survey_model import SurveyVersion

            current_transaction = get_db().transaction

            with current_transaction:
                test_survey_version_1 = SurveyVersion(
                    title="Test Survey Version 1", currentVersion=True)
                test_survey_version_1.save()

                test_survey_wrapper_1 = pytest.test_survey_wrapper_1
                test_survey = test_survey_wrapper_1.survey

                test_survey.versions.connect(test_survey_version_1)
                assert test_survey_version_1 in test_survey.versions
                assert test_survey_wrapper_1.currentVersionNode == test_survey_version_1
Ejemplo n.º 8
0
    def test_currentVersion_setter_node_from_another_parent(self):
        with self.app.app_context():
            from src.database.db import get_db
            from src.models.survey_model import SurveyVersion
            from src.utils.exceptions.wrapper_exceptions import VersionDoesNotBelongToNode
            current_transaction = get_db().transaction

            with current_transaction:
                test_survey_version_4 = SurveyVersion(
                    title="Test Survey Version 4")

                test_survey_version_4.save()
                test_survey_1 = pytest.test_survey_1

                test_survey_1.versions.connect(test_survey_version_4)

                test_survey_wrapper_1 = pytest.test_survey_wrapper_1
                with pytest.raises(VersionDoesNotBelongToNode):
                    test_survey_wrapper_1.currentVersion = test_survey_version_4
Ejemplo n.º 9
0
    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 SurveyVersion
            from src.utils.marshmallow.surveyversion_schema import SurveyVersionSchema

            distroy_db(self.app)
            init_db(self.app)

            current_transaction = get_db().transaction

            with current_transaction:
                test_surveyversion_1 = SurveyVersion(
                    title="Test SurveyVersion 1", )
                test_surveyversion_1.save()

            pytest.test_surveyversion_1 = test_surveyversion_1
            test_output_1 = SurveyVersionSchema().dump(test_surveyversion_1)
            pytest.test_output_1_data = test_output_1.data
            pytest.test_output_1_errors = test_output_1.errors

            assert bool(pytest.test_output_1_errors) == False
Ejemplo n.º 10
0
    def test_title_required_constraint(self):
        with self.app.app_context():
            from src.database.db import get_db
            from src.models.survey_model import SurveyVersion
            from neomodel.exceptions import RequiredProperty

            current_transaction = get_db().transaction
            with pytest.raises(RequiredProperty):
                with current_transaction:
                    test_survey_version_2 = SurveyVersion(
                    )
                    test_survey_version_2.save()

            with current_transaction:
                test_survey_version_2.title = "Survey Version 2"
                test_survey_version_2.save()
Ejemplo n.º 11
0
    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