예제 #1
0
    def test_flow_migrate(self):
        flow_def = {"nodes": [{"val": Decimal("1.23")}]}

        with patch("requests.post") as mock_post:
            mock_post.return_value = MockResponse(200, '{"name": "Migrated!"}')
            migrated = get_client().flow_migrate(flow_def, to_version="13.1.0")

            self.assertEqual({"name": "Migrated!"}, migrated)

        call = mock_post.call_args

        self.assertEqual(("http://localhost:8090/mr/flow/migrate", ), call[0])
        self.assertEqual(
            {
                "User-Agent": "Temba",
                "Content-Type": "application/json"
            }, call[1]["headers"])
        self.assertEqual({
            "flow": flow_def,
            "to_version": "13.1.0"
        }, json.loads(call[1]["data"]))
예제 #2
0
파일: tests.py 프로젝트: Ilhasoft/rapidpro
    def test_flow_inspect(self):
        flow_def = {"nodes": [{"val": Decimal("1.23")}]}

        with patch("requests.post") as mock_post:
            mock_post.return_value = MockResponse(200, '{"dependencies":[]}')
            info = get_client().flow_inspect(self.org.id, flow_def)

            self.assertEqual({"dependencies": []}, info)

        call = mock_post.call_args

        self.assertEqual(("http://localhost:8090/mr/flow/inspect", ), call[0])
        self.assertEqual(
            {
                "User-Agent": "Temba",
                "Content-Type": "application/json"
            }, call[1]["headers"])
        self.assertEqual({
            "org_id": self.org.id,
            "flow": flow_def
        }, json.loads(call[1]["data"]))
예제 #3
0
파일: tests.py 프로젝트: Spamala1/rapidpro
    def test_contact_modify(self):
        with patch("requests.post") as mock_post:
            mock_post.return_value = MockResponse(
                200,
                """{
                    "1": {
                        "contact": {
                            "uuid": "6393abc0-283d-4c9b-a1b3-641a035c34bf",
                            "id": 1,
                            "name": "Frank",
                            "timezone": "America/Los_Angeles",
                            "created_on": "2018-07-06T12:30:00.123457Z"
                        },
                        "events": [
                            {
                                "type": "contact_groups_changed",
                                "created_on": "2018-07-06T12:30:03.123456789Z",
                                "groups_added": [
                                    {
                                        "uuid": "c153e265-f7c9-4539-9dbc-9b358714b638",
                                        "name": "Doctors"
                                    }
                                ]
                            }
                        ]
                    }
                }
                """,
            )

            response = get_client().contact_modify(
                1,
                1,
                [1],
                {
                    "type":
                    "groups",
                    "modification":
                    "add",
                    "groups": [{
                        "uuid": "c153e265-f7c9-4539-9dbc-9b358714b638",
                        "name": "Doctors"
                    }],
                },
            )
            self.assertEqual("6393abc0-283d-4c9b-a1b3-641a035c34bf",
                             response["1"]["contact"]["uuid"])
            mock_post.assert_called_once_with(
                "http://localhost:8090/mr/contact/modify",
                headers={"User-Agent": "Temba"},
                json={
                    "org_id": 1,
                    "user_id": 1,
                    "contact_ids": [1],
                    "modifiers": {
                        "type":
                        "groups",
                        "modification":
                        "add",
                        "groups": [{
                            "uuid": "c153e265-f7c9-4539-9dbc-9b358714b638",
                            "name": "Doctors"
                        }],
                    },
                },
            )
예제 #4
0
파일: tests.py 프로젝트: Spamala1/rapidpro
 def test_empty_expression(self):
     # empty is as empty does
     self.assertEqual("", get_client().expression_migrate(""))
예제 #5
0
파일: tests.py 프로젝트: Spamala1/rapidpro
    def test_version(self):
        with patch("requests.get") as mock_get:
            mock_get.return_value = MockResponse(200, '{"version": "5.3.4"}')
            version = get_client().version()

        self.assertEqual("5.3.4", version)
