Esempio n. 1
0
    def test_json(self):
        """Tests coverting a PurgeSourceFile message to and from JSON"""

        # Create a file
        source_file = storage_test_utils.create_file(file_type='SOURCE')
        # Create message
        message = create_purge_source_file_message(
            source_file_id=source_file.id, trigger_id=self.trigger.id)

        # Convert message to JSON and back, and then execute
        message_json_dict = message.to_json()
        new_message = PurgeSourceFile.from_json(message_json_dict)
        result = new_message.execute()

        self.assertTrue(result)
Esempio n. 2
0
    def test_successful(self, mock_create, mock_msg_mgr):
        """Tests purging a source file."""

        msg = PurgeSourceFile()
        mock_create.return_value = msg

        input_file = storage_test_utils.create_file(file_type='SOURCE')

        json_data = {'file_id': input_file.id}

        url = '/%s/files/purge-source/' % self.api
        response = self.client.generic('POST', url, json.dumps(json_data),
                                       'application/json')
        self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)

        # Check that create_batch_recipes message was created and sent
        mock_create.assert_called_once()
Esempio n. 3
0
    def test_successful_db_check(self, mock_create, mock_msg_mgr):
        """Tests purging a source file."""

        msg = PurgeSourceFile()
        mock_create.return_value = msg

        input_file = storage_test_utils.create_file(file_type='SOURCE')

        json_data = {
            'file_id': input_file.id
        }

        url = '/%s/files/purge-source/' % self.api
        response = self.client.generic('POST', url, json.dumps(json_data), 'application/json')
        self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)

        # Check that PurgeResults entry was made
        self.assertEqual(PurgeResults.objects.filter(source_file_id=input_file.id).count(), 1)