@@ -23,7 +23,12 @@ def test_init(self):
2323 self .assertEqual (self .config_dict ['experiments' ], self .project_config .experiments )
2424 self .assertEqual (self .config_dict ['events' ], self .project_config .events )
2525 expected_group_id_map = {
26- '19228' : copy .deepcopy (self .config_dict ['groups' ][0 ])
26+ '19228' : entities .Group (
27+ self .config_dict ['groups' ][0 ]['id' ],
28+ self .config_dict ['groups' ][0 ]['policy' ],
29+ self .config_dict ['groups' ][0 ]['experiments' ],
30+ self .config_dict ['groups' ][0 ]['trafficAllocation' ]
31+ )
2732 }
2833 expected_experiment_key_map = {
2934 'test_experiment' : entities .Experiment (
@@ -316,18 +321,20 @@ def test_get_attribute__invalid_key(self):
316321
317322 self .assertIsNone (self .project_config .get_attribute ('invalid_key' ))
318323
319- def test_get_traffic_allocation__valid_key (self ):
320- """ Test that trafficAllocation is retrieved correctly for valid group ID. """
324+ def test_get_group__valid_id (self ):
325+ """ Test that group is retrieved correctly for valid group ID. """
326+
327+ self .assertEqual (entities .Group (self .config_dict ['groups' ][0 ]['id' ],
328+ self .config_dict ['groups' ][0 ]['policy' ],
329+ self .config_dict ['groups' ][0 ]['experiments' ],
330+ self .config_dict ['groups' ][0 ]['trafficAllocation' ]),
331+ self .project_config .get_group ('19228' ))
321332
322- self .assertEqual (self .config_dict ['groups' ][0 ]['trafficAllocation' ],
323- self .project_config .get_traffic_allocation (self .project_config .group_id_map ,
324- '19228' ))
325333
326- def test_get_traffic_allocation__invalid_key (self ):
334+ def test_get_group__invalid_id (self ):
327335 """ Test that None is returned when provided group ID is invalid. """
328336
329- self .assertIsNone (self .project_config .get_traffic_allocation (self .project_config .group_id_map ,
330- 'invalid_key' ))
337+ self .assertIsNone (self .project_config .get_group ('42' ))
331338
332339
333340class ConfigTestV2 (base .BaseTestV2 ):
@@ -446,6 +453,14 @@ def test_get_attribute__invalid_key(self):
446453
447454 mock_logging .assert_called_once_with (enums .LogLevels .ERROR , 'Attribute "invalid_key" is not in datafile.' )
448455
456+ def test_get_group__invalid_id (self ):
457+ """ Test that message is logged when provided group ID is invalid. """
458+
459+ with mock .patch ('optimizely.logger.SimpleLogger.log' ) as mock_logging :
460+ self .project_config .get_group ('42' )
461+
462+ mock_logging .assert_called_once_with (enums .LogLevels .ERROR , 'Group ID "42" is not in datafile.' )
463+
449464
450465class ConfigExceptionTest (base .BaseTestV1 ):
451466
@@ -503,3 +518,10 @@ def test_get_attribute__invalid_key(self):
503518 self .assertRaisesRegexp (exceptions .InvalidAttributeException ,
504519 enums .Errors .INVALID_ATTRIBUTE_ERROR ,
505520 self .project_config .get_attribute , 'invalid_key' )
521+
522+ def test_get_group__invalid_id (self ):
523+ """ Test that exception is raised when provided group ID is invalid. """
524+
525+ self .assertRaisesRegexp (exceptions .InvalidGroupException ,
526+ enums .Errors .INVALID_GROUP_ID_ERROR ,
527+ self .project_config .get_group , '42' )
0 commit comments