Beispiel #1
0
    def test_dict_generation(self):
        services = [
            Service(
                details({
                    "Name of service": "test_name_2",
                    "Abbr": "tn2",
                    "2013-Q3 Vol.": "6,400,000"
                })),
            Service(
                details({
                    "Name of service": "test_name_3",
                    "Abbr": "tn3",
                    "2012-Q4 Vol.": "6,400,000"
                }))
        ]

        dicts = dict_map([("name", lambda s: s.name),
                          ("abbr", lambda s: s.abbr)], services)

        assert_that(dicts[0],
                    has_entries({
                        'name': 'test_name_2',
                        'abbr': 'tn2'
                    }))
        assert_that(
            dicts[1],
            has_entries({
                'name': 'test_name_3',
                'abbr': 'tn3',
                'historic': 'Apr 2011 to Mar 2012'
            }))
    def test_cost(self):
        service = Service(details({
            "2012-Q4 Vol.": "2,000",
            u'2012-Q4 CPT (\xa3)': "2.00"
        }))

        assert_that(service.latest_kpi_for('cost'), is_(4000))
Beispiel #3
0
    def test_building_a_list_of_departments_from_services(self):
        services = [
            Service(
                details({
                    u'Abbr': 'ABC',
                    u'Department': "Agency for Beautiful Code"
                })),
            Service(
                details({
                    u'Abbr': 'MSW',
                    u'Department': "Ministry of Silly Walks"
                })),
            Service(
                details({
                    u'Abbr': 'ABC',
                    u'Department': "Agency for Beautiful Code"
                })),
        ]

        departments = Department.from_services(services)

        assert_that(len(departments), is_(2))
        assert_that(departments[0].name, is_("Agency for Beautiful Code"))
        assert_that(departments[0].services, contains(services[0],
                                                      services[2]))
    def test_calculate_volume_change_from_previous_value(self):
        increase_service = Service(details({
            '2013-Q1 Vol.': '200',
            '2012-Q4 Vol.': '100',
        }))
        decrease_service = Service(details({
            '2013-Q1 Vol.': '100',
            '2012-Q4 Vol.': '200',
        }))
        no_previous_vol_service = Service(details({
            '2013-Q1 Vol.': '100',
            '2012-Q4 Vol.': '',
        }))
        zero_previous_vol_service = Service(details({
            '2013-Q1 Vol.': '100',
            '2012-Q4 Vol.': '0',
        }))
        zero_current_vol_service = Service(details({
            '2013-Q1 Vol.': '0',
            '2012-Q4 Vol.': '100',
        }))

        assert_that(increase_service.latest_kpi_for('volume_change'), is_(2))
        assert_that(decrease_service.latest_kpi_for('volume_change'), is_(0.5))
        assert_that(no_previous_vol_service.latest_kpi_for('volume_change'), is_(None))
        assert_that(zero_previous_vol_service.latest_kpi_for('volume_change'), is_(None))
        assert_that(zero_current_vol_service.latest_kpi_for('volume_change'), is_(0))
Beispiel #5
0
    def test_data_coverage_excludes_non_high_volume_services(self):
        services = [
            Service(
                details({
                    "2012-Q4 Vol.": "2,000",
                    '2012-Q4 Digital vol.': '10',
                    u'2012-Q4 CPT (\xa3)': "2.00",
                    "2013-Q1 Vol.": "2,000",
                    u'2013-Q1 CPT (\xa3)': "2.00",
                    '2013-Q1 Digital vol.': '10',
                })),
            Service(
                details({
                    "2012-Q4 Vol.": "1,000",
                    u'2012-Q4 CPT (\xa3)': "3.00",
                    '2012-Q4 Digital vol.': '10',
                    u'High-volume?': 'yes'
                })),
        ]

        dept = Department("Agency for Beautiful Code", services)

        coverage = dept.data_coverage

        assert_that(float(coverage.percentage), is_(0.125))
        assert_that(coverage.requested, is_(24))
        assert_that(coverage.provided, is_(3))
