コード例 #1
0
    def test_with_tocken(self):
        auth = Auth(token=generate_token())

        # If the request is sent successfully, then I expect a response to
        # be returned.
        self.assertIsInstance(auth.__str__(), str)
        self.assertFalse(auth.is_expired())
コード例 #2
0
    def setUp(self):
        self.auth = Auth(token=generate_token())

        with open(os.path.join(DATA_PATH, "sample2.json")) as handle:
            self.data = json.load(handle)

        self.sample = Sample(self.auth, data=self.data)
コード例 #3
0
    def setup_class(cls):
        cls.mock_get_patcher = patch('requests.Session.get')
        cls.mock_get = cls.mock_get_patcher.start()

        # define an auth object
        token = generate_token()
        cls.auth = Auth(token=token)
コード例 #4
0
ファイル: test_team.py プロジェクト: cnr-ibba/pyUSIrest
    def setUp(self):
        self.auth = Auth(token=generate_token())

        with open(os.path.join(DATA_PATH, "team.json")) as handle:
            data = json.load(handle)

        self.team = Team(self.auth, data=data)
コード例 #5
0
    def test_login(self):
        # Call the service, which will send a request to the server.
        auth = Auth(user='******', password='******')

        # If the request is sent successfully, then I expect a response to
        # be returned.
        self.assertIsInstance(auth.__str__(), str)
        self.assertFalse(auth.is_expired())
コード例 #6
0
ファイル: test_team.py プロジェクト: cnr-ibba/pyUSIrest
    def setUp(self):
        self.auth = Auth(token=generate_token())

        # read domain data (a list of domains)
        with open(os.path.join(DATA_PATH, "myDomain.json")) as handle:
            data = json.load(handle)

        self.domain = Domain(self.auth, data=data[0])
コード例 #7
0
    def test_render_token(self):
        """test token rendering with to_json template tags"""

        rendered = self.TEMPLATE.render(
            Context({'auth': Auth(token=generate_token())}))

        self.assertIsInstance(rendered, str)

        data = json.loads(rendered)
        self.assertIsInstance(data, dict)
コード例 #8
0
    def test_expired(self):
        self.mock_get.return_value = Mock()
        self.mock_get.return_value.text = generate_token(
            now=self.now-10000)
        self.mock_get.return_value.status_code = 200

        # Call the service, which will send a request to the server.
        auth = Auth(user='******', password='******')

        self.assertIsInstance(auth.__str__(), str)
        self.assertTrue(auth.is_expired())
コード例 #9
0
    def test_get_domains(self):
        self.mock_get.return_value = Mock()
        self.mock_get.return_value.text = generate_token(
            domains=['subs.test-team-1', 'subs.test-team-2'])
        self.mock_get.return_value.status_code = 200

        auth = Auth(user='******', password='******')

        test_domains = auth.get_domains()

        self.assertEqual(
            test_domains, ['subs.test-team-1', 'subs.test-team-2'])
コード例 #10
0
ファイル: test_root.py プロジェクト: cnr-ibba/pyUSIrest
    def setUp(self):
        self.auth = Auth(token=generate_token())

        with open(os.path.join(DATA_PATH, "root.json")) as handle:
            data = json.load(handle)

        self.mock_get.return_value = Mock()
        self.mock_get.return_value.json.return_value = data
        self.mock_get.return_value.status_code = 200

        # get a root object
        self.root = Root(self.auth)
コード例 #11
0
    def setUp(self):
        self.auth = Auth(token=generate_token())

        with open(os.path.join(DATA_PATH, "newSubmission.json")) as handle:
            data = json.load(handle)

        self.submission = Submission(self.auth, data=data)

        with open(os.path.join(DATA_PATH, "contents.json")) as handle:
            self.content = json.load(handle)

        # defining samples
        self.sample1 = {
            'alias': 'animal_1',
            'title': 'animal_title',
            'releaseDate': '2018-07-13',
            'taxonId': 9940,
            'taxon': 'Ovis aries',
            'attributes': {
                'material': [
                    {'value': 'organism',
                     'terms': [
                        {'url': 'http://purl.obolibrary.org/obo/OBI_0100026'}
                     ]}
                ],
                'project': [{'value': 'test'}]
            },
            'sampleRelationships': []}

        self.sample2 = {
            'alias': 'sample_1',
            'title': 'sample_title',
            'taxonId': 9940,
            'taxon': 'Ovis aries',
            'description': 'a description',
            'attributes': {
                'material': [
                    {'value': 'specimen from organism',
                     'terms': [
                        {'url': 'http://purl.obolibrary.org/obo/OBI_0001479'}
                     ]}
                ],
                'project': [{'value': 'test'}]
            },
            'sampleRelationships': [{
                'alias': 'animal_1',
                'relationshipNature': 'derived from'}]
            }
コード例 #12
0
    def test_get_durations(self):
        self.mock_get.return_value = Mock()
        self.mock_get.return_value.text = generate_token(
            now=self.now-3300)
        self.mock_get.return_value.status_code = 200

        # Call the service, which will send a request to the server.
        auth = Auth(user='******', password='******')

        # get duration
        duration = auth.get_duration()

        # get remaining seconds
        seconds = int(duration.total_seconds())

        self.assertAlmostEqual(seconds, 300, delta=10)
コード例 #13
0
ファイル: test_user.py プロジェクト: cnr-ibba/pyUSIrest
    def setUp(self):
        self.auth = Auth(token=generate_token())
        self.user = User(self.auth)

        self.data = {
            "userName": "******",
            "email": "*****@*****.**",
            "userReference": "usr-f1801430-51e1-4718-8fca-778887087bad",
            "_links": {
                "self": {
                    "href":
                    "https://explore.api.aai.ebi.ac.uk/users/usr-"
                    "f1801430-51e1-4718-8fca-778887087bad"
                }
            }
        }
コード例 #14
0
    def test_fill_managed(self, my_auth):
        """test fill_managed command"""

        # remove a managed team
        managed = ManagedTeam.objects.get(pk=2)
        managed.delete()

        # patch get_manager_auth value
        my_auth.return_value = Auth(
            token=generate_token(
                domains=[
                    'subs.test-team-1',
                    'subs.test-team-2',
                    'subs.test-team-3']
            )
        )

        # calling commands
        call_command('fill_managed')

        # get all managedteams object
        self.assertEqual(ManagedTeam.objects.count(), 3)
        self.assertTrue(my_auth.called)
コード例 #15
0
ファイル: test_client.py プロジェクト: cnr-ibba/pyUSIrest
 def test_with_auth_object(self):
     token = generate_token()
     auth = Auth(token=token)
     client = Client(auth)
     self.assertFalse(client.auth.is_expired())
コード例 #16
0
    def test_get_tocken(self):
        # Call the service, which will send a request to the server.
        auth = Auth(user='******', password='******')
        token = auth.token

        self.assertIsInstance(token, str)
コード例 #17
0
 def mocked_auth():
     token = generate_token(
         domains=['subs.test-team-1', 'subs.test-team-3'])
     return Auth(token=token)