コード例 #1
0
 def setUp(self):
     super().setUp()
     db.create_all()
     self.AUTH_TYPE = current_app.config["AUTH_TYPE"]
     self.data = {
         "username": "******",
         "email": "*****@*****.**",
         "password": "******",
     }
     user = UserModel(data=self.data)
     user.save()
     db.session.commit()
     self.data.pop("email")
コード例 #2
0
ファイル: test_log_in.py プロジェクト: baobabsoluciones/corn
 def setUp(self):
     super().setUp()
     db.create_all()
     self.AUTH_TYPE = current_app.config["AUTH_TYPE"]
     self.data = {
         "username": "******",
         "email": "*****@*****.**",
         "password": "******",
     }
     user = UserModel(data=self.data)
     user.save()
     db.session.commit()
     # we take out the email, we do not need it to log in
     self.data.pop("email")
     self.idx = UserModel.query.filter_by(username="******").first().id
コード例 #3
0
 def test_successful_log_in_service(self):
     self.data = {"username": "******", "password": "******"}
     super().test_successful_log_in()
     self.assertEqual(
         UserModel.get_one_user_by_username(self.data["username"]).id,
         self.response.json["id"],
     )
コード例 #4
0
 def test_move_case2(self):
     user = UserModel.get_one_user(self.user)
     case3 = CaseModel.get_one_object(user=user, idx=3)
     case11 = CaseModel.get_one_object(user=user, idx=11)
     case9 = CaseModel.get_one_object(user=user, idx=9)
     case10 = CaseModel.get_one_object(user=user, idx=10)
     case3.move_to(case11)
     case9.move_to(case3)
     self.assertEqual(case10.path, "1/7/11/3/9/")
コード例 #5
0
 def test_successful_log_in_admin(self):
     self.data = {
         "username": "******",
         "password": "******"
     }
     super().test_successful_log_in()
     self.assertEqual(
         UserModel.get_one_user_by_username(self.data["username"]).id,
         self.response.json["id"],
     )
コード例 #6
0
    def setUp(self):
        super().setUp()

        def load_file(_file):
            with open(_file) as f:
                temp = json.load(f)
            return temp

        self.payload = load_file(INSTANCE_PATH)
        self.payloads = [load_file(f) for f in INSTANCES_LIST]
        parents = [None, 1, 1, 3, 3, 3, 1, 7, 7, 9, 7]
        user = UserModel.get_one_user(self.user)
        data = {**self.payload, **dict(user_id=user.id)}
        for parent in parents:
            if parent is not None:
                parent = CaseModel.get_one_object(user=user, idx=parent)
            node = CaseModel(data=data, parent=parent)
            node.save()
コード例 #7
0
ファイル: test_roles.py プロジェクト: baobabsoluciones/corn
 def test_delete_all_user_roles(self):
     # create some user:
     data = {
         "username": "******",
         "email": "testemail" + "@test.org",
         "password": "******",
     }
     user_response = self.create_user(data)
     user_id = user_response.json["id"]
     # give it all roles:
     for role in ROLES_MAP:
         self.assign_role(user_id, role)
     all_roles = UserModel.get_one_user(user_id).roles
     diff = set(r for r in all_roles).symmetric_difference(ROLES_MAP.keys())
     self.assertEqual(len(all_roles), len(ROLES_MAP))
     self.assertEqual(len(diff), 0)
     UserRoleModel.del_one_user(user_id)
     all_roles = UserRoleModel.get_all_objects(user_id=user_id).all()
     self.assertEqual(all_roles, [])
コード例 #8
0
ファイル: test_sign_up.py プロジェクト: baobabsoluciones/corn
    def test_successful_signup(self):
        payload = self.data

        response = self.client.post(
            SIGNUP_URL,
            data=json.dumps(payload),
            follow_redirects=True,
            headers={"Content-Type": "application/json"},
        )

        self.assertEqual(201, response.status_code)
        self.assertEqual(str, type(response.json["token"]))
        self.assertEqual(int, type(response.json["id"]))
        self.assertEqual(
            PLANNER_ROLE,
            UserRoleModel.query.filter_by(
                user_id=response.json["id"]).first().role_id,
        )
        self.assertNotEqual(
            None, UserModel.get_one_user_by_email(self.data["email"]))
