Ejemplo n.º 1
0
    def test_api_get_blackboard_type(self):
        self.api = BlackboardAPI(mock_data_generator.settings(),
                                 MongoClient=mock_data_generator.mock_client)

        # Test getting date-based
        self.assertEqual(self.api.get_blackboard_type('ARTICLE'),
                         CounterManager.counter_type_date_based)
        self.assertEqual(
            self.api.get_blackboard_type('ARTICLE', date_based=True),
            CounterManager.counter_type_date_based)
        with self.assertRaises(ValueError):
            self.api.get_blackboard_type('ARTICLE', date_based=False)

        # Test getting standard
        self.assertEqual(self.api.get_blackboard_type('FEED'),
                         CounterManager.counter_type_standard)
        self.assertEqual(
            self.api.get_blackboard_type('FEED', date_based=False),
            CounterManager.counter_type_standard)
        with self.assertRaises(ValueError):
            self.api.get_blackboard_type('FEED', date_based=True)

        # Test getting a different date-based
        self.assertEqual(self.api.get_blackboard_type('ARTICLE2'),
                         CounterManager.counter_type_date_based)

        # Test getting a non-existing blackboard
        self.assertEqual(self.api.get_blackboard_type('MISSING'), None)
        self.assertEqual(
            self.api.get_blackboard_type('MISSING', date_based=True),
            CounterManager.counter_type_date_based)
        self.assertEqual(
            self.api.get_blackboard_type('MISSING', date_based=False),
            CounterManager.counter_type_standard)
Ejemplo n.º 2
0
    def test_api_drop_blackboard(self):
        # Non-admin user
        self.api = BlackboardAPI(mock_data_generator.settings(), MongoClient=mock_data_generator.mock_client)

        # Check they exist before attempting drop
        blackboards = [('ARTICLE', True), ('ARTICLE2', True), ('FEED', True), ('article', False)]
        for bb in blackboards:
            self.assertEqual(self.api.blackboard_exists(bb[0]), bb[1])

        with self.assertRaises(ValueError): self.api.drop_blackboard('ARTICLE_TAGS')
        with self.assertRaises(ValueError): self.api.drop_blackboard('article_counter')
        with self.assertRaises(PermissionError): self.api.drop_blackboard('ARTICLE')
        with self.assertRaises(PermissionError): self.api.drop_blackboard('article')

        # Check they still exist after failed drop
        for bb in blackboards:
            self.assertEqual(self.api.blackboard_exists(bb[0]), bb[1])

        # Test admin drop
        self.api = BlackboardAPI(mock_data_generator.admin_settings(), MongoClient=mock_data_generator.mock_client)
        
        self.api.drop_blackboard('ARTICLE')
        self.assertEqual(self.api.blackboard_exists(blackboards[0][0]), not blackboards[0][1])
        for bb in blackboards[1:]:
            self.assertEqual(self.api.blackboard_exists(bb[0]), bb[1])

        self.api.drop_blackboard('ARTICLE2')
        self.assertEqual(self.api.blackboard_exists('ARTICLE2'), False)

        self.api.drop_blackboard('FEED')
        self.assertEqual(self.api.blackboard_exists('FEED'), False)
Ejemplo n.º 3
0
    def test_api_load_blackboard(self):
        self.api = BlackboardAPI(mock_data_generator.settings(),
                                 MongoClient=mock_data_generator.mock_client)

        # Correctly called returns correct type
        self.assertIsInstance(self.api.load_blackboard('ARTICLE'),
                              DateBasedBlackboard)
        self.assertIsInstance(
            self.api.load_blackboard('ARTICLE', date_based=True),
            DateBasedBlackboard)
        self.assertIsInstance(self.api.load_blackboard('FEED'), Blackboard)
        self.assertIsInstance(
            self.api.load_blackboard('FEED', date_based=False), Blackboard)

        # Incorrectly called raises error
        with self.assertRaises(ValueError):
            self.api.load_blackboard('ARTICLE_TAGS')
        with self.assertRaises(ValueError):
            self.api.load_blackboard('article_counter')
        with self.assertRaises(ValueError):
            self.api.load_blackboard('FEED', date_based=True)
        with self.assertRaises(ValueError):
            self.api.load_blackboard('ARTICLE', date_based=False)
        with self.assertRaises(ValueError):
            self.api.load_blackboard('ARTICLE2', date_based=False)
