예제 #1
0
    def _setup_random_status(self):
        """Set up a randomized status for testing.

        This is being done in a separate function instead of in setUp() to
        facilitate testing the case where there is no status in the DB.
        """
        self.test_status = {
            'provider_id': self.provider_id,
            'status': random.choice(list(ProviderStatusCode)),
            'last_message': self.FAKE.word(),
            'retries': random.randint(0, 10),
        }

        with ProviderStatusAccessor(self.aws_test_provider_uuid) as accessor:
            status = accessor.add(**self.test_status)
            status.save()
            self.time_stamp = status.timestamp
예제 #2
0
    def _setup_random_status(self):
        """Set up a randomized status for testing.

        This is being done in a separate function instead of in setUp() to
        facilitate testing the case where there is no status in the DB.
        """
        self.test_status = {
            "provider_id": self.provider_uuid,
            "status": random.choice(list(ProviderStatusCode)),
            "last_message": self.FAKE.word(),
            "retries": random.randint(0, 10),
            "timestamp": self.date_accessor.today_with_timezone("UTC"),
        }

        with ProviderStatusAccessor(self.aws_provider_uuid) as accessor:
            status = accessor.add(**self.test_status)
            status.save()
            self.time_stamp = status.timestamp
예제 #3
0
 def test_get_provider_uuid(self):
     """Test get_provider_uuid()."""
     self._setup_random_status()
     with ProviderStatusAccessor(self.aws_test_provider_uuid) as accessor:
         output = accessor.get_provider_uuid()
         self.assertEqual(output, self.aws_test_provider_uuid)
예제 #4
0
 def test_init_wo_provider(self):
     """Test __init__() when a provider is not in the DB."""
     with self.assertRaises(MasuProviderError):
         ProviderStatusAccessor(str(uuid.uuid4()))
예제 #5
0
 def test_init(self):
     """Test __init__() when a status is in the DB."""
     self._setup_random_status()
     with ProviderStatusAccessor(self.aws_test_provider_uuid) as accessor:
         self.assertIsNotNone(accessor._table)
         self.assertIsNotNone(accessor._obj)
 def test_get_last_message(self):
     """Test get_last_message()."""
     self._setup_random_status()
     with ProviderStatusAccessor(self.aws_provider_uuid) as accessor:
         output = accessor.get_last_message()
         self.assertEqual(output, self.test_status.get('last_message'))