コード例 #1
0
def test_get_missing_chart(client, chart):
    from superset.key_value.models import KeyValueEntry

    key = 1234
    uuid_key = "e2ea9d19-7988-4862-aa69-c3a1a7628cb9"
    entry = KeyValueEntry(
        id=int(key),
        uuid=UUID("e2ea9d19-7988-4862-aa69-c3a1a7628cb9"),
        resource="explore_permalink",
        value=pickle.dumps(
            {
                "chartId": key,
                "datasetId": chart.datasource.id,
                "formData": {
                    "slice_id": key,
                    "datasource": f"{chart.datasource.id}__{chart.datasource.type}",
                },
            }
        ),
    )
    db.session.add(entry)
    db.session.commit()
    login(client, "admin")
    resp = client.get(f"api/v1/explore/permalink/{uuid_key}")
    assert resp.status_code == 404
    db.session.delete(entry)
    db.session.commit()
コード例 #2
0
ファイル: api_tests.py プロジェクト: EBoisseauSierra/superset
def test_get_missing_chart(test_client, login_as_admin, chart,
                           permalink_salt: str) -> None:
    from superset.key_value.models import KeyValueEntry

    chart_id = 1234
    entry = KeyValueEntry(
        resource=KeyValueResource.EXPLORE_PERMALINK,
        value=pickle.dumps({
            "chartId": chart_id,
            "datasourceId": chart.datasource.id,
            "datasourceType": DatasourceType.TABLE,
            "formData": {
                "slice_id": chart_id,
                "datasource":
                f"{chart.datasource.id}__{chart.datasource.type}",
            },
        }),
    )
    db.session.add(entry)
    db.session.commit()
    key = encode_permalink_key(entry.id, permalink_salt)
    resp = test_client.get(f"api/v1/explore/permalink/{key}")
    assert resp.status_code == 404
    db.session.delete(entry)
    db.session.commit()
コード例 #3
0
def key_value_entry(app_context: AppContext):
    from superset.key_value.models import KeyValueEntry

    return KeyValueEntry(
        id=int(ID_KEY),
        uuid=UUID(UUID_KEY),
        value=json.dumps({"foo": "bar"}),
    )
コード例 #4
0
ファイル: create.py プロジェクト: EBoisseauSierra/superset
 def create(self) -> Key:
     entry = KeyValueEntry(
         resource=self.resource.value,
         value=pickle.dumps(self.value),
         created_on=datetime.now(),
         created_by_fk=get_user_id(),
         expires_on=self.expires_on,
     )
     if self.key is not None:
         try:
             if isinstance(self.key, UUID):
                 entry.uuid = self.key
             else:
                 entry.id = self.key
         except ValueError as ex:
             raise KeyValueCreateFailedError() from ex
     db.session.add(entry)
     db.session.commit()
     return Key(id=entry.id, uuid=entry.uuid)
コード例 #5
0
 def create(self) -> str:
     entry = KeyValueEntry(
         resource=self.resource,
         value=pickle.dumps(self.value),
         created_on=datetime.now(),
         created_by_fk=None if self.actor is None or self.actor.is_anonymous
         else self.actor.id,
         expires_on=self.expires_on,
     )
     if self.key is not None:
         try:
             if self.key_type == "uuid":
                 entry.uuid = UUID(self.key)
             else:
                 entry.id = int(self.key)
         except ValueError as ex:
             raise KeyValueCreateFailedError() from ex
     db.session.add(entry)
     db.session.commit()
     return extract_key(entry, self.key_type)
コード例 #6
0
def key_value_entry() -> KeyValueEntry:
    from superset.key_value.models import KeyValueEntry

    entry = KeyValueEntry(
        id=int(ID_KEY),
        uuid=UUID(UUID_KEY),
        resource=RESOURCE,
        value=pickle.dumps(VALUE),
    )
    db.session.add(entry)
    db.session.commit()
    return entry
コード例 #7
0
def key_value_entry() -> Generator[KeyValueEntry, None, None]:
    from superset.key_value.models import KeyValueEntry

    entry = KeyValueEntry(
        id=int(ID_KEY),
        uuid=UUID(UUID_KEY),
        resource=RESOURCE,
        value=pickle.dumps(VALUE),
    )
    db.session.add(entry)
    db.session.commit()
    yield entry
    db.session.delete(entry)
    db.session.commit()
コード例 #8
0
def test_get_expired_entry(app_context: AppContext) -> None:
    from superset.key_value.commands.get import GetKeyValueCommand
    from superset.key_value.models import KeyValueEntry

    entry = KeyValueEntry(
        id=678,
        uuid=uuid.uuid4(),
        resource=RESOURCE,
        value=pickle.dumps(VALUE),
        expires_on=datetime.now() - timedelta(days=1),
    )
    db.session.add(entry)
    db.session.commit()
    value = GetKeyValueCommand(resource=RESOURCE, key=ID_KEY).run()
    assert value is None
    db.session.delete(entry)
    db.session.commit()
コード例 #9
0
def test_get_future_expiring_entry(app_context: AppContext) -> None:
    from superset.key_value.commands.get import GetKeyValueCommand
    from superset.key_value.models import KeyValueEntry

    id_ = 789
    entry = KeyValueEntry(
        id=id_,
        uuid=uuid.uuid4(),
        resource=RESOURCE,
        value=pickle.dumps(VALUE),
        expires_on=datetime.now() + timedelta(days=1),
    )
    db.session.add(entry)
    db.session.commit()
    value = GetKeyValueCommand(resource=RESOURCE, key=id_).run()
    assert value == VALUE
    db.session.delete(entry)
    db.session.commit()