diff --git a/caravel/model/inquiry.py b/caravel/model/inquiry.py index 4fcf002..43f9d18 100644 --- a/caravel/model/inquiry.py +++ b/caravel/model/inquiry.py @@ -8,38 +8,15 @@ from caravel.model.principal import PrincipalMixin from caravel.model.side_effects import SideEffectsMixin from caravel.model.rate_limits import RateLimitMixin -from caravel.model.replication import ReplicationMixin - from flask import render_template class _Inquiry(TimeOrderMixin, PrincipalMixin, ModeratedMixin, - ReplicationMixin, ndb.Model): - - REPLICATION_URL = "https://go-marketplace.appspot.com/inquiries" - + ndb.Model): message = ndb.StringProperty() listing = ndb.KeyProperty(kind=listing.Listing) - def encode_for_replication(self): - """Flattens this Listing into a JSON dict.""" - - data = self.to_dict() - data["listing"] = self.listing.id() - data["sender"] = { - "email": self.principal.email, - "validated": (self.principal.auth_method == "GOOGLE_APPS") - } - data["moderated"] = (bool(self.principal.validated_by) or - (self.principal.auth_method == "GOOGLE_APPS")) - del data["principal"] - del data["posted_at"] - if "run_trigger" in data: - del data["run_trigger"] - - return data - class Inquiry(SideEffectsMixin, _Inquiry): diff --git a/caravel/model/listing.py b/caravel/model/listing.py index 0dd7e5b..abbe6a4 100644 --- a/caravel/model/listing.py +++ b/caravel/model/listing.py @@ -11,7 +11,6 @@ from caravel.model.full_text import FullTextMixin from caravel.model.rate_limits import RateLimitMixin from caravel.model.sellable import SellableMixin -from caravel.model.replication import ReplicationMixin from caravel import utils @@ -22,11 +21,10 @@ class _Listing(CategoriesMixin, PhotosMixin, PrincipalMixin, TimeOrderMixin, SchemaMixin, PriceMixin, RateLimitMixin, ModeratedMixin, - SellableMixin, FullTextMixin, ReplicationMixin, ndb.Model): + SellableMixin, FullTextMixin, ndb.Model): SCHEMA_VERSION = 12 MARK_AS_OLD_AFTER = datetime.timedelta(days=30) - REPLICATION_URL = "https://go-marketplace.appspot.com/listings" title = ndb.StringProperty() body = ndb.TextProperty() @@ -35,32 +33,6 @@ class _Listing(CategoriesMixin, PhotosMixin, PrincipalMixin, TimeOrderMixin, def can_bump(self): return self.age >= datetime.timedelta(days=7) - def encode_for_replication(self): - """Flattens this Listing into a JSON dict.""" - - data = self.to_dict() - data["posted_at"] = data["posted_at"].isoformat() - data["photos"] = [{"small": photo.public_url("small"), - "large": photo.public_url("large")} - for photo in data["photos"]] - data["price"] = float(data["price"]) - if "run_trigger" in data: - del data["run_trigger"] - del data["version"] - del data["burst_count"] - del data["daily_count"] - del data["keywords"] - del data["principal"] - - data["seller"] = { - "email": self.principal.email, - "validated": (self.principal.auth_method == "GOOGLE_APPS") - } - data["moderated"] = (bool(self.principal.validated_by) or - (self.principal.auth_method == "GOOGLE_APPS")) - - return data - class Listing(SideEffectsMixin, _Listing): diff --git a/caravel/model/replication.py b/caravel/model/replication.py deleted file mode 100644 index 5e98326..0000000 --- a/caravel/model/replication.py +++ /dev/null @@ -1,31 +0,0 @@ -from google.appengine.ext import ndb, db -import urllib2 -import json -from caravel.storage import config - - -class ReplicationMixin(ndb.Model): - - """ - The ReplicatedMixin triggers a background urlfetch call to update this - listing. - """ - - REPLICATION_URL = None - - def encode_for_replication(self): - return self.to_dict() - - def _post_put_hook(self, future): - """ - Write this entity to the third-party site URL. - """ - - if self.REPLICATION_URL: - data = self.encode_for_replication() - data["key"] = self.key.id() - data["replication_key"] = config.replication_key - - urllib2.urlopen(self.REPLICATION_URL, json.dumps(data)) - - return super(ReplicationMixin, self)._post_put_hook(future) diff --git a/caravel/storage/config.py b/caravel/storage/config.py index 1417a12..ac628d3 100644 --- a/caravel/storage/config.py +++ b/caravel/storage/config.py @@ -38,6 +38,5 @@ def get_tor_addresses(): "recaptcha_private_key", "6LeIxAcTAAAAAGG-vFI1TnRWxMZNFuojJ4WifJWe") app.config["RECAPTCHA_DATA_ATTRS"] = {"size": "compact"} -replication_key = lookup("replication_key", "~key~") Bootstrap(app) diff --git a/caravel/templates/listings/map.html b/caravel/templates/listings/map.html deleted file mode 100644 index 496dcb9..0000000 --- a/caravel/templates/listings/map.html +++ /dev/null @@ -1,5 +0,0 @@ -
-
- -
-
diff --git a/caravel/tests/helper.py b/caravel/tests/helper.py index fd3b1e5..88ffb09 100644 --- a/caravel/tests/helper.py +++ b/caravel/tests/helper.py @@ -4,7 +4,6 @@ import uuid import time import sys -import urllib2 import os from contextlib import contextmanager @@ -95,10 +94,10 @@ def setUp(self): sendgrid = config.send_grid_client self._send, sendgrid.send = sendgrid.send, self.emails.append - # Capture outgoing webhooks. - self.webhooks = [] - self._urlopen = urllib2.urlopen - urllib2.urlopen = lambda url, body: self.webhooks.append((url, body)) + # Capture outgoing Slack messages. + # self.chats = [] + # self._send_chat = slack.send_chat + # slack.send_chat = lambda **kw: self.chats.append(kw) # Ensure that UUIDs are deterministic. self._uuid4 = uuid.uuid4 @@ -157,7 +156,7 @@ def tearDown(self): # Un-stub mocks. uuid.uuid4 = self._uuid4 config.send_grid_client.send = self._send - urllib2.urlopen = self._urlopen + # slack.send_chat = self._send_chat super(CaravelTestCase, self).tearDown() diff --git a/caravel/tests/test_replication.py b/caravel/tests/test_replication.py deleted file mode 100644 index 2e9fe87..0000000 --- a/caravel/tests/test_replication.py +++ /dev/null @@ -1,67 +0,0 @@ -from caravel.tests import helper -from caravel import model -import json - - -class TestListings(helper.CaravelTestCase): - - def test_creation(self): - # Submit an inquiry. - with self.google_apps_user("visitor@uchicago.edu"): - self.post("/listing_b", data={ - "principal": "buyer@foo.com", - "message": u"message\u2606 goes here", - "csrf_token": self.csrf_token("/listing_b"), - }) - - self.assertEquals( - [(u, json.loads(d)) for u, d in self.webhooks], - [ - ("https://go-marketplace.appspot.com/listings", - {u"replication_key": u"~key~", - u"key": u"listing_a", - u"title": u"Listing \u2606A", - u"sold": False, - u"body": u"Body of \u2606A", - u"categories": [u"cars"], - u"photos": [ - {u"large": u"/_ah/gcs/test.appspot.com/listing-a-large", - u"small": u"/_ah/gcs/test.appspot.com/listing-a-small"}, - {u"large": u"/_ah/gcs/test.appspot.com/listing-a2-large", - u"small": u"/_ah/gcs/test.appspot.com/listing-a2-small"} - ], - u"posted_at": self.listing_a.posted_at.isoformat(), - u"price": 3.1, - u"seller": { - u"email": u"seller-a@uchicago.edu", - u"validated": True}, - u"moderated": True}), - ("https://go-marketplace.appspot.com/listings", - {u"replication_key": u"~key~", - u"key": u"listing_b", - u"title": u"Listing \u2606B", - u"sold": False, - u"body": u"Body of \u2606B", - u"categories": [u"apartments"], - u"photos": [ - {u"large": u"/_ah/gcs/test.appspot.com/listing-b-large", - u"small": u"/_ah/gcs/test.appspot.com/listing-b-small"}, - {u"large": u"/_ah/gcs/test.appspot.com/listing-b2-large", - u"small": u"/_ah/gcs/test.appspot.com/listing-b2-small"} - ], - u"posted_at": self.listing_b.posted_at.isoformat(), - u"price": 71.1, - u"seller": { - u"email": u"seller-b@uchicago.edu", - u"validated": False}, - u"moderated": True}), - ("https://go-marketplace.appspot.com/inquiries", - {u"key": 11, - u"listing": "listing_b", - u"message": u"message\u2606 goes here", - u"moderated": True, - u"replication_key": u"~key~", - u"sender": { - u"email": u"visitor@uchicago.edu", u"validated": True} - }) - ]) diff --git a/caravel/tests/test_replication_creation_expect.txt b/caravel/tests/test_replication_creation_expect.txt deleted file mode 100644 index e69de29..0000000 diff --git a/caravel/tests/test_replication_post_inquiry_expect.txt b/caravel/tests/test_replication_post_inquiry_expect.txt deleted file mode 100644 index e69de29..0000000