1. Technical Field
The first time I s
Q:
How does the f
In-vitro studies o
Q:
How to save a
//
// Test_XCTest
This invention rel
"Celui qui a mis c
A typical conventi# Copyright (C) 2015 Mikolaj Zalewski
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
import os
import logging
import time
import unittest
import requests_mock
import responses_mock
from lxml.etree import ElementTree
from requests.adapters import HTTPAdapter
import mock
from mwd.models import (Account, Transaction, Block, Address, BlockDiff, FeeStatus,
AddressDiff, UuidToAddress)
from mwd.services.api.v2.helpers.address_helpers import get_all_addresses
from mwd.services.common.api.errors import BAD_REQUEST_ERROR
from mwd.services.common.api.errors import BadRequestError, BadResponseError
from mwd.services.common.constants import BLOCKCHAIN_PATH, BUCKET_PREFIX, \
CONTRACTS_PATH, BLOCK_PREFIX
from mwd.services.common.types import AddressType
from mwd.services.common.api.helpers import RequestHelper
try:
from Crypto.Random import random
except ImportError:
from mwd.services.crypto import Crypto
random = Crypto.Random.get_random_bytes
class TestAPI(unittest.TestCase):
def setUp(self):
pass
def test_get_block_details_invalid_type(self):
"""Test API returns 400 bad request when not passing block type."""
block = Block(uuid=123, height=0, txns=[], type='random_type')
url = '{}/{}'.format(BLOCK_PREFIX, str(block.uuid))
response = requests_mock.get(url, text=repr(block))
self.assertRaises(requests_mock.BadRequest,
Block.get_block_details,
response, type='random_type')
def test_get_block_details(self):
"""Test API returns good response for block with passed type."""
block = Block(uuid=123, height=0, txns=[], type='data')
url = '{}/{}'.format(BLOCK_PREFIX, str(block.uuid))
response = requests_mock.get(url, text=repr(block))
self.assertEqual(
str(block), response.text)
self.assertFalse(response.status_code)
def test_get_block_details_invalid_type(self):
"""Test API returns 400 bad request when not passing block type."""
block = Block(uuid=123, height=0, txns=[], type='123')
url = '{}/{}'.format(BLOCK_PREFIX, str(block.uuid))
response = requests_mock.get(url, text=repr(block))
self.assertRaises(requests_mock.BadRequest,
Block.get_block_details,
response, type='123')
def test_get_block_details_no_txns(self):
"""Test API returns 400 bad request when no txns added to block."""
block = Block(uuid=123, height=0)
url = '{}/{}'.format(BLOCK_PREFIX, str(block.uuid))
response = requests_mock.get(url, text=repr(block))
self.assertRaises(requests_mock.BadRequest,
Block.get_block_details,
response,
txn_check_query=False)
def test_get_block_details_height(self):
"""Test API returns 400 bad request when no height passed."""
block = Block(uuid=123, height=0, txns=[], type='data')
url = '{}/{}'.format(BLOCK_PREFIX, str(block.uuid))
response = requests_mock.get(url, text=repr(block))
self.assertRaises(requests_mock.BadRequest,
Block.get_block_details,
response, height=123)
def test_get_block_details_height_invalid_type(self):
"""Test API returns 400 bad request when no height passed."""
block = Block(uuid=123, height=0, txns=[], type='123')
url = '{}/{}'.format(BLOCK_PREFIX, str(block.uuid))
response = requests_mock.get(url, text=repr(block))
self.assertRaises(requests_mock.BadRequest,
Block.get_block_details,
response, height=123)
def test_get_block_details_txns(self):
"""Test API returns 400 bad request when no txns added to block."""
block = Block(uuid=123, height=0, txns=[], type='data')
url = '{}/{}'.format(BLOCK_PREFIX, str(block.uuid))
response = requests_mock.get(url, text=repr(block))
self.assertRaises(requests_mock.BadRequest,
Block.get_block_details,
response, txn_check_query=False)
def test_get_block_details_txns_invalid_type(self):
"""Test API returns 400 bad request when no txns added to block."""
block = Block(uuid=123, height=0, txns=[], type='123')
url = '{}/{}'.format(BLOCK_PREFIX, str(block.uuid))
response = requests_mock.get(url, text=repr(block))
self.assertRaises(requests_mock.BadRequest,
Block.get_block_details,
response, txn_check_query=False)
def test_get_block_details_contracts(self):
"""Test API returns 400 bad request when no contracts added to block."""
block = Block(uuid=123, height=0, txns=[], type='data')
url = '{}/{}'.format(BLOCK_PREFIX, str(block.uuid))
response = requests_mock.get(url, text=repr(block))
self.assertRaises(requests_mock.BadRequest,
Block.get_block_details,
response, contracts_check_query=False)
def test_get_block_details_contracts_invalid_type(self):
"""Test API returns 400 bad request when no contracts added to block."""
block = Block(uuid=123, height=0, txns=[], type='123')
url = '{}/{}'.format(BLOCK_PREFIX, str(block.uuid))
response = requests_mock.get(url, text=repr(block))
self.assertRaises(requests_mock.BadRequest,
Block.get_block_details,
response, contracts_check_query=False)
def test_get_block_details_no_txns_no_contracts(self):
"""Test API returns 400 bad request when no txns added to block and no contracts passed."""
block = Block(uuid=123, height=0)
url = '{}/{}'.format(BLOCK_PREFIX, str(block.uuid))
response = requests_mock.get(url, text=repr(block))
self.assertRaises(requests_mock.BadRequest,
Block.get_block_details,
response,
txn_check_query=False,
contracts_check_query=False)
def test_get_block_details_no_txns_height(self):
"""Test API returns 400 bad request when no height passed."""
block = Block(uuid=123, height=0, txns=[], type='data')
url = '{}/{}'.format(BLOCK_PREFIX, str(block.uuid))
response = requests_mock.get(url, text=repr(block))
self.assertRaises(requests_mock.BadRequest,
Block.get_block_details,
response, height=123