Beispiel #6
0
    def test_data_coverage_when_quarter_not_requested(self):
        services = [
            Service(
                details({
                    "2012-Q4 Vol.": "2,000",
                    '2012-Q4 Digital vol.': '10',
                    u'2012-Q4 CPT (\xa3)': "2.00",
                    "2013-Q1 Vol.": "***",
                    u'2013-Q1 CPT (\xa3)': "***",
                    '2013-Q1 Digital vol.': '***',
                    u'High-volume?': 'yes'
                })),
            Service(
                details({
                    "2012-Q4 Vol.": "1,000",
                    u'2012-Q4 CPT (\xa3)': "3.00",
                    '2012-Q4 Digital vol.': '10',
                    u'High-volume?': 'yes'
                })),
        ]

        dept = Department("Agency for Beautiful Code", services)

        coverage = dept.data_coverage

        assert_that(float(coverage.percentage), close_to(0.1333333, 0.001))
        assert_that(coverage.requested, is_(45))
        assert_that(coverage.provided, is_(6))
Beispiel #7
0
    def __init__(self, user, timeout):
        self.cookies = False
        self.user = user
        self.timeout = timeout

        self.s = Service(url=PAGE_URL + self.user,
                         default_timeout=self.timeout)
Beispiel #8
0
def oauth():
    code = request.args.get('code')
    s = Service(ServiceType.WEIBO)

    if not code:
        auth_url = s.get_authorize_url()
        return redirect(auth_url)

    auth, r = s.init_token(code)
    uid = auth.account__get_uid().uid
    session['userid'] = uid
    session['token'] = r.access_token
    session['expires_in'] = r.expires_in

    #oauth = OAuth.get_by_ser_uid(uid)

    #if oauth:
        #session['userid'] = oauth.id
    #else:
        #oauth = OAuth()
        #oauth.ser_uid = uid
        #oauth.service = 'weibo'
        #oauth.save()
        #session['userid'] = oauth.id
    return redirect('/')
    def test_most_recent_kpi_with_attributes_are_none_if_no_attributes_are_present(self):
        service = Service(details({
            '2012-Q4 Vol.': '10',
            '2013-Q1 Vol.': '3',
        }))

        assert_that(service.find_recent_kpis_with_attributes(['volume_num', 'digital_volume_num']),
                    is_(None))
    def test_volumes(self):
        service = Service(
            details({
                '2012-Q4 Vol.': '10',
                '2012-Q4 Digital vol.': '5'
            }))

        assert_that(service.latest_kpi_for('takeup'), is_(0.5))
    def test_most_recent_kpi_takeup_is_none_if_no_matching_quarters(self):
        service = Service(
            details({
                '2012-Q4 Vol.': '10',
                '2013-Q1 Digital vol.': '5'
            }))

        assert_that(service.latest_kpi_for('takeup'), is_(None))
    def test_cost(self):
        service = Service(
            details({
                "2012-Q4 Vol.": "2,000",
                u'2012-Q4 CPT (\xa3)': "2.00"
            }))

        assert_that(service.latest_kpi_for('cost'), is_(4000))
Beispiel #13
0
    def setup(self):
        self.train_deck.shuffle()
        self.ticket_deck.shuffle()

        for player in self.players:
            player.refresh()
            Service.deal_player_trains(self, player, 4)
            Service.deal_player_tickets(self, player, True)
    def test_sum_of_total_transactions(self):
        services = [
            Service(details({'2013-Q1 Vol.': '10'})),
            Service(details({'2013-Q2 Vol.': '20'})),
            Service(details({'2013-Q1 Vol.': '30'}))
        ]

        assert_that(total_transaction_volume(services), is_(60))
    def test_most_recent_kpi_with_given_attribute(self):
        service = Service(details({
            '2012-Q4 Vol.': '10',
            '2012-Q4 Digital vol.': '5',
            '2013-Q1 Vol.': '3',
        }))

        assert_that(service.find_recent_kpis_with_attributes(['volume_num', 'digital_volume_num'])['volume_num'],
                    is_(10))
    def test_aggregate_is_sum_of_values_when_high_volume_does_not_matter(self):
        services = [
            Service(details({"2012-Q4 Vol.": "2,000"})),
            Service(details({"2012-Q4 Vol.": "3,000"})),
        ]

        kpi_aggregator = ServiceKpiAggregator(services)

        assert_that(kpi_aggregator.aggregate(['volume_num']), is_([5000]))
