def test_get_tacc_username_api_problem(self, cassette): """Make sure we don't return the Atmosphere username when we have trouble connecting to the TAS API. It should fail. TODO: Figure out how to handle it gracefully. """ from jetstream.allocation import TASAPIDriver tas_driver = TASAPIDriver() tas_driver.clear_cache() self.assertDictEqual(tas_driver.username_map, {}) user = UserFactory.create(username='******') tacc_username = tas_driver.get_tacc_username(user) self.assertIsNone(tacc_username) self.assertDictEqual(tas_driver.username_map, {}) assert_cassette_playback_length(cassette, 1)
def test_get_tacc_username_api_problem(self, cassette): """Make sure we don't return the Atmosphere username when we have trouble connecting to the TAS API. It should fail. TODO: Figure out how to handle it gracefully. """ from jetstream.allocation import TASAPIDriver tas_driver = TASAPIDriver() tas_driver.clear_cache() self.assertDictEqual(tas_driver.username_map, {}) user = UserFactory.create(username='******') tacc_username = tas_driver.get_tacc_username(user) self.assertIsNone(tacc_username) self.assertDictEqual(tas_driver.username_map, {}) assert_cassette_playback_length(cassette, 1)
def validate_user(self, user): """ Validates an account based on the business logic assigned by jetstream. In this example: * Accounts are *ONLY* valid if they have 1+ 'jetstream' allocations. * All other allocations are ignored. """ tas_driver = TASAPIDriver() try: tacc_username = tas_driver.get_tacc_username(user) project_allocations = tas_driver.get_user_allocations( tacc_username) if not project_allocations: return False return True except TASAPIException: logger.exception("Could not validate user: %s" % user) return False