Example #1
0
    def __init__(self, *args, **kwargs):
        super(CaravelTestCase, self).__init__(*args, **kwargs)
        self.client = app.test_client()

        utils.init(caravel)

        admin = appbuilder.sm.find_user("admin")
        if not admin:
            appbuilder.sm.add_user(
                "admin", "admin", " user", "*****@*****.**", appbuilder.sm.find_role("Admin"), password="******"
            )

        gamma = appbuilder.sm.find_user("gamma")
        if not gamma:
            appbuilder.sm.add_user(
                "gamma", "gamma", "user", "*****@*****.**", appbuilder.sm.find_role("Gamma"), password="******"
            )

        alpha = appbuilder.sm.find_user("alpha")
        if not alpha:
            appbuilder.sm.add_user(
                "alpha", "alpha", "user", "*****@*****.**", appbuilder.sm.find_role("Alpha"), password="******"
            )

        utils.init(caravel)
Example #2
0
def test_new_listing():
    emails = []
    client = config.send_grid_client
    _send, client.send = client.send, emails.append

    try:
        client = app.test_client()
        page = client.get("/new")
        csrf_token = re.search(r'csrf_token".*"(.*)"', page.data).group(1)

        page = client.post("new", data=dict(
            csrf_token=csrf_token,
            title="thenewlisting",
            description="foobar",
            seller="*****@*****.**",
            categories="books"
        ))

        assert page.status == "302 FOUND"
        assert len(emails) == 1

        assert emails[0].to[0] == "*****@*****.**"
        assert emails[0].from_email == "*****@*****.**"

        assert "thenewlisting" in emails[0].html

        path = re.search(r'http://localhost(/.*)"', emails[0].html).group(1)
        client.get(path).data  # create listing
        assert "thenewlisting" in client.get(path).data

        path2 = re.search(r'http://localhost(/.*)', emails[0].text).group(1)
        assert path2 == path

    finally:
        client.send = _send
Example #3
0
def test_inquiry():
    entities.Listing(title="integtestb", posting_time=1.,
                     key_name="listingc", seller="*****@*****.**").put()

    emails = []
    client = config.send_grid_client
    _send, client.send = client.send, emails.append

    try:
        client = app.test_client()
        page = client.get("/listingc")
        csrf_token = re.search(r'csrf_token".*"(.*)"', page.data).group(1)

        page = client.post("/listingc", data=dict(
            buyer="*****@*****.**",
            message="message goes here",
            csrf_token=csrf_token,
        ))

        assert len(emails) == 1

        assert emails[0].to[0] == "*****@*****.**"
        assert emails[0].reply_to == "*****@*****.**"

        assert "integtestb" in emails[0].html
        assert "*****@*****.**" in emails[0].html
        assert "message goes here" in emails[0].html

        assert "integtestb" in emails[0].text
        assert "*****@*****.**" in emails[0].text
        assert "message goes here" in emails[0].text

    finally:
        client.send = _send
Example #4
0
    def __init__(self, *args, **kwargs):
        super(CaravelTestCase, self).__init__(*args, **kwargs)
        self.client = app.test_client()

        utils.init(caravel)

        admin = appbuilder.sm.find_user('admin')
        if not admin:
            appbuilder.sm.add_user('admin',
                                   'admin',
                                   ' user',
                                   '*****@*****.**',
                                   appbuilder.sm.find_role('Admin'),
                                   password='******')

        gamma = appbuilder.sm.find_user('gamma')
        if not gamma:
            appbuilder.sm.add_user('gamma',
                                   'gamma',
                                   'user',
                                   '*****@*****.**',
                                   appbuilder.sm.find_role('Gamma'),
                                   password='******')

        alpha = appbuilder.sm.find_user('alpha')
        if not alpha:
            appbuilder.sm.add_user('alpha',
                                   'alpha',
                                   'user',
                                   '*****@*****.**',
                                   appbuilder.sm.find_role('Alpha'),
                                   password='******')

        utils.init(caravel)
Example #5
0
    def __init__(self, *args, **kwargs):
        super(CaravelTestCase, self).__init__(*args, **kwargs)
        self.client = app.test_client()

        utils.init(caravel)

        admin = appbuilder.sm.find_user('admin')
        if not admin:
            appbuilder.sm.add_user(
                'admin', 'admin',' user', '*****@*****.**',
                appbuilder.sm.find_role('Admin'),
                password='******')

        gamma = appbuilder.sm.find_user('gamma')
        if not gamma:
            appbuilder.sm.add_user(
                'gamma', 'gamma', 'user', '*****@*****.**',
                appbuilder.sm.find_role('Gamma'),
                password='******')

        alpha = appbuilder.sm.find_user('alpha')
        if not alpha:
            appbuilder.sm.add_user(
                'alpha', 'alpha', 'user', '*****@*****.**',
                appbuilder.sm.find_role('Alpha'),
                password='******')

        utils.init(caravel)
