def test_extracts_region_from_context_if_no_regions_variable(self): self.os.environ.get.return_value = "" context = mock.Mock() for region in ("eu-west-1", "sp-moonbase-1"): context.invoked_function_arn = "arn:aws:lambda:" + region + ":..." result = chaos.get_regions(context) self.assertEqual(result, [region])
def test_extracts_region_from_context_if_no_regions_found_in_file(self): self.os.path.exists.return_value = True self.open.return_value.readlines.return_value = [] context = mock.Mock() context.invoked_function_arn = "arn:aws:lambda:eu-west-1:..." result = chaos.get_regions(context) self.assertEqual(result, ["eu-west-1"])
def test_reads_from_regions_txt_if_it_exists(self): self.os.path.exists.return_value = True f = self.open.return_value f.readlines.return_value = ["re-gion-1\n", "sp-moonbase-1\n"] result = chaos.get_regions(mock.Mock()) self.assertEqual(result, ["re-gion-1", "sp-moonbase-1"]) f.close.assert_called_once_with()
def test_extracts_region_from_context_if_no_regions_variable(self): self.os.environ.get.return_value = "" context = mock.Mock() for region in ("eu-west-1", "sp-moonbase-1"): context.invoked_function_arn = "arn:aws:lambda:" + region + ":..." result = chaos.get_regions(context) self.assertEqual(result, [region])
def test_ignores_blank_lines_and_surrounding_whitespace(self): self.os.path.exists.return_value = True self.open.return_value.readlines.return_value = [ "\n", " sp-moonbase-1\n", " \n", "re-gion-1 \n", "\n", ] result = chaos.get_regions(mock.Mock()) self.assertEqual(result, ["sp-moonbase-1", "re-gion-1"])
def test_ignores_whitespace_in_regions_variable(self): self.os.environ.get.return_value = "\n sp-moonbase-1\n, re-gion-1 " result = chaos.get_regions(mock.Mock()) self.assertEqual(result, ["sp-moonbase-1", "re-gion-1"])
def test_reads_from_comma_separated_regions_variable_if_set(self): self.os.environ.get.return_value = "re-gion-1,sp-moonbase-1" result = chaos.get_regions(mock.Mock()) self.assertEqual(result, ["re-gion-1", "sp-moonbase-1"])
def test_looks_for_a_regions_environment_variable(self): self.os.environ.get.return_value = "" context = mock.Mock() context.invoked_function_arn = "arn:aws:lambda:re-gion-1:..." chaos.get_regions(context) self.os.environ.get.assert_called_once_with("regions", "")
def test_looks_for_a_region_txt_file(self): self.os.path.exists.return_value = False context = mock.Mock() context.invoked_function_arn = "arn:aws:lambda:re-gion-1:..." chaos.get_regions(context) self.os.path.exists.assert_called_once_with("regions.txt")
def test_ignores_whitespace_in_regions_variable(self): self.os.environ.get.return_value = "\n sp-moonbase-1\n, re-gion-1 " result = chaos.get_regions(mock.Mock()) self.assertEqual(result, ["sp-moonbase-1", "re-gion-1"])
def test_reads_from_comma_separated_regions_variable_if_set(self): self.os.environ.get.return_value = "re-gion-1,sp-moonbase-1" result = chaos.get_regions(mock.Mock()) self.assertEqual(result, ["re-gion-1", "sp-moonbase-1"])
def test_looks_for_a_regions_environment_variable(self): self.os.environ.get.return_value = "" context = mock.Mock() context.invoked_function_arn = "arn:aws:lambda:re-gion-1:..." chaos.get_regions(context) self.os.environ.get.assert_called_once_with("regions", "")