Exemple #1
0
    def test_box_open_with_config(self, client, current_user, session):
        """User can open a box when providing a config they own"""

        conf = config.ConfigFactory(user=current_user)
        session.add(conf)
        session.flush()

        res = client.post(
            "/boxes",
            json={
                "data": {
                    "type": "box",
                    "attributes": {
                        "sshKey": "i-am-a-lousy-public-key"
                    },
                    "relationships": {
                        "config": {
                            "data": {
                                "type": "config",
                                "id": str(conf.id)
                            }
                        }
                    },
                }
            },
        )

        assert res.status_code == 201
        assert len(values(res.get_json(), "data/id")) == 1
        assert_valid_schema(res.get_data(), "box.json")
        assert Box.query.filter_by(user=current_user).count() == 1
Exemple #2
0
    def test_box_open_unowned_config(self, client, current_user, session):
        """User can not open a box if they dont own the config"""

        conf = config.ConfigFactory()
        session.add(conf)
        session.flush()

        res = client.post(
            "/boxes",
            json={
                "data": {
                    "type": "box",
                    "attributes": {
                        "sshKey": "i-am-a-lousy-key"
                    },
                    "relationships": {
                        "config": {
                            "data": {
                                "type": "config",
                                "id": str(conf.id)
                            }
                        }
                    },
                }
            },
        )

        assert res.status_code == 403
        assert Box.query.filter_by(user=current_user).count() == 0
Exemple #3
0
    def test_account_delete_account_with_existing_boxes(
            self, client, current_user, session):
        """DELETE to /account url succeeds and associated boxes no longer exists"""
        conf1 = config.ConfigFactory(user=current_user, name="supersub")
        box1 = box.BoxFactory(config=conf1)

        session.add(box1)
        session.flush()

        assert Config.query.filter_by(id=conf1.id).first() is not None
        assert Box.query.filter_by(job_id=box1.job_id).first() is not None

        res = client.delete(
            "/account",
            json={
                "data": {
                    "type": "user",
                    "attributes": {
                        "password": "******"
                    }
                }
            },
        )

        assert res.status_code is 200
        assert User.query.filter_by(uuid=current_user.uuid).first() is None
        assert Config.query.filter_by(id=conf1.id).first() is None
        assert Box.query.filter_by(job_id=box1.job_id).first() is None
Exemple #4
0
    def test_box_filter_by_config_name(self, client, session, current_user):
        """Can filter a config using JSON-API compliant filters"""

        conf1 = config.ConfigFactory(user=current_user, name="sub-sandwich")
        conf2 = config.ConfigFactory(user=current_user, name="subscription")

        test_box1 = box.BoxFactory(config=conf1)
        test_box2 = box.BoxFactory(config=conf2)

        session.add(test_box1, test_box2)
        session.flush()

        res = client.get(f"/boxes?filter[config][name]=sub-sandwich")

        assert_valid_schema(res.get_json(), "boxes.json")
        assert str(test_box1.id) in values(res.get_json(), "data/*/id")
        assert str(test_box2.id) not in values(res.get_json(), "data/*/id")
Exemple #5
0
    def test_box_close_owned(self, client, session, current_user):
        """User can close a box"""

        conf = config.ConfigFactory(user=current_user)
        session.add(conf)
        session.flush()
        test_box = BoxCreationService(current_user, conf.id,
                                      "i-am-a-lousy-key").create()
        session.add(test_box)
        session.flush()

        res = client.delete("/boxes/" + str(test_box.id))
        assert res.status_code == 204