Ejemplo n.º 1
0
 def test_generate_data(self, mock_method):
     """Test that the generate_data method is called."""
     generator = OCIGenerator(self.six_hours_ago, self.now, self.currency,
                              self.attributes)
     for report_type in OCI_REPORT_TYPE_TO_COLS:
         generator.generate_data(report_type)
         assert mock_method is OCIGenerator.generate_data
         assert mock_method.called
Ejemplo n.º 2
0
 def test_tag_timestamp_date(self):
     """Test tag timestamp method with valid date returns a timestamp."""
     generator = OCIGenerator(self.two_hours_ago, self.now, self.currency)
     date_str_format = "%Y-%m-%dT%H:%M:%S.000Z"
     self.assertEqual(generator._tag_timestamp(self.now),
                      self.now.strftime(date_str_format))
     tag_date = datetime.strptime(generator._tag_timestamp(self.now),
                                  date_str_format)
     self.assertIsInstance(tag_date, datetime)
Ejemplo n.º 3
0
 def test_init_data_row(self):
     """Test the init data row method."""
     generator = OCIGenerator(self.six_hours_ago, self.now, self.currency)
     test_row = {}
     for report_type in OCI_REPORT_TYPE_TO_COLS:
         kwargs = {"report_type": report_type}
         test_row.update(
             generator._init_data_row(self.six_hours_ago, self.now,
                                      **kwargs))
         self.assertIsInstance(test_row, dict)
Ejemplo n.º 4
0
 def test_generate_hourly_data(self):
     """Test that the _generate_hourly_data method is called."""
     kwargs = {"report_type": "oci_cost_type"}
     with patch.object(OCIGenerator,
                       "_generate_hourly_data",
                       return_value=None) as mock_method:
         generator = OCIGenerator(self.six_hours_ago, self.now,
                                  self.currency, self.attributes)
         generator._generate_hourly_data(**kwargs)
     mock_method.assert_called_with(**kwargs)
Ejemplo n.º 5
0
 def test_add_common_usage_info(self):
     """Test that add_common_usage_info updates usage timestamps."""
     generator = OCIGenerator(self.six_hours_ago, self.now, self.currency)
     test_row_in = {}
     for report_type in OCI_REPORT_TYPE_TO_COLS:
         kwargs = {"report_type": report_type}
         test_row_in.update(
             generator._init_data_row(self.six_hours_ago, self.now,
                                      **kwargs))
         test_row_out = generator._add_common_usage_info(
             test_row_in, self.six_hours_ago, self.now)
         self.assertIn("lineItem/intervalUsageStart", test_row_out)
         self.assertIn("lineItem/intervalUsageEnd", test_row_out)
Ejemplo n.º 6
0
 def test_init_data_row_start_none(self):
     """Test the init data row method none start date."""
     generator = OCIGenerator(self.six_hours_ago, self.now, self.currency)
     with self.assertRaises(ValueError):
         generator._init_data_row(None, self.now)
Ejemplo n.º 7
0
 def test_tag_timestamp_invalid_date(self):
     """Test tag timestamp method with invalid date returns an empty."""
     generator = OCIGenerator(self.six_hours_ago, self.now, self.currency)
     tag_date = generator._tag_timestamp("invalid date")
     self.assertIsInstance(tag_date, str)
     self.assertEqual(tag_date, "")
Ejemplo n.º 8
0
 def test_tag_timestamp(self):
     """Test tag timestamp method returns a string."""
     generator = OCIGenerator(self.six_hours_ago, self.now, self.currency)
     tag_date = generator._tag_timestamp(self.now)
     self.assertIsInstance(tag_date, str)
Ejemplo n.º 9
0
 def test_timestamp_valid(self):
     """Test timestamp method returns a date string."""
     generator = OCIGenerator(self.six_hours_ago, self.now, self.currency)
     tag_date = generator.timestamp(self.now)
     self.assertIsInstance(tag_date, str)
     self.assertEqual(tag_date, self.now.strftime("%Y-%m-%dT%H:%MZ"))
Ejemplo n.º 10
0
 def test_timestamp_invalid(self):
     """Test timestamp method fails with an invalid date."""
     with self.assertRaises(ValueError):
         OCIGenerator.timestamp("invalid")
Ejemplo n.º 11
0
 def test_timestamp_none(self):
     """Test the timestamp method fails with none."""
     with self.assertRaises(ValueError):
         OCIGenerator.timestamp(None)
Ejemplo n.º 12
0
 def test_init_data_row_end_invalid(self):
     """Test the init data row method invalid end date."""
     generator = OCIGenerator(self.six_hours_ago, self.now, self.currency)
     with self.assertRaises(ValueError):
         generator._init_data_row(self.six_hours_ago, "invalid")