def test_missing_schema_key(self): """ Tests for valid exception when the '000_schema.json' key is missing from a table's data """ test = {"test": {"00_schema.json": {}}} with self.assertRaisesRegexp( MalformedTableData, "000_schema.json is missing for this table: test"): validate_and_process(test)
def test_missing_schema_ids(self): """ Tests for valid exception when the keys attribute in the schema is length 0 """ test = {"test": {"000_schema.json": self.invalid_schema_missing_id}} with self.assertRaisesRegexp( MalformedTableData, "Keys attribute in schema is length 0 for table test, expecting at least one element" ): validate_and_process(test)
def test_missing_keys_field(self): """ Tests for valid exception when the keys attribute is missing from the schema """ test = { "test": { "000_schema.json": self.invalid_schema_missing_keys_field } } with self.assertRaisesRegexp( MalformedTableData, "Schema file for test does not contain table name or keys attribute" ): validate_and_process(test)
def test_delete_without_create(self): """ Tests that a valid exception is thrown when an delete is attempted on a record which does not exist """ test = { "test": { "000_schema.json": self.valid_dual_key_schema, "002_delete.json": self.valid_delete } } with self.assertRaisesRegexp( MalformedTableData, "Check record file 002_delete.json for table test as action is 'delete' but keys have not been seen before" ): validate_and_process(test)
def test_missing_dual_key(self): """ Tests that a valid exception is thrown when one key field from a dual key schema is missing """ test = { "test": { "000_schema.json": self.valid_dual_key_schema, "001_create.json": self.valid_create_single_key } } with self.assertRaisesRegexp( MalformedTableData, "One or more key fields are missing in record file 001_create.json for table test" ): validate_and_process(test)
def test_create_missing_id_single(self): """ Tests that a valid exception is thrown for a create missing an ID field """ test = { "test": { "000_schema.json": self.valid_single_key_schema, "001_create.json": self.create_missing_key } } with self.assertRaisesRegexp( MalformedTableData, "One or more key fields are missing in record file 001_create.json for table test" ): validate_and_process(test)
def test_action_attribute_missing(self): """ Tests that a valid exception is thrown when the action attribute is missing """ test = { "test": { "000_schema.json": self.valid_dual_key_schema, "001_action.json": self.record_missing_action } } with self.assertRaisesRegexp( MalformedTableData, "Record file 001_action.json for table test does not contain action and data attribute" ): validate_and_process(test)
def test_invalid_action(self): """ Tests that a valid exception is thrown for an invalid action """ test = { "test": { "000_schema.json": self.valid_dual_key_schema, "001_action.json": self.invalid_action } } with self.assertRaisesRegexp( MalformedTableData, "Action value is unknown in record file 001_action.json for table test" ): validate_and_process(test)
def test_missing_key(self): """ Tests that an delete with a missing key field fails """ test = { "test": { "000_schema.json": self.valid_dual_key_schema, "001_create.json": self.valid_create_dual_key_multi_field, "002_delete.json": self.delete_missing_key } } with self.assertRaisesRegexp( MalformedTableData, "One or more key fields are missing in record file 002_delete.json for table test" ): validate_and_process(test)
def test_create_duplicated_key_dual(self): """ Tests that a valid exception is thrown when attempting a create with a duplicated key """ test = { "test": { "000_schema.json": self.valid_dual_key_schema, "001_create.json": self.valid_create_dual_key, "002_create.json": self.valid_create_dual_key } } with self.assertRaisesRegexp( MalformedTableData, "Check record file 002_create.json for table test as action is 'create' but keys have been seen before" ): validate_and_process(test)
def test_valid_single_id_schema(self): """ Tests that a valid schema with a single ID field is created """ test = {"test": {"000_schema.json": self.valid_single_key_schema}} self.assertDictEqual(validate_and_process(test), dict_single_key_schema)
def test_update_single_entry(self): """ Tests that a single record is updated for a table with multiple records """ test = { "test": { "000_schema.json": self.valid_dual_key_schema, "001_create.json": self.valid_create_dual_key, "002_delete.json": self.valid_delete, "003_update.json": self.valid_update } } with self.assertRaisesRegexp( MalformedTableData, "Check record file 003_update.json for table test as action is update but record has previously been deleted" ): validate_and_process(test)
def test_delete(self): """ Tests a valid delete works """ test = { "test": { "000_schema.json": self.valid_dual_key_schema, "001_create.json": self.valid_create_dual_key_multi_field, "002_delete.json": self.valid_delete } } self.assertDictEqual(validate_and_process(test), dict_valid_delete)
def test_update_all_cols(self): """ Tests a valid update of all columns works """ test = { "test": { "000_schema.json": self.valid_dual_key_schema, "001_create.json": self.valid_create_dual_key_multi_field, "002_update.json": self.valid_update } } self.assertDictEqual(validate_and_process(test), dict_valid_update)
def test_valid_dual_key(self): """ Tests that a valid create record for a dual key schema works """ test = { "test": { "000_schema.json": self.valid_dual_key_schema, "001_create.json": self.valid_create_dual_key } } self.assertDictEqual(validate_and_process(test), dict_valid_create_dual_key)
def test_update_single_col(self): """ Test a valid update of a single column works """ test = { "test": { "000_schema.json": self.valid_dual_key_schema, "001_create.json": self.valid_create_dual_key_multi_field, "002_update.json": self.valid_update_single_col } } self.assertDictEqual(validate_and_process(test), dict_valid_update_single_col)