Ejemplo n.º 4
0
    def test_api_load_blackboard(self):
        self.api = BlackboardAPI(mock_data_generator.settings(), MongoClient=mock_data_generator.mock_client)

        # Correctly called returns correct type
        self.assertIsInstance(self.api.load_blackboard('ARTICLE'), DateBasedBlackboard)
        self.assertIsInstance(self.api.load_blackboard('ARTICLE', date_based=True), DateBasedBlackboard)
        self.assertIsInstance(self.api.load_blackboard('FEED'), Blackboard)
        self.assertIsInstance(self.api.load_blackboard('FEED', date_based=False), Blackboard)

        # Incorrectly called raises error
        with self.assertRaises(ValueError): self.api.load_blackboard('ARTICLE_TAGS')
        with self.assertRaises(ValueError): self.api.load_blackboard('article_counter')
        with self.assertRaises(ValueError): self.api.load_blackboard('FEED', date_based=True)
        with self.assertRaises(ValueError): self.api.load_blackboard('ARTICLE', date_based=False)
        with self.assertRaises(ValueError): self.api.load_blackboard('ARTICLE2', date_based=False)
Ejemplo n.º 5
0
    def test_api_get_blackboard_type(self):
        self.api = BlackboardAPI(mock_data_generator.settings(), MongoClient=mock_data_generator.mock_client)
        
        # Test getting date-based
        self.assertEqual(self.api.get_blackboard_type('ARTICLE'), CounterManager.counter_type_date_based)
        self.assertEqual(self.api.get_blackboard_type('ARTICLE', date_based=True), CounterManager.counter_type_date_based)
        with self.assertRaises(ValueError): self.api.get_blackboard_type('ARTICLE', date_based=False)

        # Test getting standard
        self.assertEqual(self.api.get_blackboard_type('FEED'), CounterManager.counter_type_standard)
        self.assertEqual(self.api.get_blackboard_type('FEED', date_based=False), CounterManager.counter_type_standard)
        with self.assertRaises(ValueError): self.api.get_blackboard_type('FEED', date_based=True)
        
        # Test getting a different date-based
        self.assertEqual(self.api.get_blackboard_type('ARTICLE2'), CounterManager.counter_type_date_based)

        # Test getting a non-existing blackboard
        self.assertEqual(self.api.get_blackboard_type('MISSING'), None)
        self.assertEqual(self.api.get_blackboard_type('MISSING', date_based=True), CounterManager.counter_type_date_based)
        self.assertEqual(self.api.get_blackboard_type('MISSING', date_based=False), CounterManager.counter_type_standard)
Ejemplo n.º 6
0
    def test_api_drop_blackboard(self):
        # Non-admin user
        self.api = BlackboardAPI(mock_data_generator.settings(),
                                 MongoClient=mock_data_generator.mock_client)

        # Check they exist before attempting drop
        blackboards = [('ARTICLE', True), ('ARTICLE2', True), ('FEED', True),
                       ('article', False)]
        for bb in blackboards:
            self.assertEqual(self.api.blackboard_exists(bb[0]), bb[1])

        with self.assertRaises(ValueError):
            self.api.drop_blackboard('ARTICLE_TAGS')
        with self.assertRaises(ValueError):
            self.api.drop_blackboard('article_counter')
        with self.assertRaises(PermissionError):
            self.api.drop_blackboard('ARTICLE')
        with self.assertRaises(PermissionError):
            self.api.drop_blackboard('article')

        # Check they still exist after failed drop
        for bb in blackboards:
            self.assertEqual(self.api.blackboard_exists(bb[0]), bb[1])

        # Test admin drop
        self.api = BlackboardAPI(mock_data_generator.admin_settings(),
                                 MongoClient=mock_data_generator.mock_client)

        self.api.drop_blackboard('ARTICLE')
        self.assertEqual(self.api.blackboard_exists(blackboards[0][0]),
                         not blackboards[0][1])
        for bb in blackboards[1:]:
            self.assertEqual(self.api.blackboard_exists(bb[0]), bb[1])

        self.api.drop_blackboard('ARTICLE2')
        self.assertEqual(self.api.blackboard_exists('ARTICLE2'), False)

        self.api.drop_blackboard('FEED')
        self.assertEqual(self.api.blackboard_exists('FEED'), False)
Ejemplo n.º 7
0
 def test_api_get_blackboard_names(self):
     self.api = BlackboardAPI(mock_data_generator.settings(),
                              MongoClient=mock_data_generator.mock_client)
     self.assertSetEqual(set(self.api.get_blackboard_names()),
                         set(['FEED', 'ARTICLE', 'ARTICLE2']))
Ejemplo n.º 8
0
 def test_api_get_blackboard_names(self):
     self.api = BlackboardAPI(mock_data_generator.settings(), MongoClient=mock_data_generator.mock_client)
     self.assertSetEqual(set(self.api.get_blackboard_names()), set(['FEED', 'ARTICLE', 'ARTICLE2']))
Ejemplo n.º 9
0
 def setUp(self):
     self.api = BlackboardAPI(mock_data_generator.settings(),
                              MongoClient=mock_data_generator.mock_client)
     self.bb = self.api.load_blackboard('ARTICLE')
Ejemplo n.º 10
0
 def setUp(self):
     self.api = BlackboardAPI(mock_data_generator.settings(), MongoClient=mock_data_generator.mock_client)
     self.bb = self.api.load_blackboard('ARTICLE')