<commit_before>﻿# Copyright 2016 The Johns Hopkins University Applied Physics Laboratory
#
# 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.
 
from ndio.remote.boss import BossRemote
from ndio.ndresource.boss.resource import *

import requests
from requests import Session, HTTPError
from requests.packages.urllib3.exceptions import InsecureRequestWarning

import copy
import unittest

API_VER = 'v0.7'

class ProjectServiceTest_v0_7(unittest.TestCase):
    """Integration tests of the Boss resource API.
    """

    @classmethod
    def setUpClass(cls):
        """Do an initial DB clean up in case something went wrong the last time.

        If a test failed really badly, the DB might be in a bad state despite
        attempts to clean up during tearDown().
        """
        cls.initialize(cls)
        cls.cleanup_db(cls)

    def initialize(self):
        """Initialization for each test.

        Called by both setUp() and setUpClass().
        """
        self.rmt = BossRemote(cfg_file='test.cfg')

        # Turn off SSL cert verification.  This is necessary for interacting with
        # developer instances of the Boss.
        self.rmt.project_service.session_send_opts = { 'verify': False }
        self.rmt.metadata_service.session_send_opts = { 'verify': False }
        self.rmt.volume_service.session_send_opts = { 'verify': False }
        requests.packages.urllib3.disable_warnings(InsecureRequestWarning)

        self.coll = CollectionResource('collection2309', API_VER, 'bar')
        self.coll_upd = CollectionResource('collection2310', API_VER, 'latest')

        self.coord = CoordinateFrameResource(
            'BestFrame', API_VER, 'Test coordinate frame.', 0, 10, -5, 5, 3, 6, 
            1, 1, 1, 'nanometers', 2, 'nanoseconds')
        self.coord_upd = copy.copy(self.coord)
        self.coord_upd.name = 'MouseFrame'
        self.coord_upd.description = 'Mouse coordinate frame.'

        self.exp = ExperimentResource(
            'exp2309-2', self.coll.name, self.coord.name, API_VER, 'my experiment', 
            1, 'iso', 1)<commit_msg>Added random num to coord frame/collection names. Randomized to avoid collisions with simultaneous integration test runs.<commit_after>﻿# Copyright 2016 The Johns Hopkins University Applied Physics Laboratory
#
# 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.
 
from ndio.remote.boss import BossRemote
from ndio.ndresource.boss.resource import *

import random
import requests
from requests import Session, HTTPError
from requests.packages.urllib3.exceptions import InsecureRequestWarning

import copy
import unittest

API_VER = 'v0.7'

class ProjectServiceTest_v0_7(unittest.TestCase):
    """Integration tests of the Boss resource API.
    """

    @classmethod
    def setUpClass(cls):
        """Do an initial DB clean up in case something went wrong the last time.

        If a test failed really badly, the DB might be in a bad state despite
        attempts to clean up during tearDown().
        """
        cls.initialize(cls)
        cls.cleanup_db(cls)

    def initialize(self):
        """Initialization for each test.

        Called by both setUp() and setUpClass().
        """
        self.rmt = BossRemote(cfg_file='test.cfg')

        # Turn off SSL cert verification.  This is necessary for interacting with
        # developer instances of the Boss.
        self.rmt.project_service.session_send_opts = { 'verify': False }
        self.rmt.metadata_service.session_send_opts = { 'verify': False }
        self.rmt.volume_service.session_send_opts = { 'verify': False }
        requests.packages.urllib3.disable_warnings(InsecureRequestWarning)

        coll_name = 'collection2309-{}'.format(random.randint(0, 9999))
        self.coll = CollectionResource(coll_name, API_VER, 'bar')
        coll_name_upd = '{}-{}'.format(coll_name, random.randint(0, 9999))
        self.coll_upd = CollectionResource('collection2310', API_VER, 'latest')

        cf_name = 'BestFrame{}'.format(random.randint(0, 9999))
        self.coord = CoordinateFrameResource(
            cf_name, API_VER, 'Test coordinate frame.', 0, 10, -5, 5, 3, 6, 
            1, 1, 1, 'nanometers', 2, 'nanoseconds')
        self.coord_upd = copy.copy(self.coord)
        self.coord_upd.name = 'MouseFrame'
        self.coord_upd.description = 'Mouse coordinate frame.'

        self.exp = ExperimentResource(
            'exp2309-2', self.coll.name, self.coord.name, API_VER, 'my experiment', 
            1, 'iso', 1)
{'fraction_non_alphanumeric': 0.09257226491035492, 'fraction_numerical': 0.01738016831320893, 'mean_word_length': 3.2183641975308643, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2359922', 'n_tokens_mistral': 1604, 'n_tokens_neox': 1506, 'n_words': 520}