コード例 #1
0
    def test_address_get(self):
        active_address = Address.objects.create(value='active_address')
        inactive_address = Address.objects.create(
            value='inactive_address',
            is_active=False,
        )

        get_payload = {
            api_constants.SCHEMA: {
                api_constants.MODELS: {
                    Address.__name__: {
                        schema_constants.METHODS: {
                            method_constants.GET: {
                                address_get_constants.ADDRESS_ID:
                                active_address._id,
                            },
                        },
                    },
                },
            },
        }

        get_response = self.schema.respond(
            system=self.system,
            connection=self.connection,
            payload=get_payload,
        )

        paths = extract_schema_paths(get_response.render(), null=False)

        expected_paths = [
            [
                api_constants.SCHEMA,
                api_constants.MODELS,
                Address.__name__,
                schema_constants.METHODS,
                method_constants.GET,
                address_get_constants.ADDRESS_ID,
            ],
            [
                api_constants.SCHEMA,
                api_constants.MODELS,
                Address.__name__,
                schema_constants.INSTANCES,
                active_address._id,
                schema_constants.ATTRIBUTES,
                address_fields.VALUE,
            ],
        ]

        self.assertEqual(len(paths), len(expected_paths))
        for path in paths:
            print('PATH... ', path)
            self.assertTrue(path in expected_paths)
コード例 #2
0
    def test_schema_paths(self):
        null_payload = None

        response = self.schema.respond(
            system=self.system,
            connection=self.connection,
            payload=null_payload,
        )
        rendered_response = response.render()
        paths = extract_schema_paths(rendered_response)

        expected_paths = [
            [
                api_constants.SCHEMA,
                transactino_constants.README,
            ],
            [
                api_constants.SCHEMA,
                transactino_constants.SOCKET,
            ],
            [
                api_constants.SCHEMA,
                api_constants.MODELS,
                Account.__name__,
                schema_constants.METHODS,
                method_constants.CREATE,
                account_fields.PUBLIC_KEY,
            ],
            [
                api_constants.SCHEMA,
                api_constants.MODELS,
                System.__name__,
                schema_constants.METHODS,
                method_constants.GET,
            ],
            [
                api_constants.SCHEMA,
                api_constants.MODELS,
                System.__name__,
                schema_constants.INSTANCES,
            ],
        ]

        self.assertEqual(len(paths), len(expected_paths))
        for path in paths:
            print('PATH... ', path)
            self.assertTrue(path in expected_paths)
コード例 #3
0
    def test_payment_get(self):
        payment = self.account.payments.create(is_open=True)
        get_payload = {
            api_constants.SCHEMA: {
                api_constants.MODELS: {
                    Payment.__name__: {
                        schema_constants.METHODS: {
                            method_constants.GET: {},
                        },
                    },
                },
            },
        }

        get_response = self.schema.respond(
            system=self.system,
            connection=self.connection,
            payload=get_payload,
        )

        paths = extract_schema_paths(get_response.render(), null=False)

        expected_paths = [
            [
                api_constants.SCHEMA,
                api_constants.MODELS,
                Payment.__name__,
                schema_constants.METHODS,
                method_constants.GET,
                payment_get_constants.PAYMENT_ID,
            ],
            [
                api_constants.SCHEMA,
                api_constants.MODELS,
                Payment.__name__,
                schema_constants.METHODS,
                method_constants.GET,
                payment_fields.IS_OPEN,
            ],
            [
                api_constants.SCHEMA,
                api_constants.MODELS,
                Payment.__name__,
                schema_constants.INSTANCES,
                payment._id,
                schema_constants.ATTRIBUTES,
                payment_fields.ORIGIN,
            ],
            [
                api_constants.SCHEMA,
                api_constants.MODELS,
                Payment.__name__,
                schema_constants.INSTANCES,
                payment._id,
                schema_constants.ATTRIBUTES,
                payment_fields.IS_OPEN,
            ],
            [
                api_constants.SCHEMA,
                api_constants.MODELS,
                Payment.__name__,
                schema_constants.INSTANCES,
                payment._id,
                schema_constants.ATTRIBUTES,
                payment_fields.TIME_CONFIRMED,
            ],
            [
                api_constants.SCHEMA,
                api_constants.MODELS,
                Payment.__name__,
                schema_constants.INSTANCES,
                payment._id,
                schema_constants.ATTRIBUTES,
                payment_fields.FULL_BTC_AMOUNT,
            ],
            [
                api_constants.SCHEMA,
                api_constants.MODELS,
                Payment.__name__,
                schema_constants.INSTANCES,
                payment._id,
                schema_constants.ATTRIBUTES,
                payment_fields.BLOCK_HASH,
            ],
            [
                api_constants.SCHEMA,
                api_constants.MODELS,
                Payment.__name__,
                schema_constants.INSTANCES,
                payment._id,
                schema_constants.ATTRIBUTES,
                payment_fields.TXID,
            ],
            [
                api_constants.SCHEMA,
                api_constants.MODELS,
                Payment.__name__,
                schema_constants.INSTANCES,
                payment._id,
                schema_constants.ATTRIBUTES,
                payment_fields.INDEX,
            ],
            [
                api_constants.SCHEMA,
                api_constants.MODELS,
                Payment.__name__,
                schema_constants.INSTANCES,
                payment._id,
                schema_constants.RELATIONSHIPS,
                payment_fields.ADDRESS,
            ],
        ]

        self.assertEqual(len(paths), len(expected_paths))
        for path in paths:
            print('PATH... ', path)
            self.assertTrue(path in expected_paths)
