def test_order_frameworks_for_reuse_one(self): """Test that the function returns a list of 1 when given a single suitable framework.""" t09 = '2009-03-03T01:01:01.000000Z' t07 = '2007-03-03T01:01:01.000000Z' t12 = '2012-03-03T01:01:01.000000Z' fake_frameworks = [ { 'allowDeclarationReuse': False, 'applicationsCloseAtUTC': t12, 'extraneousField': 'foo' }, { 'allowDeclarationReuse': False, 'applicationsCloseAtUTC': t09, 'extraneousField': 'foo' }, { 'allowDeclarationReuse': True, 'applicationsCloseAtUTC': t07, 'extraneousField': 'foo' }, ] ordered = order_frameworks_for_reuse(fake_frameworks) assert ordered == [{ 'allowDeclarationReuse': True, 'applicationsCloseAtUTC': t07, 'extraneousField': 'foo' }]
def test_order_frameworks_for_reuse_unordered(self): """Test crazy order passed in is ordered correctly.""" t09 = '2009-03-03T01:01:01.000000Z' t07 = '2007-03-03T01:01:01.000000Z' t11 = '2011-03-03T01:01:01.000000Z' t12 = '2012-03-03T01:01:01.000000Z' t13 = '2013-03-03T01:01:01.000000Z' t14 = '2014-03-03T01:01:01.000000Z' fake_frameworks = [ {'allowDeclarationReuse': True, 'applicationsCloseAtUTC': t07, 'extraneousField': 'foo'}, {'allowDeclarationReuse': True, 'applicationsCloseAtUTC': t13, 'extraneousField': 'foo'}, {'allowDeclarationReuse': True, 'applicationsCloseAtUTC': t09, 'extraneousField': 'foo'}, {'allowDeclarationReuse': True, 'applicationsCloseAtUTC': t14, 'extraneousField': 'foo'}, {'allowDeclarationReuse': True, 'applicationsCloseAtUTC': t12, 'extraneousField': 'foo'}, {'allowDeclarationReuse': True, 'applicationsCloseAtUTC': t11, 'extraneousField': 'foo'}, ] ordered = order_frameworks_for_reuse(fake_frameworks) expected = [ {'allowDeclarationReuse': True, 'applicationsCloseAtUTC': t14, 'extraneousField': 'foo'}, {'allowDeclarationReuse': True, 'applicationsCloseAtUTC': t13, 'extraneousField': 'foo'}, {'allowDeclarationReuse': True, 'applicationsCloseAtUTC': t12, 'extraneousField': 'foo'}, {'allowDeclarationReuse': True, 'applicationsCloseAtUTC': t11, 'extraneousField': 'foo'}, {'allowDeclarationReuse': True, 'applicationsCloseAtUTC': t09, 'extraneousField': 'foo'}, {'allowDeclarationReuse': True, 'applicationsCloseAtUTC': t07, 'extraneousField': 'foo'} ] assert ordered == expected
def test_order_frameworks_for_reuse_none(self): """Test no suitable frameworks returns an empty list.""" t09 = '2009-03-03T01:01:01.000000Z' t07 = '2007-03-03T01:01:01.000000Z' t12 = '2012-03-03T01:01:01.000000Z' fake_frameworks = [ { 'allowDeclarationReuse': False, 'applicationsCloseAtUTC': t12, 'extraneousField': 'foo' }, { 'allowDeclarationReuse': False, 'applicationsCloseAtUTC': t09, 'extraneousField': 'foo' }, { 'allowDeclarationReuse': False, 'applicationsCloseAtUTC': t07, 'extraneousField': 'foo' }, ] ordered = order_frameworks_for_reuse(fake_frameworks) assert ordered == []
def test_order_frameworks_for_reuse(self): """Test happy path. Should return 2 frameworks, closest date first.""" t09 = '2009-03-03T01:01:01.000000Z' t07 = '2007-03-03T01:01:01.000000Z' t12 = '2012-03-03T01:01:01.000000Z' fake_frameworks = [ {'allowDeclarationReuse': False, 'applicationsCloseAtUTC': t09, 'extraneousField': 'foo'}, {'allowDeclarationReuse': True, 'applicationsCloseAtUTC': t12, 'extraneousField': 'foo'}, {'allowDeclarationReuse': True, 'applicationsCloseAtUTC': t07, 'extraneousField': 'foo'}, ] ordered = order_frameworks_for_reuse(fake_frameworks) assert len(ordered) == 2, "order_frameworks_for_reuse should only filter out inappropriate frameworks." assert ordered == [ {'allowDeclarationReuse': True, 'applicationsCloseAtUTC': t12, 'extraneousField': 'foo'}, {'allowDeclarationReuse': True, 'applicationsCloseAtUTC': t07, 'extraneousField': 'foo'} ], "order_frameworks_for_reuse should return appropriate frameworks."