Skip to content

Commit

Permalink
Merge pull request #10 from rohitverma007/main
Browse files Browse the repository at this point in the history
Adding action enum and related tests

Fix #9
  • Loading branch information
MatteoCampinoti94 authored Oct 17, 2023
2 parents 44e248f + 3fbb2e8 commit 574eb30
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
12 changes: 9 additions & 3 deletions acacore/models/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Imports
# -----------------------------------------------------------------------------
import re
from enum import Enum
from pathlib import Path
from typing import Optional
from typing import Tuple
Expand All @@ -17,11 +18,16 @@
from .base import ACABase
from .identification import Identification


class Action(Enum):
CONVERT = 'Convertool: To convert.'
REPLACE = 'Convertool: Replace with template. File is not preservable.'
MANUAL = 'Manual: File should be converted manually. [info about the manual conversion from reference_files].'
RENAME = 'Renamer: File has extension mismatch. Should be renamed'

# -----------------------------------------------------------------------------
# Model
# -----------------------------------------------------------------------------


class File(ACABase):
"""File data model."""

Expand All @@ -34,7 +40,7 @@ class File(ACABase):
file_size_in_bytes: int
signature: Optional[str]
warning: Optional[str] = None
action: Optional[str] = None
action: Optional[Action] = None

def identify(self, sf: Siegfried) -> SiegfriedFile:
"""Identify the file using `siegfried`.
Expand Down
35 changes: 35 additions & 0 deletions acacore/tests/file_action_enum_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import unittest
from uuid import uuid4
from acacore.models.file import Action, File


class TestFileActionEnum(unittest.TestCase):
def setUp(self):
self.file = File(id=1, uuid=uuid4(), checksum='abc123', puid='fmt/18', relative_path='test.txt', is_binary=False, file_size_in_bytes=1024, signature='test')

def test_action_enum_values(self):
self.assertEqual(Action.CONVERT.value, 'Convertool: To convert.')
self.assertEqual(Action.REPLACE.value, 'Convertool: Replace with template. File is not preservable.')
self.assertEqual(Action.MANUAL.value, 'Manual: File should be converted manually. [info about the manual conversion from reference_files].')
self.assertEqual(Action.RENAME.value, 'Renamer: File has extension mismatch. Should be renamed')

def test_file_action(self):
self.file.action = Action.CONVERT
self.assertEqual(self.file.action, Action.CONVERT)
self.assertEqual(self.file.action.value, 'Convertool: To convert.')

self.file.action = Action.REPLACE
self.assertEqual(self.file.action, Action.REPLACE)
self.assertEqual(self.file.action.value, 'Convertool: Replace with template. File is not preservable.')

self.file.action = Action.MANUAL
self.assertEqual(self.file.action, Action.MANUAL)
self.assertEqual(self.file.action.value, 'Manual: File should be converted manually. [info about the manual conversion from reference_files].')

self.file.action = Action.RENAME
self.assertEqual(self.file.action, Action.RENAME)
self.assertEqual(self.file.action.value, 'Renamer: File has extension mismatch. Should be renamed')


if __name__ == '__main__':
unittest.main()

0 comments on commit 574eb30

Please sign in to comment.