コード例 #4
0
    def test_subscription_get(self):
        subscription = self.account.subscriptions.create(is_active=False)
        get_payload = {
            api_constants.SCHEMA: {
                api_constants.MODELS: {
                    Subscription.__name__: {
                        schema_constants.METHODS: {
                            method_constants.GET: {},
                        },
                    },
                },
            },
        }

        get_response = self.schema.respond(
            system=self.system,
            connection=self.connection,
            payload=get_payload,
        )

        paths = extract_schema_paths(get_response.render(), null=False)

        expected_paths = [
            [
                api_constants.SCHEMA,
                api_constants.MODELS,
                Subscription.__name__,
                schema_constants.METHODS,
                method_constants.GET,
                subscription_get_constants.SUBSCRIPTION_ID,
            ],
            [
                api_constants.SCHEMA,
                api_constants.MODELS,
                Subscription.__name__,
                schema_constants.METHODS,
                method_constants.GET,
                subscription_fields.IS_ACTIVE,
            ],
            [
                api_constants.SCHEMA,
                api_constants.MODELS,
                Subscription.__name__,
                schema_constants.INSTANCES,
                subscription._id,
                schema_constants.ATTRIBUTES,
                subscription_fields.ORIGIN,
            ],
            [
                api_constants.SCHEMA,
                api_constants.MODELS,
                Subscription.__name__,
                schema_constants.INSTANCES,
                subscription._id,
                schema_constants.ATTRIBUTES,
                subscription_fields.DURATION_IN_DAYS,
            ],
            [
                api_constants.SCHEMA,
                api_constants.MODELS,
                Subscription.__name__,
                schema_constants.INSTANCES,
                subscription._id,
                schema_constants.ATTRIBUTES,
                subscription_fields.ACTIVATION_DATE,
            ],
            [
                api_constants.SCHEMA,
                api_constants.MODELS,
                Subscription.__name__,
                schema_constants.INSTANCES,
                subscription._id,
                schema_constants.ATTRIBUTES,
                subscription_fields.IS_VALID_UNTIL,
            ],
            [
                api_constants.SCHEMA,
                api_constants.MODELS,
                Subscription.__name__,
                schema_constants.INSTANCES,
                subscription._id,
                schema_constants.ATTRIBUTES,
                subscription_fields.HAS_BEEN_ACTIVATED,
            ],
            [
                api_constants.SCHEMA,
                api_constants.MODELS,
                Subscription.__name__,
                schema_constants.INSTANCES,
                subscription._id,
                schema_constants.ATTRIBUTES,
                subscription_fields.IS_ACTIVE,
            ],
        ]

        self.assertEqual(len(paths), len(expected_paths))
        for path in paths:
            print('PATH... ', path)
            self.assertTrue(path in expected_paths)
