forked from upstream-mirrors/OpenTracks
Remove spreadsheet for the test activity on Google Drive.
This commit is contained in:
@@ -207,6 +207,40 @@ public class GoogleUtils {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete spreadsheet which name is title.
|
||||||
|
*
|
||||||
|
* @param title the name of spreadsheet
|
||||||
|
* @param activity to get context
|
||||||
|
*/
|
||||||
|
public static void deleteSpreadsheetByTitle(String title, Activity activity) {
|
||||||
|
Context context = activity.getApplicationContext();
|
||||||
|
DocumentsClient documentsClient = new DocumentsClient(
|
||||||
|
GDataClientFactory.getGDataClient(context), new XmlDocsGDataParserFactory(
|
||||||
|
new AndroidXmlParserFactory()));
|
||||||
|
|
||||||
|
try {
|
||||||
|
String documentsAuthToken = AccountManager.get(context).blockingGetAuthToken(
|
||||||
|
getAccount(context), documentsClient.getServiceName(), false);
|
||||||
|
String uri = String.format(Locale.US, SendDocsUtils.GET_SPREADSHEET_BY_TITLE_URI,
|
||||||
|
URLEncoder.encode(title, "utf-8"));
|
||||||
|
GDataParser gDataParser = documentsClient.getParserForFeed(Entry.class, uri,
|
||||||
|
documentsAuthToken);
|
||||||
|
gDataParser.init();
|
||||||
|
|
||||||
|
while (gDataParser.hasMoreData()) {
|
||||||
|
Entry entry = gDataParser.readNextEntry(null);
|
||||||
|
String entryTitle = entry.getTitle();
|
||||||
|
if (entryTitle.equals(title)) {
|
||||||
|
documentsClient.deleteEntry(entry.getEditUri(), documentsAuthToken);
|
||||||
|
Log.d(EndToEndTestUtils.LOG_TAG, "Delete one spreadsheet.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e(EndToEndTestUtils.LOG_TAG, "Unable to fetch spreadsheet.", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Searches docs in user's Google Documents.
|
* Searches docs in user's Google Documents.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -76,6 +76,8 @@ public class SendToGoogleTest extends ActivityInstrumentationTestCase2<TrackList
|
|||||||
public void testSendTwoTracksWithSameActivity() {
|
public void testSendTwoTracksWithSameActivity() {
|
||||||
String testActivity = "(TestActivity)";
|
String testActivity = "(TestActivity)";
|
||||||
EndToEndTestUtils.activityType = testActivity;
|
EndToEndTestUtils.activityType = testActivity;
|
||||||
|
GoogleUtils.deleteSpreadsheetByTitle("My Tracks-" + EndToEndTestUtils.activityType,
|
||||||
|
EndToEndTestUtils.activityMytracks);
|
||||||
EndToEndTestUtils.createSimpleTrack(1, false);
|
EndToEndTestUtils.createSimpleTrack(1, false);
|
||||||
boolean result = sendToGoogle();
|
boolean result = sendToGoogle();
|
||||||
result = result && sendToGoogle();
|
result = result && sendToGoogle();
|
||||||
|
|||||||
Reference in New Issue
Block a user