TestIntegrationRun tests both the twitter API and zip file import paths.
(t *testing.T)
| 101 | |
| 102 | // TestIntegrationRun tests both the twitter API and zip file import paths. |
| 103 | func TestIntegrationRun(t *testing.T) { |
| 104 | const accessToken = "foo" |
| 105 | const accessSecret = "bar" |
| 106 | const userID = "camlistore_test" |
| 107 | |
| 108 | responder := httputil.FileResponder("testdata/user_timeline.json") |
| 109 | transport, err := httputil.NewRegexpFakeTransport([]*httputil.Matcher{ |
| 110 | {URLRegex: `^https\://api\.twitter\.com/1.1/statuses/user_timeline.json\?`, Fn: responder}, |
| 111 | }) |
| 112 | if err != nil { |
| 113 | t.Fatal(err) |
| 114 | } |
| 115 | |
| 116 | imptest.ImporterTest(t, "twitter", transport, func(rc *importer.RunContext) { |
| 117 | |
| 118 | err = rc.AccountNode().SetAttrs(importer.AcctAttrAccessToken, accessToken, importer.AcctAttrAccessTokenSecret, accessSecret, importer.AcctAttrUserID, userID) |
| 119 | if err != nil { |
| 120 | t.Fatal(err) |
| 121 | } |
| 122 | |
| 123 | // First, run without the zip. |
| 124 | testee := imp{} |
| 125 | if err := testee.Run(rc); err != nil { |
| 126 | t.Fatal(err) |
| 127 | } |
| 128 | |
| 129 | // Tests that special characters are decoded properly, #476. |
| 130 | jsonTweets := map[string]string{ |
| 131 | "727366997390946304": "I am a test account. Boop beep.", |
| 132 | "727613700438265858": "foo and bar", |
| 133 | "727613616149565440": `More beeping and booping & <> . $ % ^ * && /\/\()!`, |
| 134 | } |
| 135 | |
| 136 | checkTweets(t, rc, jsonTweets) |
| 137 | |
| 138 | zipFile, err := os.Open("testdata/camlistore_test.zip") |
| 139 | if err != nil { |
| 140 | t.Fatal(err) |
| 141 | } |
| 142 | defer zipFile.Close() |
| 143 | |
| 144 | zipRef, err := schema.WriteFileFromReader(ctxbg, rc.Host.Target(), "camlistore_test.zip", zipFile) |
| 145 | if err != nil { |
| 146 | t.Fatal(err) |
| 147 | } |
| 148 | err = rc.AccountNode().SetAttrs(acctAttrTweetZip, zipRef.String()) |
| 149 | if err != nil { |
| 150 | t.Fatal(err) |
| 151 | } |
| 152 | |
| 153 | // Now run with the zip. |
| 154 | if err := testee.Run(rc); err != nil { |
| 155 | t.Fatal(err) |
| 156 | } |
| 157 | |
| 158 | zipTweets := map[string]string{ |
| 159 | // Different text from JSON version for this item. Tests that importer prefers JSON. |
| 160 | // Included here just to explain the test. |
nothing calls this directly
no test coverage detected