def run(self, *args, **kwargs):
        """Run WriteVolumesDb Action."""
        data_from_namespace = kwargs.get(NAMESPACE_CINDER_CONST)
        if not data_from_namespace:
            raise AbortMigrationError(
                "Cannot read attribute {attribute} from namespace".format(
                    attribute=NAMESPACE_CINDER_CONST))

        self.cloud = {
            SRC: {
                CLOUD: self.src_cloud,
                RES: self.src_cloud.resources.get(utils.STORAGE_RESOURCE),
                CFG: self.cfg.src,
            },
            DST: {
                CLOUD: self.dst_cloud,
                RES: self.dst_cloud.resources.get(utils.STORAGE_RESOURCE),
                CFG: self.cfg.dst,
            }
        }

        self.data[SRC] = jsondate.loads(data_from_namespace)

        search_opts = kwargs.get('search_opts_tenant', {})
        self.data[DST] = jsondate.loads(
            self.cloud[DST][RES].read_db_info(**search_opts))

        LOG.debug('Cloud info: %s', str(self.cloud))

        self._copy_volumes()

        self.data[SRC] = _modify_data(self.data[SRC])
        self.cloud[DST][RES].deploy(jsondate.dumps(self.data[SRC]))
Ejemplo n.º 2
0
    def __init__(self):
        print("GUI class instantiated")

        # just to test that HTTP requests are working
        r = requests.get('http://api.github.com/users/octocat/orgs')
        DirectLabel(text=r.headers['date'], scale=0.09, hpr=(0, 0, 0),
                    pos=(0, 0, 0.7), frameColor=(0, 0, 0, 0))

        # Right now this is just a pile of mess :)
        r = requests.get('http://localhost:5001/api/question')
        print r
        # print r.text
        print r.status_code
        print type(r.status_code)
        r_dict = json.loads(r.text)
        json.loads(r.text)['objects']
Ejemplo n.º 3
0
    def parse_config(self):
        """
        Parse a JSON config.

        Keyword arguments:
        config_path -- Path to a seedbank.json
        """
        self.data = json.loads(open(self.path, 'r').read())
Ejemplo n.º 4
0
    def test_json_output(self, diff_res, expected):
        diff_json = diff_res[0].dump_json(indent=4)

        if os.environ.get('REGENERATE', 'false') == 'true':
            expected.write(diff_json)
            return

        assert jsondate.loads(diff_json) == jsondate.load(expected)
Ejemplo n.º 5
0
    def test_dumps_datelike_string_does_not_roundtrip(self):
        """A string that looks like a date *will* be interpreted as a date.

        If for whatever reason, you don't want that to happen, you'll need to
        do some pre or post-processing to fixup the results.
        """
        orig_dict = dict(created_at='2011-01-01')
        expected = dict(created_at=datetime.date(2011, 1, 1))
        self.assertEqual(expected, jsondate.loads(jsondate.dumps(orig_dict)))
Ejemplo n.º 6
0
    def __init__(self):
        print("GUI class instantiated")

        # just to test that HTTP requests are working
        r = requests.get('http://api.github.com/users/octocat/orgs')
        DirectLabel(text=r.headers['date'],
                    scale=0.09,
                    hpr=(0, 0, 0),
                    pos=(0, 0, 0.7),
                    frameColor=(0, 0, 0, 0))

        # Right now this is just a pile of mess :)
        r = requests.get('http://localhost:5001/api/question')
        print r
        # print r.text
        print r.status_code
        print type(r.status_code)
        r_dict = json.loads(r.text)
        json.loads(r.text)['objects']
Ejemplo n.º 7
0
    def test_dump_unicode_roundtrips(self):
        orig_dict = {u'foo': u'bar', 'empty': u''}

        # json module broken: unicode objects, empty-string objects are str
        result = json.loads(json.dumps(orig_dict))
        self.assertTypeAndValue(unicode, u'bar', result[u'foo'])
        self.assertTypeAndValue(str, '', result[u'empty'])

        # jsondate fix: always return unicode objects
        result = jsondate.loads(jsondate.dumps(orig_dict))
        self.assertTypeAndValue(unicode, u'bar', result[u'foo'])
        self.assertTypeAndValue(unicode, u'', result[u'empty'])
Ejemplo n.º 8
0
 def run(self, *args, **kwargs):
     data_from_namespace = kwargs.get(NAMESPACE_CINDER_CONST)
     if not data_from_namespace:
         raise RuntimeError(
             "Cannot read attribute {attribute} from namespace".format(
                 attribute=NAMESPACE_CINDER_CONST))
     data = jsondate.loads(data_from_namespace)
     # mark attached volumes as available
     for volume in data['volumes']:
         if volume['status'] == 'in-use':
             volume['mountpoint'] = None
             volume['status'] = 'available'
             volume['instance_uuid'] = None
             volume['attach_status'] = 'detached'
     self.get_resource().deploy(jsondate.dumps(data))
 def run(self, *args, **kwargs):
     data_from_namespace = kwargs.get(NAMESPACE_CINDER_CONST)
     if not data_from_namespace:
         raise RuntimeError(
             "Cannot read attribute {attribute} from namespace".format(
                 attribute=NAMESPACE_CINDER_CONST))
     data = jsondate.loads(data_from_namespace)
     # mark attached volumes as available
     for volume in data['volumes']:
         if volume['status'] == 'in-use':
             volume['mountpoint'] = None
             volume['status'] = 'available'
             volume['instance_uuid'] = None
             volume['attach_status'] = 'detached'
     self.get_resource().deploy(jsondate.dumps(data))