コード例 #9
0
    def setUp(self):
        super().setUp()

        payload = self.load_file(INSTANCE_PATH)
        instance_id = self.create_new_row(INSTANCE_URL,
                                          InstanceModel,
                                          payload=payload)

        payload = self.load_file(EXECUTION_PATH, "instance_id", instance_id)
        execution_id = self.create_new_row(EXECUTION_URL_NORUN,
                                           ExecutionModel,
                                           payload=payload)

        self.url = CASE_INSTANCE_URL
        self.model = CaseModel
        self.items_to_check = ["name", "description", "schema"]
        self.response_items = [
            "name",
            "description",
            "data",
            "data_hash",
            "schema",
            "solution",
            "solution_hash",
            "user_id",
        ]

        self.payload = {
            "name": "testcase",
            "description": "test case for unit tests",
            "instance_id": instance_id,
            "execution_id": execution_id,
            "schema": "solve_model_dag",
        }
        self.user_object = UserModel.get_one_user(self.user)
        self.instance = InstanceModel.get_one_object(user=self.user_object,
                                                     idx=instance_id)
        self.execution = ExecutionModel.get_one_object(user=self.user_object,
                                                       idx=execution_id)
コード例 #10
0
    def test_copy_case(self):
        new_case = self.create_new_row(self.url + str(self.case_id) + "/copy/",
                                       self.model, {},
                                       check_payload=False)
        user = UserModel.get_one_user(self.user)

        original_case = CaseModel.get_one_object(user=user, idx=self.case_id)
        new_case = CaseModel.get_one_object(user=user, idx=new_case["id"])

        for key in self.copied_items:
            self.assertEqual(getattr(original_case, key),
                             getattr(new_case, key))

        for key in self.modified_items:
            self.assertNotEqual(getattr(original_case, key),
                                getattr(new_case, key))
            self.assertEqual("Copy_" + getattr(original_case, key),
                             getattr(new_case, key))

        for key in self.new_items:
            self.assertNotEqual(getattr(original_case, key),
                                getattr(new_case, key))
コード例 #11
0
 def test_depth(self):
     user = UserModel.get_one_user(self.user)
     case10 = CaseModel.get_one_object(user=user, idx=10)
     self.assertEqual(case10.depth, 4)
コード例 #12
0
 def test_descendants(self):
     user = UserModel.get_one_user(self.user)
     case7 = CaseModel.get_one_object(user=user, idx=7)
     self.assertEqual(len(case7.descendants), 4)
コード例 #13
0
 def test_delete_case(self):
     user = UserModel.get_one_user(self.user)
     case7 = CaseModel.get_one_object(user=user, idx=7)
     case7.delete()
     case11 = CaseModel.get_one_object(user=user, idx=11)
     self.assertIsNone(case11)
コード例 #14
0
 def test_move_case(self):
     user = UserModel.get_one_user(self.user)
     case6 = CaseModel.get_one_object(user=user, idx=6)
     case11 = CaseModel.get_one_object(user=user, idx=11)
     case6.move_to(case11)
     self.assertEqual(case6.path, "1/7/11/")
コード例 #15
0
 def test_new_case(self):
     user = UserModel.get_one_user(self.user)
     case = CaseModel.get_one_object(user=user, idx=6)
     self.assertEqual(case.path, "1/3/")
     case = CaseModel.get_one_object(user=user, idx=11)
     self.assertEqual(case.path, "1/7/")
コード例 #16
0
 def test_successful_log_in(self):
     super().test_successful_log_in()
     self.assertEqual(
         UserModel.get_one_user_by_username(self.data["username"]).id,
         self.response.json["id"],
     )