# Path: blindr/models/event.py
# _ADJUSTED_DELAY = 5
# class Event(object):
#     def create(data):
#     def fetch(user=None, city=None, since=60):
#     def fetch_history(user, other,since=0):


import tests.utils.fake_dynamodb
import unittest
import time
import boto
from unittest.mock import MagicMock
from freezegun import freeze_time
from blindr.models.event import Event, events


class EventTests(unittest.TestCase):
    @freeze_time('2015-01-01')
    def test_create(self):
        events.put_item = MagicMock(return_value = 'put_item_ret')

        event = Event.create({'foo': 'bar'})
        event_data = events.put_item.call_args[1]['data']
        self.assertEqual(event, 'put_item_ret')
        self.assertEqual(event_data['sent_at'], time.time())
        self.assertIsNotNone(event_data['event_id'])
        self.assertEqual(event_data['foo'], 'bar')

    def test_fetch_adjust_since(self):
        events.query_2 = MagicMock(return_value = [])
        Event.fetch(since=100060)

        self.assertEqual(100000, events.query_2.call_args[1]['sent_at__gte'])

    def test_fetch_city(self):
        events.query_2 = MagicMock(return_value = [])
        Event.fetch(city='some_city')


# Path: blindr/models/event.py
# _ADJUSTED_DELAY = 5
# class Event(object):
#     def create(data):
#     def fetch(user=None, city=None, since=60):
#     def fetch_history(user, other,since=0):


# Path: tests/models/test_event.py
import tests.utils.fake_dynamodb
import unittest
import time
import boto
from unittest.mock import MagicMock
from freezegun import freeze_time
from blindr.models.event import Event, events



class EventTests(unittest.TestCase):
    @freeze_time('2015-01-01')
    def test_create(self):
        events.put_item = MagicMock(return_value = 'put_item_ret')

        event = Event.create({'foo': 'bar'})
        event_data = events.put_item.call_args[1]['data']
        self.assertEqual(event, 'put_item_ret')
        self.assertEqual(event_data['sent_at'], time.time())
        self.assertIsNotNone(event_data['event_id'])
        self.assertEqual(event_data['foo'], 'bar')

    def test_fetch_adjust_since(self):
        events.query_2 = MagicMock(return_value = [])
        Event.fetch(since=100060)

        self.assertEqual(100000, events.query_2.call_args[1]['sent_at__gte'])

    def test_fetch_city(self):
        events.query_2 = MagicMock(return_value = [])
        Event.fetch(city='some_city')


        city = events.query_2.call_args[1]['dst__eq']