Ejemplo n.º 10
0
    def from_file(file_path):
        """
        Initialize an archive by parsing it from a file.

        Keyword arguments:
        file_path -- Path to read JSON from.
        """
        archive = Archive()
        archive_obj = json.loads(open(file_path, 'r').read())
        archive.create_time = archive_obj['create_time']
        archive.description = archive_obj['description']
        archive.uid = archive_obj['uid']
        archive.file_list = archive_obj['file_list']
        archive.aws_response = archive_obj['aws_response']
        archive.size = archive_obj['size']
        archive.remote_id = archive_obj['remote_id']
        return archive
Ejemplo n.º 11
0
 def deploy(self, data):
     """ Reads serialized data and writes it to database """
     for table_name, table_data in jsondate.loads(data).items():
         self.deploy_data_to_table(table_name, table_data)
Ejemplo n.º 12
0
    {'name': 'After the experience', 'sort_nr': '3',
    'info_text': 'Questions regarding post-play', 'questionnaire_id': '1'}
]

question_sets_ids = []
for qs in question_sets:
    r = requests.post('{}/question_set'.format(BASE_URL),
                      data=json.dumps(qs),
                      headers={'content-type': 'application/json'})
    if r.status_code == 201:
        log.info('Question set {} with status code {}'.format(qs['name'], r.status_code))
    else:
        log.error('Question set {} with status code {}'.format(qs['name'], r.status_code))


    question_sets_ids.append(json.loads(r.text)['id'])

# Questions
questions = [
    ## Before
    {'question': 'Please select your gender',
    'sort_nr': '1', 'type': '2', 'info_text': '', 'question_set_id': question_sets_ids[0]},
    {'question': 'Please type in your age',
    'sort_nr': '2', 'type': '3', 'info_text': 'In a single, whole number (e.g. 15)',
    'question_set_id': question_sets_ids[0]},
    {'question': 'How many hours (approximately) do you play video games per week?',
    'sort_nr': '3', 'type': '1', 'info_text': 'In a single, whole number (e.g. 15)',
    'question_set_id': question_sets_ids[0]},
    {'question': 'List a few of your favourite games or game genres',
    'sort_nr': '4', 'type': '3', 'info_text': '', 'question_set_id': question_sets_ids[0]},
    {'question': 'Please indicate below the extent to which you agree or disagree with this sentence: "I want to begin the experience"',
Ejemplo n.º 13
0
 def deploy(self, data):
     """ Reads serialized data and writes it to database """
     for table_name, table_data in jsondate.loads(data).items():
         self.deploy_data_to_table(table_name, table_data)
Ejemplo n.º 14
0
import jsondate as json
import requests
from logbook import Logger, FileHandler, StderrHandler


BASE_URL = 'http://fmr-api-507.herokuapp.com/api'
log = Logger('Logbook')
log_filehandler = FileHandler('application.log')
log_stderrhandler = StderrHandler()

# Participants
participants = [
    {'scenario': '0'},
    {'scenario': '1'},
    {'scenario': '0'}
]

participants_ids = []
for p in participants:
    r = requests.post('{}/participant'.format(BASE_URL),
                      data=json.dumps(p),
                      headers={'content-type': 'application/json'})
    if r.status_code == 201:
        log.info('Participant with scenario {} with status code {}'.format(p['scenario'], r.status_code))
        participants_ids.append(json.loads(r.text)['id'])
    else:
        log.error('Participant with scenario {} with status code {}'.format(p['scenario'], r.status_code))
        print r.text

Ejemplo n.º 15
0
 def test_dumps_none_roundtrips(self):
     # Generates a TypeError from _datetime_object_hook
     orig_dict = dict(foo=None)
     self.assertEqual(orig_dict, jsondate.loads(jsondate.dumps(orig_dict)))
Ejemplo n.º 16
0
 def deserializar_datetime(self, payload):
     data = jsondate.loads(payload)
     return data
Ejemplo n.º 17
0
 def test_dumps_date_roundtrips(self):
     orig_dict = dict(created_at=datetime.date(2011, 1, 1))
     self.assertEqual(orig_dict, jsondate.loads(jsondate.dumps(orig_dict)))
Ejemplo n.º 18
0
 def _get(self, key):
     value = super(TaskDb, self)._get(key)
     if value.strip():
         return json.loads(value)
     else:
         return None
Ejemplo n.º 19
0
 def test_dumps_str_roundtrips(self):
     # Generates a ValueError from _datetime_object_hook
     orig_dict = dict(foo='bar')
     self.assertEqual(orig_dict, jsondate.loads(jsondate.dumps(orig_dict)))
Ejemplo n.º 20
0
 def roundtrip(input):
     return jsondate.loads(jsondate.dumps(input))
Ejemplo n.º 21
0
 def test_dumps_empty_roundtrips(self):
     self.assertEqual({}, jsondate.loads(jsondate.dumps({})))