Example #6
0
    def setUp(self):
        # FIXME: Remove once everything else is TestCase-ified.
        db.delete(db.Query(keys_only=True))
        memcache.flush_all()

        # Configure a basic HTTP client.
        self.http_client = app.test_client()

        # Capture outgoing email messages.
        self.emails = []
        sendgrid = config.send_grid_client
        self._send, sendgrid.send = sendgrid.send, self.emails.append

        # 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
        uuid.uuid4 = lambda: "ZZ-ZZ-ZZ"

        # Create simple entities to play with.
        self.listing_a = entities.Listing(
            title=u"Listing \u2606A",
            body=u"Body of \u2606A",
            posting_time=time.time() - 4 * 3600,
            seller="*****@*****.**",
            price=310,
            categories=["category:cars"],
            photos=["listing-a", "listing-a2"],
            admin_key="a_key",
            key_name="listing_a")
        self.listing_a.put()

        self.listing_b = entities.Listing(
            title=u"Listing \u2606B",
            body=u"Body of \u2606B",
            posting_time=time.time() - 24 * 3600,
            seller="*****@*****.**",
            price=7110,
            categories=["category:apartments"],
            photos=["listing-b", "listing-b2"],
            key_name="listing_b")
        self.listing_b.put()
        
        self.listing_c = entities.Listing(
            title=u"Listing \u2606C",
            body=u"Body of \u2606C",
            posting_time=0.,
            seller="*****@*****.**",
            price=9105,
            categories=["category:appliances"],
            photos=[],
            admin_key="adminkey",
            key_name="listing_c")
        self.listing_c.put()

        # Allow very large diffs.
        self.maxDiff = None
Example #7
0
 def __init__(self, *args, **kwargs):
     super(CaravelTestCase, self).__init__(*args, **kwargs)
     self.client = app.test_client()
     role_admin = appbuilder.sm.find_role('Admin')
     user = appbuilder.sm.find_user('admin')
     if not user:
         appbuilder.sm.add_user('admin', 'admin', ' user', '*****@*****.**',
                                role_admin, 'general')
Example #8
0
    def __init__(self, *args, **kwargs):
        if (
                self.requires_examples and
                not os.environ.get('SOLO_TEST') and
                not os.environ.get('examples_loaded')
            ):
            cli.load_examples(load_test_data=True)
            utils.init(caravel)
            os.environ['examples_loaded'] = '1'
        super(CaravelTestCase, self).__init__(*args, **kwargs)
        self.client = app.test_client()
        self.maxDiff = None
        utils.init(caravel)

        admin = appbuilder.sm.find_user('admin')
        if not admin:
            appbuilder.sm.add_user(
                'admin', 'admin', ' user', '*****@*****.**',
                appbuilder.sm.find_role('Admin'),
                password='******')

        gamma = appbuilder.sm.find_user('gamma')
        if not gamma:
            appbuilder.sm.add_user(
                'gamma', 'gamma', 'user', '*****@*****.**',
                appbuilder.sm.find_role('Gamma'),
                password='******')

        alpha = appbuilder.sm.find_user('alpha')
        if not alpha:
            appbuilder.sm.add_user(
                'alpha', 'alpha', 'user', '*****@*****.**',
                appbuilder.sm.find_role('Alpha'),
                password='******')

        # create druid cluster and druid datasources
        session = db.session
        cluster = session.query(models.DruidCluster).filter_by(
            cluster_name="druid_test").first()
        if not cluster:
            cluster = models.DruidCluster(cluster_name="druid_test")
            session.add(cluster)
            session.commit()

            druid_datasource1 = models.DruidDatasource(
                datasource_name='druid_ds_1',
                cluster_name='druid_test'
            )
            session.add(druid_datasource1)
            druid_datasource2 = models.DruidDatasource(
                datasource_name='druid_ds_2',
                cluster_name='druid_test'
            )
            session.add(druid_datasource2)
            session.commit()

        utils.init(caravel)
Example #9
0
 def __init__(self, *args, **kwargs):
     super(CaravelTestCase, self).__init__(*args, **kwargs)
     self.client = app.test_client()
     role_admin = appbuilder.sm.find_role('Admin')
     user = appbuilder.sm.find_user('admin')
     if not user:
         appbuilder.sm.add_user(
             'admin', 'admin',' user', '*****@*****.**',
             role_admin, 'general')
Example #10
0
def test_search():
    entities.Listing(
        title="integtesta", posting_time=time.time() - 35000,
        key_name="test_listing_search").put()

    client = app.test_client()
    page = client.get("/?q=integtesta")

    assert "integtesta" in page.data
    assert "10h ago" in page.data
    assert "$0.00" in page.data
    assert "/test_listing_search" in page.data

    page = client.get("/?q=integtesta&offset=1")
    assert "test_listing_search" not in page.data