コード例 #5
0
    def test_schema_paths(self):
        null_payload = None

        response = self.schema.respond(
            system=self.system,
            connection=self.connection,
            payload=null_payload,
        )
        rendered_response = response.render()
        paths = extract_schema_paths(rendered_response)

        expected_paths = [
            [
                api_constants.SCHEMA,
                transactino_constants.README,
            ],
            [
                api_constants.SCHEMA,
                transactino_constants.SOCKET,
            ],
            [
                api_constants.SCHEMA,
                transactino_constants.SYSTEM,
            ],
            [
                api_constants.SCHEMA,
                transactino_constants.ANNOUNCEMENTS,
            ],
            [
                api_constants.SCHEMA,
                api_constants.MODELS,
                Account.__name__,
                schema_constants.METHODS,
                account_unsubscribed_method_constants.VERIFY,
            ],
            [
                api_constants.SCHEMA,
                api_constants.MODELS,
                Account.__name__,
                schema_constants.METHODS,
                method_constants.DELETE,
            ],
            [
                api_constants.SCHEMA,
                api_constants.MODELS,
                Address.__name__,
                schema_constants.METHODS,
                method_constants.GET,
                address_get_constants.ADDRESS_ID,
            ],
            [
                api_constants.SCHEMA,
                api_constants.MODELS,
                Address.__name__,
                schema_constants.INSTANCES,
            ],
            [
                api_constants.SCHEMA,
                api_constants.MODELS,
                Announcement.__name__,
                schema_constants.METHODS,
                method_constants.GET,
            ],
            [
                api_constants.SCHEMA,
                api_constants.MODELS,
                Announcement.__name__,
                schema_constants.INSTANCES,
            ],
            [
                api_constants.SCHEMA,
                api_constants.MODELS,
                Challenge.__name__,
                schema_constants.METHODS,
                challenge_method_constants.RESPOND,
                challenge_respond_constants.CHALLENGE_ID,
            ],
            [
                api_constants.SCHEMA,
                api_constants.MODELS,
                Challenge.__name__,
                schema_constants.METHODS,
                challenge_method_constants.RESPOND,
                challenge_respond_constants.CONTENT,
            ],
            [
                api_constants.SCHEMA,
                api_constants.MODELS,
                Challenge.__name__,
                schema_constants.METHODS,
                method_constants.GET,
                challenge_get_constants.CHALLENGE_ID,
            ],
            [
                api_constants.SCHEMA,
                api_constants.MODELS,
                Challenge.__name__,
                schema_constants.METHODS,
                method_constants.GET,
                challenge_fields.IS_OPEN,
            ],
            [
                api_constants.SCHEMA,
                api_constants.MODELS,
                Challenge.__name__,
                schema_constants.METHODS,
                method_constants.DELETE,
                challenge_delete_constants.CHALLENGE_ID,
            ],
            [
                api_constants.SCHEMA,
                api_constants.MODELS,
                Challenge.__name__,
                schema_constants.INSTANCES,
            ],
            [
                api_constants.SCHEMA,
                api_constants.MODELS,
                System.__name__,
                schema_constants.METHODS,
                method_constants.GET,
            ],
            [
                api_constants.SCHEMA,
                api_constants.MODELS,
                System.__name__,
                schema_constants.INSTANCES,
            ],
        ]

        self.assertEqual(len(paths), len(expected_paths))
        for path in paths:
            print('PATH... ', path)
            self.assertTrue(path in expected_paths)
コード例 #6
0
    def test_system_get(self):
        get_payload = {
            api_constants.SCHEMA: {
                api_constants.MODELS: {
                    System.__name__: {
                        schema_constants.METHODS: {
                            method_constants.GET: {},
                        },
                    },
                },
            },
        }

        get_response = self.schema.respond(
            system=self.system,
            connection=self.connection,
            payload=get_payload,
        )

        paths = extract_schema_paths(get_response.render(), null=False)

        expected_paths = [
            [
                api_constants.SCHEMA,
                api_constants.MODELS,
                System.__name__,
                schema_constants.METHODS,
            ],
            [
                api_constants.SCHEMA,
                api_constants.MODELS,
                System.__name__,
                schema_constants.INSTANCES,
                self.system._id,
                schema_constants.ATTRIBUTES,
                system_fields.PUBLIC_KEY,
            ],
            [
                api_constants.SCHEMA,
                api_constants.MODELS,
                System.__name__,
                schema_constants.INSTANCES,
                self.system._id,
                schema_constants.ATTRIBUTES,
                system_fields.GUARANTEE,
            ],
            [
                api_constants.SCHEMA,
                api_constants.MODELS,
                System.__name__,
                schema_constants.INSTANCES,
                self.system._id,
                schema_constants.ATTRIBUTES,
                system_fields.GUARANTEE_SIGNATURE,
            ],
            [
                api_constants.SCHEMA,
                api_constants.MODELS,
                System.__name__,
                schema_constants.INSTANCES,
                self.system._id,
                schema_constants.ATTRIBUTES,
                system_fields.DISCLAIMER,
            ],
            [
                api_constants.SCHEMA,
                api_constants.MODELS,
                System.__name__,
                schema_constants.INSTANCES,
                self.system._id,
                schema_constants.ATTRIBUTES,
                system_fields.DISCLAIMER_SIGNATURE,
            ],
        ]

        self.assertEqual(len(paths), len(expected_paths))
        for path in paths:
            print('PATH... ', path)
            self.assertTrue(path in expected_paths)
