Esempio n. 1
0
def test_get_with_reference(requireMocking):
    # store data
    tm = TableManager()
    table = tm.get_acquisition_table()
    item = {
        'sample': '180415dZKsa20_1',
        'experiment': '12345',
        'acquisition': {
            'instrument': 'Leco GC-Tof',
            'name': 'GCTOF',
            'ionisation': 'positive',
            'method': 'gcms'
        },
        'metadata': {
            'class': '382172',
            'species': 'rat',
            'organ': 'tissue'
        },
        'userdata': {
            'label': 'GP_S_6_006',
            'comment': ''
        },
        'processing': {
            'method': 'gcms | test | test | positive'
        },
        'time': 1525121375499,
        'id': '180415dZKsa20_1',
        'references': [{
            'name': 'minix',
            'value': '12345'
        }]
    }
    try:
        validate(item, __ACQUISITION_SCHEMA__)
        table.put_item(Item=tm.sanitize_json_for_dynamo(item))
    except ValidationException as vex:
        result = None
        fail(str(vex.body))
    except ClientError as cer:
        result = None
        fail(str(cer.response))

    # process data

    result = get.get({"pathParameters": {"sample": "180415dZKsa20_1"}}, {})

    assert result['statusCode'] == 200
    assert json.loads(result['body'])["id"] == "180415dZKsa20_1"
    assert json.loads(
        result['body'])["acquisition"]["instrument"] == "Leco GC-Tof"
    assert json.loads(result['body'])["references"][0]["name"] == "minix"
    assert json.loads(result['body'])["references"][0]["value"] == "12345"
Esempio n. 2
0
def test_get_experiment(requireMocking, sample_count):
    tm = TableManager()
    table = tm.get_acquisition_table()

    try:
        for x in range(0, sample_count):
            table.put_item(Item=tm.sanitize_json_for_dynamo({
                "sample": f"test-{x:06d}",
                "experiment": "1",
                "id": f"test-{x:06d}",
                "acquisition": {
                    "instrument": "random",
                    "ionisation": "positive",
                    "method": "test-method"
                },
                "metadata": {
                    "class": f"{x%100}",
                    "species": "rat",
                    "organ": "tissue"
                },
                "userdata": {
                    "label": "GP_S_6_006",
                    "comment": ""
                },
                "processing": {
                    "method": "test-method | random | test | positive"
                }
            }))
    except ValidationException as vex:
        result = None
        fail(str(vex.body))
    except ClientError as cer:
        result = None
        fail(str(cer.response))

    page_size = 3

    result = experiment.get(
        {'pathParameters': {
            'experiment': '1',
            'psize': page_size
        }}, {})

    data = json.loads(result['body'])

    assert result['statusCode'] == 200
    assert len(data['items']) == page_size
    assert data['last_item']['id'] == 'test-000002'
Esempio n. 3
0
class DynamoDBBasedConfigManager(ConfigManager):
    """
    configuration manager based on key/value storage of data in dynamodb
    """
    def email_sender(self) -> str:
        result = str(
            self._get_item("sender", "*****@*****.**", "notification"))
        return result

    def notification_enabled(self) -> bool:
        return bool(
            self._get_item("automatic_notifications", False, "notification"))

    def notification_emails(self) -> List[str]:
        result = list(
            self._get_item("notify", ["*****@*****.**"],
                           "notification"))
        return result

    def __init__(self):
        self.tm = TableManager()
        self.table = self.tm.get_configuration_table()

    def _default_singular_tasks(self) -> List[str]:
        """
        default value for tasks, which can not run in parallel
        """
        return [SECURE_CARROT_STEAC]

    def _default_tasks(self) -> Dict:
        """
        default values for tasks
        """
        return {
            SECURE_CARROT_RUNNER: 10,
            SECURE_CARROT_AGGREGATOR: 1,
            SECURE_CARROT_STEAC: 1
        }

    def tasks(self) -> Dict[str, int]:
        result = self._get_item("tasks", self._default_tasks())
        return result

    def max_allowed_tasks(self) -> int:
        result = int(self._get_item("max_concurrent_tasks", 20))

        return result

    def max_tasks_for_service(self, service: str) -> int:
        result = int(self._get_item(service, self._default_tasks()[service]))
        return result

    def is_singular(self, name: str) -> bool:
        return name in self.singular_tasks()

    def singular_tasks(self) -> List[str]:
        return self._default_singular_tasks()

    def automatic_scheduling(self) -> bool:
        return bool(self._get_item("automatic_scheduling", True))

    def _get_item(self, name, default_value, group: str = "fargate"):
        results = self.table.query(KeyConditionExpression=Key("key").eq(name))
        if results['Count'] == 0:
            self.table.put_item(
                Item=self.tm.sanitize_json_for_dynamo({
                    "key": name,
                    "range": group,
                    "value": default_value
                }))
            results = self.table.query(
                KeyConditionExpression=Key("key").eq(name))
        top = results['Items'][0]
        return top['value']