Example #11
0
def test_show():
    entities.Listing(title="integtestb", body="integbody", admin_key="4",
                     key_name="listingb", seller="e@mail").put()

    client = app.test_client()
    page = client.get("/listingb")

    assert page.status == "404 NOT FOUND"

    client.get("/listingb?key=4")
    page = client.get("/listingb")

    assert "e@mail" in page.data
    assert "integtestb" in page.data
    assert "integbody" in page.data
Example #12
0
    def setUp(self):
        # FIXME: Remove once everything else is TestCase-ified.
        db.delete(db.Query(keys_only=True))
        memcache.flush_all()

        # Configure a basic HTTP client.
        self.http_client = app.test_client()

        # Capture outgoing email messages.
        self.emails = []
        sendgrid = config.send_grid_client
        self._send, sendgrid.send = sendgrid.send, self.emails.append

        # 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
        uuid.uuid4 = lambda: "ZZ-ZZ-ZZ"

        # Allocate a test session.
        device = utils.Device(nonce="foobar",
                              user_agent="mozilla",
                              ip_address="1.2.3.4")

        # Create simple entities to play with.
        self.listing_a = model.Listing(
            title=u"Listing \u2606A",
            body=u"Body of \u2606A",
            posted_at=datetime.datetime.now() - datetime.timedelta(hours=4),
            principal=utils.Principal("*****@*****.**", device,
                                      utils.Principal.GOOGLE_APPS),
            run_trigger=True,
            version=11,
            price=3.10,
            categories=["cars"],
            photos=[model.Photo("listing-a"),
                    model.Photo("listing-a2")],
            id="listing_a")
        self.listing_a.put()

        seller_b = utils.Principal("*****@*****.**", device,
                                   utils.Principal.EMAIL)
        seller_b.validated_by = "fixture for unit test"

        self.listing_b = model.Listing(
            title=u"Listing \u2606B",
            body=u"Body of \u2606B",
            posted_at=datetime.datetime.now() - datetime.timedelta(hours=24),
            principal=seller_b,
            price=71.10,
            run_trigger=True,
            version=11,
            categories=["apartments"],
            photos=[model.Photo("listing-b"),
                    model.Photo("listing-b2")],
            id="listing_b")
        self.listing_b.put()

        # Allow very large diffs.
        self.maxDiff = None

        # Look up static expectations.
        super(CaravelTestCase, self).setUp()
Example #13
0
 def __init__(self, *args, **kwargs):
     super(CeleryTestCase, self).__init__(*args, **kwargs)
     self.client = app.test_client()
Example #14
0
 def __init__(self, *args, **kwargs):
     super(CeleryTestCase, self).__init__(*args, **kwargs)
     self.client = app.test_client()
Example #15
0
    def setUp(self):
        # FIXME: Remove once everything else is TestCase-ified.
        db.delete(db.Query(keys_only=True))
        memcache.flush_all()

        # Configure a basic HTTP client.
        self.http_client = app.test_client()

        # Capture outgoing email messages.
        self.emails = []
        sendgrid = config.send_grid_client
        self._send, sendgrid.send = sendgrid.send, self.emails.append

        # 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
        uuid.uuid4 = lambda: "ZZ-ZZ-ZZ"

        # Allocate a test session.
        device = utils.Device(
            nonce="foobar",
            user_agent="mozilla",
            ip_address="1.2.3.4"
        )

        # Create simple entities to play with.
        self.listing_a = model.Listing(
            title=u"Listing \u2606A",
            body=u"Body of \u2606A",
            posted_at=datetime.datetime.now() - datetime.timedelta(hours=4),
            principal=utils.Principal("*****@*****.**", device,
                                      utils.Principal.GOOGLE_APPS),
            run_trigger=True,
            version=11,
            price=3.10,
            categories=["cars"],
            photos=[model.Photo("listing-a"), model.Photo("listing-a2")],
            id="listing_a")
        self.listing_a.put()

        seller_b = utils.Principal("*****@*****.**", device,
                                   utils.Principal.EMAIL)
        seller_b.validated_by = "fixture for unit test"

        self.listing_b = model.Listing(
            title=u"Listing \u2606B",
            body=u"Body of \u2606B",
            posted_at=datetime.datetime.now() - datetime.timedelta(hours=24),
            principal=seller_b,
            price=71.10,
            run_trigger=True,
            version=11,
            categories=["apartments"],
            photos=[model.Photo("listing-b"), model.Photo("listing-b2")],
            id="listing_b")
        self.listing_b.put()

        # Allow very large diffs.
        self.maxDiff = None

        # Look up static expectations.
        super(CaravelTestCase, self).setUp()