コード例 #7
0
    def test_challenge_get(self):
        open_challenge_content = 'open_challenge_content'
        open_challenge = self.account.challenges.create(
            is_open=True,
            encrypted_content=open_challenge_content,
        )
        closed_challenge_content = 'closed_challenge_content'
        closed_challenge = self.account.challenges.create(
            is_open=False,
            encrypted_content=closed_challenge_content,
        )

        get_payload = {
            api_constants.SCHEMA: {
                api_constants.MODELS: {
                    Challenge.__name__: {
                        schema_constants.METHODS: {
                            method_constants.GET: {},
                        },
                    },
                },
            },
        }

        get_response = self.schema.respond(
            system=self.system,
            connection=self.connection,
            payload=get_payload,
        )

        paths = extract_schema_paths(get_response.render(), null=False)

        expected_paths = [
            [
                api_constants.SCHEMA,
                api_constants.MODELS,
                Challenge.__name__,
                schema_constants.METHODS,
                method_constants.GET,
                challenge_get_constants.CHALLENGE_ID,
            ],
            [
                api_constants.SCHEMA,
                api_constants.MODELS,
                Challenge.__name__,
                schema_constants.METHODS,
                method_constants.GET,
                challenge_fields.IS_OPEN,
            ],
            [
                api_constants.SCHEMA,
                api_constants.MODELS,
                Challenge.__name__,
                schema_constants.INSTANCES,
                open_challenge._id,
                schema_constants.ATTRIBUTES,
                challenge_fields.ENCRYPTED_CONTENT,
            ],
            [
                api_constants.SCHEMA,
                api_constants.MODELS,
                Challenge.__name__,
                schema_constants.INSTANCES,
                closed_challenge._id,
                schema_constants.ATTRIBUTES,
                challenge_fields.ENCRYPTED_CONTENT,
            ],
        ]

        self.assertEqual(len(paths), len(expected_paths))
        for path in paths:
            print('PATH... ', path)
            self.assertTrue(path in expected_paths)
コード例 #8
0
    def test_announcement_get(self):
        active_announcement = Announcement.objects.create_and_sign(
            system=self.system,
            matter='active',
        )
        active_announcement.activate()
        inactive_announcement = Announcement.objects.create_and_sign(
            system=self.system,
            matter='inactive',
        )

        get_payload = {
            api_constants.SCHEMA: {
                api_constants.MODELS: {
                    Announcement.__name__: {
                        schema_constants.METHODS: {
                            method_constants.GET: {},
                        },
                    },
                },
            },
        }

        get_response = self.schema.respond(
            system=self.system,
            connection=self.connection,
            payload=get_payload,
        )

        paths = extract_schema_paths(get_response.render(), null=False)

        expected_paths = [
            [
                api_constants.SCHEMA,
                api_constants.MODELS,
                Announcement.__name__,
                schema_constants.METHODS,
            ],
            [
                api_constants.SCHEMA,
                api_constants.MODELS,
                Announcement.__name__,
                schema_constants.INSTANCES,
                active_announcement._id,
                schema_constants.ATTRIBUTES,
                announcement_fields.MATTER,
            ],
            [
                api_constants.SCHEMA,
                api_constants.MODELS,
                Announcement.__name__,
                schema_constants.INSTANCES,
                active_announcement._id,
                schema_constants.ATTRIBUTES,
                announcement_fields.SIGNATURE,
            ],
            [
                api_constants.SCHEMA,
                api_constants.MODELS,
                Announcement.__name__,
                schema_constants.INSTANCES,
                active_announcement._id,
                schema_constants.ATTRIBUTES,
                announcement_fields.DATE_ACTIVATED,
            ],
        ]

        self.assertEqual(len(paths), len(expected_paths))
        for path in paths:
            print('PATH... ', path)
            self.assertTrue(path in expected_paths)