Beispiel #17
0
    def test_cost_is_none_when_no_kpi_is_available(self):
        services = [
            Service(details({u'High-volume?': 'yes'})),
            Service(details({u'High-volume?': 'yes'})),
        ]

        dept = Department("Agency for Beautiful Code", services)

        assert_that(dept.cost, is_(None))
    def test_aggregate_ignores_when_no_kpis(self):
        services = [
            Service(details({"2012-Q4 Vol.": "2,000"})),
            Service(details({})),
        ]

        kpi_aggregator = ServiceKpiAggregator(services)

        assert_that(kpi_aggregator.aggregate(['volume_num']), is_([2000]))
Beispiel #19
0
    def test_abbreviation_is_first_services_abbreviation(self):
        services = [
            Service(details({u'Abbr': "ABC"})),
            Service(details({u'Abbr': "ABC"})),
        ]

        dept = Department("Agency for Beautiful Code", services)

        assert_that(dept.abbr, is_("ABC"))
    def test_sum_of_total_transactions_when_kpis_are_missing(self):
        services = [
            Service(details({})),
            Service(details({'2013-Q2 Vol.': '100'})),
            Service(details({'2013-Q2 Vol.': '***'}))
        ]

        assert_that(services[0].has_kpis, is_(False))
        assert_that(total_transaction_volume(services), is_(100))
    def test_aggregate_is_none_when_no_values(self):
        services = [
            Service(details({u'2012-Q4 Digital vol.': "2,000"})),
            Service(details({u'2012-Q4 Digital vol.': "3,000"}))
        ]

        kpi_aggregator = ServiceKpiAggregator(services)

        assert_that(kpi_aggregator.aggregate(['volume_num']), is_([None]))
Beispiel #22
0
    def test_volume_ignores_services_with_no_kpis(self):
        services = [
            Service(details({"2012-Q4 Vol.": "2,000"})),
            Service(details({})),
        ]

        dept = Department("Agency for Beautiful Code", services)

        assert_that(dept.volume, is_(2000))
Beispiel #23
0
    def test_link_is_first_services_slugified_abbreviation(self):
        services = [
            Service(details({u'Abbr': "ABC"})),
            Service(details({u'Abbr': "ABC"})),
        ]

        dept = Department("Agency for Beautiful Code", services)

        assert_that(dept.link,
                    is_("department/abc/by-transactions-per-year/descending"))
    def test_has_detailed_page_when_in_csv(self):
        service_with_details = Service(details({"Detailed view?": "yes"}))
        service_without_details = Service(details({"Detailed view?": ""}))
        service_explicitly_without_details = Service(
            details({"Detailed view?": "no"}))

        assert_that(service_with_details.has_details_page, is_(True))
        assert_that(service_without_details.has_details_page, is_(False))
        assert_that(service_explicitly_without_details.has_details_page,
                    is_(False))
    def test_keywords(self):
        service_with_no_keywords = Service(details({'Keywords': None}))
        service_with_one_keywords = Service(details({'Keywords': 'keyword'}))
        service_with_two_keywords = Service(
            details({'Keywords': 'keyword1, keyword2'}))

        assert_that(service_with_no_keywords.keywords, is_([]))
        assert_that(service_with_one_keywords.keywords, is_(['keyword']))
        assert_that(service_with_two_keywords.keywords,
                    is_(['keyword1', 'keyword2']))
Beispiel #26
0
    def test_count_of_high_volume_services(self):
        services = [
            Service(details({u'High-volume?': 'yes'})),
            Service(details({u'High-volume?': 'yes'})),
            Service(details({})),
        ]

        dept = Department("Agency for Beautiful Code", services)

        assert_that(dept.high_volume_count, is_(2))