예제 #6
0
    def test_contact_modify(self):
        with patch("requests.post") as mock_post:
            mock_post.return_value = MockResponse(
                200,
                """{
                    "1": {
                        "contact": {
                            "uuid": "6393abc0-283d-4c9b-a1b3-641a035c34bf",
                            "id": 1,
                            "name": "Frank",
                            "timezone": "America/Los_Angeles",
                            "created_on": "2018-07-06T12:30:00.123457Z"
                        },
                        "events": [
                            {
                                "type": "contact_groups_changed",
                                "created_on": "2018-07-06T12:30:03.123456789Z",
                                "groups_added": [
                                    {
                                        "uuid": "c153e265-f7c9-4539-9dbc-9b358714b638",
                                        "name": "Doctors"
                                    }
                                ]
                            }
                        ]
                    }
                }
                """,
            )

            response = get_client().contact_modify(
                1,
                1,
                [1],
                [
                    modifiers.Name(name="Bob"),
                    modifiers.Language(language="fra"),
                    modifiers.Field(field=modifiers.FieldRef(key="age", name="Age"), value="43"),
                    modifiers.Status(status="blocked"),
                    modifiers.Groups(
                        groups=[modifiers.GroupRef(uuid="c153e265-f7c9-4539-9dbc-9b358714b638", name="Doctors")],
                        modification="add",
                    ),
                    modifiers.URNs(urns=["+tel+1234567890"], modification="append"),
                ],
            )
            self.assertEqual("6393abc0-283d-4c9b-a1b3-641a035c34bf", response["1"]["contact"]["uuid"])
            mock_post.assert_called_once_with(
                "http://localhost:8090/mr/contact/modify",
                headers={"User-Agent": "Temba"},
                json={
                    "org_id": 1,
                    "user_id": 1,
                    "contact_ids": [1],
                    "modifiers": [
                        {"type": "name", "name": "Bob"},
                        {"type": "language", "language": "fra"},
                        {"type": "field", "field": {"key": "age", "name": "Age"}, "value": "43"},
                        {"type": "status", "status": "blocked"},
                        {
                            "type": "groups",
                            "groups": [{"uuid": "c153e265-f7c9-4539-9dbc-9b358714b638", "name": "Doctors"}],
                            "modification": "add",
                        },
                        {"type": "urns", "urns": ["+tel+1234567890"], "modification": "append"},
                    ],
                },
            )
예제 #7
0
    def test_contact_create(self, mock_post):
        mock_post.return_value = MockResponse(
            200, '{"contact": {"id": 1234, "name": "", "language": ""}}')

        # try with empty contact spec
        response = get_client().contact_create(
            self.org.id, self.admin.id,
            ContactSpec(name="", language="", urns=[], fields={}, groups=[]))

        self.assertEqual({
            "id": 1234,
            "name": "",
            "language": ""
        }, response["contact"])
        mock_post.assert_called_once_with(
            "http://localhost:8090/mr/contact/create",
            headers={"User-Agent": "Temba"},
            json={
                "org_id": self.org.id,
                "user_id": self.admin.id,
                "contact": {
                    "name": "",
                    "language": "",
                    "urns": [],
                    "fields": {},
                    "groups": []
                },
            },
        )

        mock_post.reset_mock()
        mock_post.return_value = MockResponse(
            200, '{"contact": {"id": 1234, "name": "Bob", "language": "eng"}}')

        response = get_client().contact_create(
            self.org.id,
            self.admin.id,
            ContactSpec(
                name="Bob",
                language="eng",
                urns=["tel:+123456789"],
                fields={
                    "age": "39",
                    "gender": "M"
                },
                groups=["d5b1770f-0fb6-423b-86a0-b4d51096b99a"],
            ),
        )

        self.assertEqual({
            "id": 1234,
            "name": "Bob",
            "language": "eng"
        }, response["contact"])
        mock_post.assert_called_once_with(
            "http://localhost:8090/mr/contact/create",
            headers={"User-Agent": "Temba"},
            json={
                "org_id": self.org.id,
                "user_id": self.admin.id,
                "contact": {
                    "name": "Bob",
                    "language": "eng",
                    "urns": ["tel:+123456789"],
                    "fields": {
                        "age": "39",
                        "gender": "M"
                    },
                    "groups": ["d5b1770f-0fb6-423b-86a0-b4d51096b99a"],
                },
            },
        )