예제 #1
0
 def __create_503_response():
     return HttpMockSequence([
         ({'status': '200'},
          content('tests/json_samples/bigquery_v2_test_schema.json')),
         ({'status': '503'},
          content('tests/json_samples/bigquery_503_error.json'))
     ])
예제 #2
0
 def __create_random_table_no_results_responses():
     return HttpMockSequence([
         ({'status': '200'},
          content('tests/json_samples/bigquery_v2_test_schema.json')),
         ({'status': '200'},
          content(
              'tests/json_samples/random_table/big_query_for_random_table_no_results.json'))
     ])
예제 #3
0
 def __create_table_responses_with_only_one_response_for_get_table():
     return HttpMockSequence([(
         {'status': '200'},
         content('tests/json_samples/bigquery_v2_test_schema.json')),
         ({'status': '200'},
          content(
              'tests/json_samples/random_table/biquery_query_for_random_table.json'))
     ])
예제 #4
0
 def __create_dataset_not_found_during_tables_list_responses():
     return HttpMockSequence([
         ({'status': '200'},
          content('tests/json_samples/bigquery_v2_test_schema.json')),
         ({'status': '200'},
          content(
              'tests/json_samples/bigquery_table_list_404_dataset_not_exist.json'))
     ])
예제 #5
0
 def __create_get_table_400_responses():
     return HttpMockSequence([
         ({'status': '200'},
          content('tests/json_samples/bigquery_v2_test_schema.json')),
         ({'status': '400'},
          content(
              'tests/json_samples/table_get/bigquery_view_get_400_read_partition.json'))
     ])
예제 #6
0
 def __create_access_denied_response():
     return HttpMockSequence([
         ({
             'status': '200'
         }, content('tests/json_samples/bigquery_v2_test_schema.json')),
         ({
             'status': '403'
         }, content('tests/json_samples/bigquery_access_denied.json')),
     ])
예제 #7
0
 def __create_dataset_create_already_exist_responses():
     return HttpMockSequence([
         ({
             'status': '200'
         }, content('tests/json_samples/bigquery_v2_test_schema.json')),
         ({
             'status': '409'
         }, content('tests/json_samples/bigquery_dataset_create.json')),
     ])
예제 #8
0
 def __create_dataset_responses_with_only_one_response_for_get_dataset():
     return HttpMockSequence([
         ({
             'status': '200'
         }, content('tests/json_samples/bigquery_v2_test_schema.json')),
         ({
             'status': '200'
         }, content('tests/json_samples/bigquery_dataset_create.json')),
     ])
예제 #9
0
 def __create_tables_list_responses():
     return HttpMockSequence([
         ({'status': '200'},
          content('tests/json_samples/bigquery_v2_test_schema.json')),
         ({'status': '200'},
          content('tests/json_samples/bigquery_table_list_page_1.json')),
         ({'status': '200'},
          content('tests/json_samples/bigquery_table_list_page_last.json'))
     ])
예제 #10
0
 def __execute_long_query_responses():
     return HttpMockSequence([
         ({'status': '200'}, content(
             'tests/json_samples/bigquery_v2_test_schema.json')),
         ({'status': '200'},
          content('tests/json_samples/big_query/query_response.json')),
         ({'status': '200'}, content(
             'tests/json_samples/big_query/get_query_results_job_not_completed.json')),
         ({'status': '200'}, content(
             'tests/json_samples/big_query/get_query_results_job_completed.json'))
     ])
예제 #11
0
 def __create_table_partititions_list_responses_table_404_not_found():
     return HttpMockSequence([
         ({
             'status': '200'
         }, content('tests/json_samples/bigquery_v2_test_schema.json')),
         ({
             'status': '404'
         },
          content(
              'tests/json_samples/bigquery_partition_query_404_table_not_exist.json'
          ))
     ])
    def test_should_create_datastore_backup_entity(self, _create_http, _):
        # given
        _create_http.return_value = HttpMockSequence([
            ({
                'status': '200'
            }, content('tests/json_samples/bigquery_v2_test_schema.json')),
            ({
                'status': '200'
            },
             content('tests/json_samples/table_get/'
                     'bigquery_partitioned_table_get.json'))
        ])

        table_entity = Table(project_id="source_project_id",
                             dataset_id="source_dataset_id",
                             table_id="source_table_id",
                             partition_id="123")
        table_entity.put()

        source_bq_table = TableReference.from_table_entity(
            table_entity).create_big_query_table()
        destination_bq_table = BigQueryTable("target_project_id",
                                             "target_dataset_id",
                                             "target_table_id")
        data = {
            "sourceBqTable": source_bq_table,
            "targetBqTable": destination_bq_table
        }
        payload = json.dumps({
            "data": data,
            "jobJson": JobResultExample.DONE
        },
                             cls=RequestEncoder)
        copy_job_result = CopyJobResult(json.loads(payload).get('jobJson'))

        # when
        response = self.under_test.post(
            '/callback/backup-created/project/dataset/table', params=payload)
        backup = table_entity.last_backup

        # then
        self.assertEqual(response.status_int, 200)
        self.assertEqual(backup.dataset_id, "target_dataset_id")
        self.assertEqual(backup.table_id, "target_table_id")
        self.assertTrue(isinstance(backup.created, datetime))
        self.assertEqual(backup.created, copy_job_result.end_time)

        self.assertTrue(isinstance(backup.last_modified, datetime))
        self.assertEqual(backup.last_modified, copy_job_result.start_time)
    def test_should_not_create_backups_entity_if_backup_table_doesnt_exist(
            self, _create_http, error_reporting, _):
        # given
        _create_http.return_value = HttpMockSequence([
            ({
                'status': '200'
            }, content('tests/json_samples/bigquery_v2_test_schema.json')),
            (
                {
                    'status': '404'
                },  # Table not found
                content('tests/json_samples/table_get/'
                        'bigquery_partitioned_table_get.json'))
        ])

        table_entity = Table(project_id="source_project_id",
                             dataset_id="source_dataset_id",
                             table_id="source_table_id",
                             partition_id="123")
        table_entity.put()

        source_bq_table = TableReference.from_table_entity(
            table_entity).create_big_query_table()
        destination_bq_table = BigQueryTable("target_project_id",
                                             "target_dataset_id",
                                             "target_table_id")
        data = {
            "sourceBqTable": source_bq_table,
            "targetBqTable": destination_bq_table
        }
        payload = json.dumps({
            "data": data,
            "jobJson": JobResultExample.DONE
        },
                             cls=RequestEncoder)

        # when
        response = self.under_test.post(
            '/callback/backup-created/project/dataset/table', params=payload)
        backup = table_entity.last_backup

        # then
        self.assertEqual(response.status_int, 200)
        self.assertIsNone(backup)
        error_reporting.assert_called_once()