from unittest.mock import Mock
from app.master.atom import Atom
from app.master.job_config import JobConfig

from app.master.subjob import Subjob
from app.project_type.project_type import ProjectType
from test.framework.base_unit_test_case import BaseUnitTestCase


class TestSubjob(BaseUnitTestCase):

    def test_api_representation_matches_expected(self):
        job_config_command = 'fake command'
        subjob = Subjob(
            build_id=12,
            subjob_id=34,
            project_type=Mock(spec_set=ProjectType),
            job_config=Mock(spec=JobConfig, command=job_config_command),
            atoms=[
                Atom('BREAKFAST', 'pancakes', expected_time=23.4, actual_time=56.7),
                Atom('BREAKFAST', 'cereal', expected_time=89.0, actual_time=24.6),
            ],
        )

        actual_api_repr = subjob.api_representation()

        expected_api_repr = {
            'id': 34,
            'command': job_config_command,
            'atoms': [
                {'id': 0, 'atom': 'export BREAKFAST="pancakes";', 'expected_time': 23.4, 'actual_time': 56.7},
                {'id': 1, 'atom': 'export BREAKFAST="cereal";', 'expected_time': 89.0, 'actual_time': 24.6},
            ]
        }
        self.assertEqual(actual_api_repr, expected_api_repr, 'Actual api representation should match expected.')

@@ -193,16 +193,91 @@
 ectType%0A
+from app.util.process_utils import get_environment_variable_setter_command%0A
 from tes
@@ -1081,33 +1081,107 @@
    %7B
-'id': 0, 'atom': 'export 
+%0A                    'id': 0,%0A                    'atom': get_environment_variable_setter_command('
 BREA
@@ -1189,18 +1189,20 @@
 FAST
-=%22
+', '
 pancakes
 %22;',
@@ -1197,20 +1197,39 @@
 pancakes
-%22;',
+'),%0A                   
  'expect
@@ -1243,16 +1243,36 @@
 ': 23.4,
+%0A                   
  'actual
@@ -1283,16 +1283,34 @@
 e': 56.7
+,%0A                
 %7D,%0A     
@@ -1325,33 +1325,107 @@
    %7B
-'id': 1, 'atom': 'export 
+%0A                    'id': 1,%0A                    'atom': get_environment_variable_setter_command('
 BREA
@@ -1433,20 +1433,41 @@
 FAST
-=%22
+', '
 cereal
-%22;',
+'),%0A                   
  'ex
@@ -1485,16 +1485,36 @@
 ': 89.0,
+%0A                   
  'actual
@@ -1525,16 +1525,34 @@
 e': 24.6
+,%0A                
 %7D,%0A     

Make test_subjob cross platform