Beispiel #27
0
class Tellonym(object):
    def __init__(self, user, timeout):
        self.cookies = False
        self.user = user
        self.timeout = timeout

        self.s = Service(url=PAGE_URL + self.user,
                         default_timeout=self.timeout)

    def send(self, message) -> bool:
        self.s.load_page()

        if not self.cookies:
            self.s.handle_popup()
            self.cookies = True

        self.s.send_message(message)

        try:
            return self.s.validate_message()
        except:
            return False

    def close(self) -> None:
        self.s.close_browser_instance()
    def test_most_recent_kpi_with_attributes_are_none_if_no_attributes_are_present(
            self):
        service = Service(
            details({
                '2012-Q4 Vol.': '10',
                '2013-Q1 Vol.': '3',
            }))

        assert_that(
            service.find_recent_kpis_with_attributes(
                ['volume_num', 'digital_volume_num']), is_(None))
    def test_most_recent_kpi_with_given_attribute(self):
        service = Service(
            details({
                '2012-Q4 Vol.': '10',
                '2012-Q4 Digital vol.': '5',
                '2013-Q1 Vol.': '3',
            }))

        assert_that(
            service.find_recent_kpis_with_attributes(
                ['volume_num', 'digital_volume_num'])['volume_num'], is_(10))
Beispiel #30
0
    def game_turn(self):
        # perform a single turn of the game
        for player in self.players:
            if Service.check_if_its_over(self): return
            action = player.action(self)
            Service.take_action(self, action)
            Service.check_if_its_almost_over(self, player)

            # record keeping
            self.actions[player.name].append(action[1])
            self.scores[player.name].append(player.score())
Beispiel #31
0
    def test_volume_is_total_of_last_available_quarter_for_each_service(self):
        services = [
            Service(details({
                "2012-Q4 Vol.": "1,000",
                "2013-Q1 Vol.": "1,500"
            })),
            Service(details({"2012-Q4 Vol.": "2,000"})),
        ]

        dept = Department("Agency for Beautiful Code", services)

        assert_that(dept.volume, is_(3500))
    def test_most_up_to_date_volume(self):
        service_with_one_vol = Service(details({'2013-Q1 Vol.': '200'}))
        service_with_two_vols = Service(
            details({
                '2013-Q1 Vol.': '200',
                '2013-Q2 Vol.': '250'
            }))
        service_with_no_vols = Service(details({}))

        assert_that(service_with_one_vol.most_up_to_date_volume, is_(200))
        assert_that(service_with_two_vols.most_up_to_date_volume, is_(250))
        assert_that(service_with_no_vols.most_up_to_date_volume, is_(None))
    def test_aggregate_is_none_when_no_high_volume_services_and_ignore_non_high_volume(
            self):
        services = [
            Service(details({"2012-q4 vol.": "2,000"})),
            Service(details({"2012-q4 vol.": "3,000"}))
        ]

        kpi_aggregator = ServiceKpiAggregator(services)

        assert_that(
            kpi_aggregator.aggregate(['volume_num'], high_volume_only=True),
            is_([None]))
    def test_aggregate_is_sum_of_values_when_high_volume_matters(self):
        services = [
            Service(details({
                "2012-Q4 Vol.": "2,000",
                u'High-volume?': 'yes'
            })),
            Service(details({"2012-Q4 Vol.": "3,000"}))
        ]

        kpi_aggregator = ServiceKpiAggregator(services)

        assert_that(
            kpi_aggregator.aggregate(['volume_num'], high_volume_only=True),
            is_([2000]))
    def test_calculate_cost_change_from_previous_value(self):
        increase_service = Service(details({
            '2013-Q1 Vol.': '200',
            u'2013-Q1 CPT (\xa3)': '2',
            '2012-Q4 Vol.': '100',
            u'2012-Q4 CPT (\xa3)': '1',
        }))
        decrease_service = Service(details({
            '2013-Q1 Vol.': '100',
            u'2013-Q1 CPT (\xa3)': '1',
            '2012-Q4 Vol.': '100',
            u'2012-Q4 CPT (\xa3)': '2',
        }))
        no_previous_vol_service = Service(details({
            '2013-Q1 Vol.': '100',
            u'2013-Q1 CPT (\xa3)': '1',
            '2012-Q4 Vol.': '',
            u'2012-Q4 CPT (\xa3)': '',
        }))
        zero_previous_vol_service = Service(details({
            '2013-Q1 Vol.': '100',
            u'2013-Q1 CPT (\xa3)': '1',
            '2012-Q4 Vol.': '0',
            u'2012-Q4 CPT (\xa3)': '0',
        }))

        assert_that(increase_service.latest_kpi_for('cost_change'), is_(4))
        assert_that(decrease_service.latest_kpi_for('cost_change'), is_(0.5))
        assert_that(no_previous_vol_service.latest_kpi_for('cost_change'), is_(None))
        assert_that(zero_previous_vol_service.latest_kpi_for('cost_change'), is_(None))
