-
Notifications
You must be signed in to change notification settings - Fork 179
Expand file tree
/
Copy pathread_resource_steps.py
More file actions
59 lines (50 loc) · 2.08 KB
/
read_resource_steps.py
File metadata and controls
59 lines (50 loc) · 2.08 KB
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
# -*- coding: utf-8 -*-
#
# Copyright 2014-2025 BigML
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import time
from datetime import datetime
from bigml.api import HTTP_OK, get_status, get_resource_type
from .world import world, logged_wait, eq_, ok_
def wait_until_status_code_is(code1, code2, secs, resource_info):
"""Waits for the resource to be finished and stores the resulting full
info in the corresponding dictionary. Attention, resource_info is
modified
"""
start = datetime.utcnow()
delta = int(secs) * world.delta
resource_info = world.get_minimal_resource(
resource_info['resource']).get("object")
status = get_status(resource_info)
count = 0
while (status['code'] != int(code1) and
status['code'] != int(code2)):
count += 1
resource_type = get_resource_type(resource_info["resource"])
logged_wait(start, delta, count, resource_type, status=status)
ok_((datetime.utcnow() - start).seconds < delta)
resource_info = world.get_minimal_resource(
resource_info['resource']).get("object")
status = get_status(resource_info)
if status['code'] == int(code2):
world.errors.append(resource_info)
eq_(status['code'], int(code1))
time.sleep(0.1) # added to avoid synch mongo issues
return i_get_the_resource(resource_info)
def i_get_the_resource(resource_info):
"""Step: I get the resource <resource_info>"""
resource = world.get_maximal_resource(resource_info["resource"])
world.status = resource['code']
eq_(world.status, HTTP_OK)
return resource['object']