def test_num_fresh_bugs_with_big_stale_query(self): """ Given a query that returns max_batch_size + n results, where n < max_batch_size, the number of fresh bugs in the form's cleaned data is equal to n the second time the query is submitted (Next n bugs are accepted.) """ max_batch_size = 3 n = 2 query_params = 'foo' db_bugs = BugzillaBugFactory.create_batch(max_batch_size) batch1 = TaskImportBatchFactory.create() for bug in db_bugs: TaskFactory.create_batch(1, batch=batch1, imported_item=bug, is_invalid=False) with patch('oneanddone.tasks.forms.BugzillaUtils.request_bugs') as request_bugs: stale_bugs = [{u'id': bug.bugzilla_id, u'summary': bug.summary} for bug in db_bugs] new_bugs = [{u'id': 50 + i, u'summary': u'a'} for i in range(n)] all_bugs = stale_bugs + new_bugs def fake_request(request_params, fields=['id', 'summary'], offset=0, limit=99): return all_bugs[offset:offset + limit] request_bugs.side_effect = fake_request bugs = TaskImportBatchForm._get_fresh_bugs(batch1.query, query_params, len(all_bugs), max_batch_size) eq_(bugs, all_bugs[max_batch_size:])
def test_num_fresh_bugs_with_small_stale_query(self): """ Given a query that returns n < max_batch_size results, the number of fresh bugs in the form's cleaned data is equal to 0, if the query has been submitted before """ max_batch_size = 20 query_params = 'foo' bug1, bug2 = BugzillaBugFactory.create_batch(2) batch1 = TaskImportBatchFactory.create() TaskFactory.create_batch(1, batch=batch1, imported_item=bug1, is_invalid=False) TaskFactory.create_batch(1, batch=batch1, imported_item=bug2, is_invalid=False) with patch('oneanddone.tasks.forms.BugzillaUtils.request_bugs') as request_bugs: # two bugs previously imported in batch1 request_bugs.return_value = [{u'id': bug1.bugzilla_id, u'summary': bug1.summary}, {u'id': bug2.bugzilla_id, u'summary': bug2.summary}] bugs = TaskImportBatchForm._get_fresh_bugs(batch1.query, query_params, len(request_bugs()), max_batch_size) eq_(len(bugs), 0)
def test_num_fresh_bugs_with_big_fresh_query(self): """ Given a query that returns max_batch_size + n results, where n < max_batch_size, the first max_batch_size bugs are accepted. """ max_batch_size = 2 query_params = fresh_query = 'foo' with patch('oneanddone.tasks.forms.BugzillaUtils.request_bugs' ) as request_bugs: request_bugs.return_value = [{ u'id': 50, u'summary': u'a' }, { u'id': 51, u'summary': u'b' }, { u'id': 52, u'summary': u'c' }, { u'id': 53, u'summary': u'd' }] bugs = TaskImportBatchForm._get_fresh_bugs(fresh_query, query_params, len(request_bugs()), max_batch_size) eq_(bugs, request_bugs()[:max_batch_size])
def test_num_fresh_bugs_with_small_stale_query(self): """ Given a query that returns n < max_batch_size results, the number of fresh bugs in the form's cleaned data is equal to 0, if the query has been submitted before """ max_batch_size = 20 query_params = 'foo' bug1, bug2 = BugzillaBugFactory.create_batch(2) batch1 = TaskImportBatchFactory.create() TaskFactory.create_batch(1, batch=batch1, imported_item=bug1, is_invalid=False) TaskFactory.create_batch(1, batch=batch1, imported_item=bug2, is_invalid=False) with patch('oneanddone.tasks.forms.BugzillaUtils.request_bugs' ) as request_bugs: # two bugs previously imported in batch1 request_bugs.return_value = [{ u'id': bug1.bugzilla_id, u'summary': bug1.summary }, { u'id': bug2.bugzilla_id, u'summary': bug2.summary }] bugs = TaskImportBatchForm._get_fresh_bugs(batch1.query, query_params, len(request_bugs()), max_batch_size) eq_(len(bugs), 0)
def test_num_fresh_bugs_with_big_fresh_query(self): """ Given a query that returns max_batch_size + n results, where n < max_batch_size, the first max_batch_size bugs are accepted. """ max_batch_size = 2 query_params = fresh_query = 'foo' with patch('oneanddone.tasks.forms.BugzillaUtils.request_bugs') as request_bugs: request_bugs.return_value = [{u'id': 50, u'summary': u'a'}, {u'id': 51, u'summary': u'b'}, {u'id': 52, u'summary': u'c'}, {u'id': 53, u'summary': u'd'}] bugs = TaskImportBatchForm._get_fresh_bugs(fresh_query, query_params, len(request_bugs()), max_batch_size) eq_(bugs, request_bugs()[:max_batch_size])
def test_num_fresh_bugs_with_small_new_query(self): """ Given a query that returns n < max_batch_size results, the number of fresh bugs in the form's cleaned data is equal to n if this is the first time the query is ever submitted. """ max_batch_size = 20 query_params = 'foo' with patch('oneanddone.tasks.forms.BugzillaUtils.request_bugs') as request_bugs: # two fresh bugs request_bugs.return_value = [{u'id': 50, u'summary': u'foo'}, {u'id': 51, u'summary': u'bar'}] query = 'baz' n = len(request_bugs()) fresh_bugs = TaskImportBatchForm._get_fresh_bugs(query, query_params, n, max_batch_size) eq_(len(fresh_bugs), n)
def test_num_fresh_bugs_with_big_stale_query(self): """ Given a query that returns max_batch_size + n results, where n < max_batch_size, the number of fresh bugs in the form's cleaned data is equal to n the second time the query is submitted (Next n bugs are accepted.) """ max_batch_size = 3 n = 2 query_params = 'foo' db_bugs = BugzillaBugFactory.create_batch(max_batch_size) batch1 = TaskImportBatchFactory.create() for bug in db_bugs: TaskFactory.create_batch(1, batch=batch1, imported_item=bug, is_invalid=False) with patch('oneanddone.tasks.forms.BugzillaUtils.request_bugs' ) as request_bugs: stale_bugs = [{ u'id': bug.bugzilla_id, u'summary': bug.summary } for bug in db_bugs] new_bugs = [{u'id': 50 + i, u'summary': u'a'} for i in range(n)] all_bugs = stale_bugs + new_bugs def fake_request(request_params, fields=['id', 'summary'], offset=0, limit=99): return all_bugs[offset:offset + limit] request_bugs.side_effect = fake_request bugs = TaskImportBatchForm._get_fresh_bugs(batch1.query, query_params, len(all_bugs), max_batch_size) eq_(bugs, all_bugs[max_batch_size:])
def test_num_fresh_bugs_with_small_new_query(self): """ Given a query that returns n < max_batch_size results, the number of fresh bugs in the form's cleaned data is equal to n if this is the first time the query is ever submitted. """ max_batch_size = 20 query_params = 'foo' with patch('oneanddone.tasks.forms.BugzillaUtils.request_bugs' ) as request_bugs: # two fresh bugs request_bugs.return_value = [{ u'id': 50, u'summary': u'foo' }, { u'id': 51, u'summary': u'bar' }] query = 'baz' n = len(request_bugs()) fresh_bugs = TaskImportBatchForm._get_fresh_bugs( query, query_params, n, max_batch_size) eq_(len(fresh_bugs), n)