Beispiel #36
0
    def test_takeup_is_none_if_digital_volume_is_none(self):
        services = [
            Service(details({
                '2012-Q4 Vol.': '10',
                u'High-volume?': 'yes'
            })),
            Service(details({
                '2012-Q4 Vol.': '30',
                u'High-volume?': 'yes'
            })),
        ]

        dept = Department("Agency for Beautiful Code", services)

        assert_that(dept.takeup, is_(None))
Beispiel #37
0
	def __init__(self, query):
		self.query = query
		self.where = None
		self.orders = None
		self.limit = None
		self.filter = []
		self.fixedFilter = None
		self.conn = Service.getDbConn()
Beispiel #38
0
	def authenticate(self, login, password):
		pwd = md5(str(password)).hexdigest()
		
		user = False
		conn = Service.getDbConn()
		try:
			user = {}
			cursor = conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
			cursor.execute("SELECT * FROM pim.users WHERE login = %s AND password = %s AND active = true", (login, pwd))
			
			for row in cursor.fetchall():
				user['user_id'] = row['user_id']
				user['role'] = row['role']
				
			
		finally:
			Service.putDbConn(conn)
		
		self.loggedUser = user
		return user
Beispiel #39
0
    def wrapped(self, *args):
        for name, value in zip(arg_names[1:], args):
            setattr(self, name, value)

        conn = Service.getPostgresPool().getconn()
        cursor = conn.cursor()
        cursor.execute("BEGIN")
        # self.cursor = cursor

        try:
            return function(self, cursor, *args)
            cursor.execute("COMMIT")

        except Exception, e:
            cursor.execute("ROLLBACK")
            print e

            traceback.print_exc(file=sys.stdout)
Beispiel #40
0
import sys


def SQLTransaction(function):

    arg_names = inspect.getargspec(function)[0]

    def wrapped(self, *args):
        for name, value in zip(arg_names[1:], args):
            setattr(self, name, value)

        conn = Service.getPostgresPool().getconn()
        cursor = conn.cursor()
        cursor.execute("BEGIN")
        # self.cursor = cursor

        try:
            return function(self, cursor, *args)
            cursor.execute("COMMIT")

        except Exception, e:
            cursor.execute("ROLLBACK")
            print e

            traceback.print_exc(file=sys.stdout)

        finally:
            Service.getPostgresPool().putconn(conn)

    return wrapped
    def test_no_kpi_for_quarter_with_noVolume(self):
        service = Service(details({
           '2012-Q4 Digital vol.': '5'
        }))

        assert_that(service.latest_kpi_for('volume_num'), is_(None))
    def test_cost_is_non_when_no_cpt(self):
        service = Service(details({
            "2012-Q4 Vol.": "2,000",
        }))

        assert_that(service.latest_kpi_for('cost'), is_(None))
    def test_no_kpis(self):
        service = Service(details({}))

        assert_that(service.latest_kpi_for('takeup'), is_(None))
    def test_most_recent_kpi_takeup_is_none_if_no_matching_quarters(self):
        service = Service(details({'2012-Q4 Vol.': '10',
                                   '2013-Q1 Digital vol.': '5'}))

        assert_that(service.latest_kpi_for('takeup'),
                    is_(None))
    def test_kpi_with_missing_property(self):
        service = Service(details({
           '2012-Q4 Vol.': '5'
        }))

        assert_that(service.latest_kpi_for('volume_change'), is_(None))
Beispiel #46
0
	def __del__(self):
		Service.putDbConn(self.conn)
    def test_transactions_count(self):
        service = Service(details({'2013-Q1 Vol.': '10'}))

        assert_that(service.latest_kpi_for('volume_num'), is_(10))
    def test_volumes(self):
        service = Service(details({'2012-Q4 Vol.': '10',
                                   '2012-Q4 Digital vol.': '5'}))

        assert_that(service.latest_kpi_for('takeup'), is_(0.5))