File: test_inmemory_server.py

package info (click to toggle)
python-moto 5.1.18-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 116,520 kB
  • sloc: python: 636,725; javascript: 181; makefile: 39; sh: 3
file content (62 lines) | stat: -rw-r--r-- 1,908 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import json

from moto import server


def test_set_transition():
    backend = server.create_backend_app("moto_api")
    test_client = backend.test_client()

    post_body = {
        "model_name": "server::test1",
        "transition": {"progression": "waiter", "wait_times": 3},
    }
    resp = test_client.post(
        "http://localhost:5000/moto-api/state-manager/set-transition",
        data=json.dumps(post_body),
    )
    assert resp.status_code == 201

    resp = test_client.get(
        "http://localhost:5000/moto-api/state-manager/get-transition?model_name=server::test1"
    )
    assert resp.status_code == 200
    assert json.loads(resp.data) == {"progression": "waiter", "wait_times": 3}


def test_unset_transition():
    backend = server.create_backend_app("moto_api")
    test_client = backend.test_client()

    post_body = {
        "model_name": "server::test2",
        "transition": {"progression": "waiter", "wait_times": 3},
    }
    test_client.post(
        "http://localhost:5000/moto-api/state-manager/set-transition",
        data=json.dumps(post_body),
    )

    post_body = {"model_name": "server::test2"}
    resp = test_client.post(
        "http://localhost:5000/moto-api/state-manager/unset-transition",
        data=json.dumps(post_body),
    )
    assert resp.status_code == 201

    resp = test_client.get(
        "http://localhost:5000/moto-api/state-manager/get-transition?model_name=server::test2"
    )
    assert resp.status_code == 200
    assert json.loads(resp.data) == {"progression": "immediate"}


def test_get_default_transition():
    backend = server.create_backend_app("moto_api")
    test_client = backend.test_client()

    resp = test_client.get(
        "http://localhost:5000/moto-api/state-manager/get-transition?model_name=unknown"
    )
    assert resp.status_code == 200
    assert json.loads(resp.data) == {"progression": "immediate"}